Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Not Fully Functional Quest Script (Now Fully Functional)


Kimimaru
 Share

Recommended Posts

EDIT (7/08/09): The Quest script is now fully functional and works even better than before! In your Main.txt, look for this:

Credit to: - Ne0n - helped me figure out how to make different characters on different accounts start the quest
              - Admiral Refuge - helped me fix up some errors

Find this:

```
' Executes whenever a scripted NPC does an action.
Sub ScriptedNPC(Index, Script)
Select Case Script
              Case 0
Call PlayerMsg(Index, "This scripted NPC has no apparent use.", WHITE)
Exit Sub

Case Else
Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)
Exit Sub
End Select
End Sub
```
Replace it with this:

```
' Executes whenever a scripted NPC does an action.
Sub ScriptedNPC(Index, Script)
Select Case Script

' First Quest Script

Case 0

' Creates Quest1 file

If GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") = "" Then
Call PutVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp", "1")
End If

'Starts quest

If GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") <> 0 and GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") <>2 Then
        MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
End If
If GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") = 0 Then
        If CanTake(Index, 1, 50) = False Then
            MsgBox "Oh, it looks like you didn't get what I need yet.", 0, "Item Needed!"
          Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            MsgBox "Thank you! Here is your reward!", 0, "Quest Complete!"
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
Call PutVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp", "2")
End If
        ElseIf GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") = 2 Then
MsgBox "Thanks for the help before; I really appreciate it!", 0, "Quest Already Complete!"
End If
If GetVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp") <> 2 Then
Call PutVar("Scripts\Quest1.ini", GetPlayerName(Index), "Questhelp", "0")
End If
      Exit Sub

Case Else
Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)
Exit Sub
End Select
End Sub
```
That's all there is to it! What this does is create an INI file in your Scripts folder, which is located in your Server folder, after you talk to the NPC and start the quest. First, you talk to the NPC, and it will tell you that you need to bring it an item of some sort (Of course, you can change this). The NPC will then either give you a reward or tell you that you do not have what was required to complete the quest the next time you talk to it. Once you've completed the quest, the computer will thank you for helping it, and then you can no longer do the quest again. Each account and character you make will be able to do the quest.

You can edit anything to your specific needs.
Link to comment
Share on other sites

Hmm okay
Anyway, here are the errors in the script:

You may be calling "MsgBox", wrong.  Does it work in the script?

The sytnax is usually MsgBox:
MsgBox("Prompt", 0, "Title")

GetPlayerExp is a function, not a sub; which means you don't "Call" it.  Also, you're not storing it in the variable "Exp", and you've never declared that variable either.

Also, when you update exp, you need to SendStats afterward.

To allow the players to only do this once, you'll need to store in an ini that the player did it.
Read over the updated version of your code:
```
      Case 0
        MsgBox("I'm the quest tester. Please get me 50 (money).", 0, "Notice")
        If CanTake(Index, 1, 50) = False Then
            Call PlayerMsg(index, "You don't have the items required!", 12)
        Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            Call PlayerMsg(index, "Thanks; here's your reward!", 12)
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
        End If
      Exit Sub

```
Link to comment
Share on other sites

Okay, thanks a lot! The MsgBox actually does work, although it contained no title. I was wondering why the MsgBox title wasn't appearing, but the syntax I was using was:

MsgBox("Prompt","Title)

That's similar to how you can do certain Dialog Boxes in Java with an external library file to shorten the command, but I realized that I was in SadScript, not Java.  XD

I'll test it out now and edit my post to let you know if it works or not. Thanks again!
Link to comment
Share on other sites

@Kimimaru:

> Okay, thanks a lot! The MsgBox actually does work, although it contained no title. I was wondering why the MsgBox title wasn't appearing, but the syntax I was using was:
>
> MsgBox("Prompt","Title)
>
> That's similar to how you can do certain Dialog Boxes in Java with an external library file to shorten the command, but I realized that I was in SadScript, not Java.  XD
>
> I'll test it out now and edit my post to let you know if it works or not. Thanks again!

Well, sadscript is VBscript, so any functions that VBscript has, Sadscript can use; though, I think the commands such as MsgBox may appear to everyone online (global), and not just you, so you may want to test that (have two people online at the same time, and see if they both get the msgbox).
Link to comment
Share on other sites

Your code worked great, except the MsgBox command was slightly off. You don't need the parenthesis.

Here's the final code that works, incase anyone wants it:

```
                Case 0
        MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
        If CanTake(Index, 1, 50) = False Then
            Call PlayerMsg(index, "You don't have the items required!", 12)
          Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            Call PlayerMsg(index, "Thanks; here's your reward!", 12)
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
        End If
      Exit Sub
```
As for the MsgBox concern, it only applies to one player. The other players don't see it.

Well, everything's fine now. Thanks a lot, Admiral!
Link to comment
Share on other sites

By saying, "msgbox continues to pop up a few times," I assume you mean that you can do the quest multiple times by talking to the same NPC. Yes, that is a problem; however, as Admiral said, "to allow the players to only do this once, you'll need to store in an ini that the player did it."

Therefore, it's not a problem in the script but a problem in storing the data. You didn't store the data anywhere that says that the player already completed the quest, so the player can obviously keep doing it over and over again.

Now, if you claim that the MsgBox pops up multiple times by talking to the NPC once, I don't see how that's possible, as the code states that the MsgBox only appears once. There are no loops that allow it to continue unless you perform an action that allows you to exit the loop, either.

Anyway, I hope that cleared things up for you.
Link to comment
Share on other sites

Strange. That doesn't happen with me. Maybe you put the code in the wrong spot or made a mistake on part of the code. Anyway, go into your Main.txt in the Scripts folder on the Server side.

Find this:

```
' Executes whenever a scripted NPC does an action.
Sub ScriptedNPC(Index, Script)
Select Case Script
              Case 0
Call PlayerMsg(Index, "This scripted NPC has no apparent use.", WHITE)
Exit Sub

Case Else
Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)
Exit Sub
End Select
End Sub

```
Replace it with this:

```

' Executes whenever a scripted NPC does an action.
Sub ScriptedNPC(Index, Script)
Select Case Script
Case 0       
                        MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
        If CanTake(Index, 1, 50) = False Then
            Call PlayerMsg(index, "You don't have the items required!", 12)
          Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            Call PlayerMsg(index, "Thanks; here's your reward!", 12)
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
        End If
      Exit Sub
    Case Else
Call PlayerMsg(Index, "No NPC script found. Please contact an admin to solve this problem.", WHITE)
Exit Sub
End Select
End Sub

```
If you do not like the MsgBox, you can replace it with this:

```
Call PlayerMsg(Index, "I'm the quest tester. Please get me 50 (money).", WHITE)
```
I hope that helps!
Link to comment
Share on other sites

I believe I said that in one of my earlier posts, but no, it doesn't pop up for every player online. I tested it earlier. Only the player that started and completed the quest received the MsgBox. I'm sure the results would be more reliable if someone from another computer tested it with me.
Link to comment
Share on other sites

@Kimimaru:

> I believe I said that in one of my earlier posts, but no, it doesn't pop up for every player online. I tested it earlier. Only the player that completed the quest received the MsgBox. I'm sure the results would be more reliable if someone from another computer tested it with me.

No, that's okay, and this is good to know.
I normally don't use too many Vbscript functions in sadscript (e.g. instead of a msgbox, I'd just use the Call PlayerPrompt or Custom Menus), only recently for my Rick Roll script I used it, and that was because I was trying to mimic a javascript application.

Either way, it's good to hear that it only effects that player, and not everyone on the server XD
Link to comment
Share on other sites

I thought it would be a waste to post another topic, so I'll ask another question about this script here. I'm using a code to store the data in an INI file so that you cannot do the quest after you've already completed it. Here's my code:

When you join the game:

```
' Creates Quest 1 file

Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")
```
When you talk to a scripted NPC:

```
' First Quest Script

Case 0
If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> 2 Then
Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")
        MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
        If CanTake(Index, 1, 50) = False Then
            MsgBox "Oh, it looks like you didn't get what I need yet.", 0, "Item Needed!"
          Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            MsgBox "Thank you! Here is your reward!", 0, "Quest Complete!"
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
Call PutVar(Quest1.ini", "Quest 1", "Questhelp", "2")
        End If
End If
      Exit Sub
```
None of it is working when I talk to the NPC for some reason. I believe I did most of it right, but there's obviously a problem somewhere, and I cannot spot out where the problem is. Any help would be appreciated.
Link to comment
Share on other sites

Although this is a simple script, I've spent an hour making it work exactly how I want it to work. There are a few things I'm concerned about, though. Here's the code:

When you join the game (very bottom of the sub):

```
' Creates Quest1 file

If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> 0 and GetVar("Quest1.ini", "Quest 1", "Questhelp") <> 2 Then

Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")

End If
```
When you talk to a scripted NPC:

```
Case 0
If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> 0 and GetVar("Quest1.ini", "Quest 1", "Questhelp") <>2 Then
Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")
        MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
End If
If GetVar("Quest1.ini", "Quest 1", "Questhelp") = 0 Then
        If CanTake(Index, 1, 50) = False Then
            MsgBox "Oh, it looks like you didn't get what I need yet.", 0, "Item Needed!"
          Else
            Dim Exp
            Call TakeItem(index, 1, 50)
            Call GiveCurrency(index, 1, 500)
            MsgBox "Thank you! Here is your reward!", 0, "Quest Complete!"
            Exp = GetPlayerExp(index)
            Call SetPlayerExp(index, Exp + 50)
            Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
            Call SendStats(Index)
Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "2")
End If
        ElseIf GetVar("Quest1.ini", "Quest 1", "Questhelp") = 2 Then
MsgBox "Thanks for the help before; I really appreciate it!", 0, "Quest Already Complete!"
End If
If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> 2 Then
Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "0")
End If
      Exit Sub
```
As of now, it works great IF you **already** have the quest file. I'm unable to think of a way to make it create the file and still function as it does now. Also, you cannot do the quest again even if you're on a different account or character, but I think I can fix that. Any suggestions, please?
Link to comment
Share on other sites

For the JoinGame thing, it should be this (since it's looking for a string, not a number):
```
' Creates Quest1 file

  If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> "0" and GetVar("Quest1.ini", "Quest 1", "Questhelp") <> "2" Then

  Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")

  End If

```But, there is an easier way of creating an ini file if it doesn't exist, like so:
```
' Creates Quest1 file

  If GetVar("Quest1.ini", "Quest 1", "Questhelp") = "" Then
      Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")
  End If

```

Also, here is your sub, where it compares it to strings (probably not needed, since I think you said it works):
```
Case 0
        If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> "0" And GetVar("Quest1.ini", "Quest 1", "Questhelp") <> "2" Then
        Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "1")
              MsgBox "I'm the quest tester. Please get me 50 (money).", 0, "Quest Start"
        End If
        If GetVar("Quest1.ini", "Quest 1", "Questhelp") = "0" Then
              If CanTake(Index, 1, 50) = False Then
                  MsgBox "Oh, it looks like you didn't get what I need yet.", 0, "Item Needed!"
              Else
                  Dim Exp
                  Call TakeItem(index, 1, 50)
                  Call GiveCurrency(index, 1, 500)
                  MsgBox "Thank you! Here is your reward!", 0, "Quest Complete!"
                  Exp = GetPlayerExp(index)
                  Call SetPlayerExp(index, Exp + 50)
                  Call PlayerMsg(index, "You've gained 50 experience and got 500 (money)!", 12)
                  Call SendStats(Index)
        Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "2")
        End If
              ElseIf GetVar("Quest1.ini", "Quest 1", "Questhelp") = "2" Then
        MsgBox "Thanks for the help before; I really appreciate it!", 0, "Quest Already Complete!"
        End If
        If GetVar("Quest1.ini", "Quest 1", "Questhelp") <> "2" Then
        Call PutVar("Quest1.ini", "Quest 1", "Questhelp", "0")
        End If
            Exit Sub

```
Another note, when you use GetVar, and you plan on doing mathmatics with the numbers you're getting, make sure you Int() it, e.g.:
Int(GetVar("File.ini", "Header", "MyNumber"))
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...