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

How to make a quest.


xweetok59
 Share

Recommended Posts

Actuall here you go:

Quest System

By Unknown_Raven

Difficulty: Unknown

Since this is one of the best and probably most useful scripts I have made I have decided to finish up the commenting at the bottom. Originally I did have good descriptions but a forum wipe deleted my post and I never got around to redoing the full descriptions. Now you should be able to see the full tutorial and find it easier to use.

Paste this at the bottom of your main.txt

' ********************
' * QUEST SYSTEM 1.1 *
' * By Unknown_Raven *
' ********************
Function GetFlagHeight(index, flagnum)
Dim X
X = GetVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum)
GetFlagHeight = X
End Function

Sub RaiseFlag(index, flagnum, height)
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum, GetVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum)+height)
End Sub

Sub LowerFlag(index, flagnum, height)
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum, GetVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum)-height)
End Sub

Sub SetFlag(index, flagnum, height)
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum, 0)
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum, GetVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum)+height)
'Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&flagnum, height)
End Sub

Sub GiveItem(index, item, value)
SLOT = 1
Do While SLOT < 24
If GetPlayerInvItemNum(index, SLOT) = 0 Then
Call SetPlayerInvItemNum(index, SLOT, item)
Call SetPlayerInvItemValue(index, SLOT, GetPlayerInvItemValue(index, SLOT)+value)
Call SendInventoryUpdate(index, SLOT)
SLOT = 24
End If
SLOT = SLOT+1
Loop
End Sub

Sub TakeItem(index, item)
SLOT = 1
Do While SLOT < 24
If GetPlayerInvItemNum(index, SLOT) = item Then
Call SetPlayerInvItemNum(index, SLOT, 0)
Call SetPlayerInvItemValue(index, SLOT, 0)
Call SendInventoryUpdate(index, SLOT)
SLOT = 24
End If
SLOT = SLOT+1
Loop
End Sub

Sub TakeCurrency(index, item, value)
SLOT = 1
Do While SLOT < 24
If GetPlayerInvItemNum(index, SLOT) = item Then
AMOUNT = GetPlayerInvItemValue(index, SLOT)
TAKE = Int(AMOUNT-value)
If TAKE <= 0 Then
Call SetPlayerInvItemNum(index, SLOT, 0)
Call SetPlayerInvItemValue(index, SLOT, 0)
Call SendInventoryUpdate(index, SLOT)
End If
If TAKE > 0 Then
Call SetPlayerInvItemNum(index, SLOT, 0)
Call SetPlayerInvItemValue(index, SLOT, 0)
Call SetPlayerInvItemNum(index, SLOT, item)
Call SetPlayerInvItemValue(index, SLOT, TAKE)
Call SendInventoryUpdate(index, SLOT)
End If
SLOT = 24
End If
SLOT = SLOT+1
Loop
End Sub

Function FindItemSlot(index, item)
slot = 1
Do While slot <= 24
If GetPlayerInvItemNum(index, Slot) = item Then
FindItemSlot = slot
slot = 24
Else
FindItemSlot = 0
End If
slot = slot + 1
Loop
End Function

Paste this at the top in the On Player Join Sub.

If GetPlayerLevel(index) = 1 Then
If GetPlayerExp(index) = 0 Then
NUM = 1
'change the 30 to number of flags you want per player
Do While NUM <= 30
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&NUM, 0)
NUM = NUM+1
Loop
Call SetPlayerExp(index, 1)
End If
End If

Here are all the commands you can now use.

Call RaiseFlag(index, flagnum, height)

-This command is used to raise the trigger flags for an event.
-flagnum specifys the flag number
-height is how high you are raising the flag. It takes the current height and adds this value to it.

Call LowerFlag(index, flagnum, height)

-This command is simply the opposite of the Raiseflag.

Call SetFlag(index, flagnum, height)

-This command is used to set a flag to an exact height. Whatever the value of height is will be the value the flag is at.

Call GiveItem(index, item, value)

-This gives the player an item.
-Item is for specifying which item to give.
-Value is how much. Value only works for currency type items.

Call TakeItem(index, item)

-This is used specifically for taking away a target item. If the player has two of the same item it will take away the one closes to the top of their inventory.

Call TakeCurrency(index, item, value)

-This is the same as the command above except it removes only currency type items.

GetFlagHeight(index, flagnum)

-returns the current height of the flag.

FindItemSlot(index, item)

-This returns the inventory slot number that the specified item is in. If the player does not have the item in his/her inventory then the value returned will be 0.

How it works

The quest system is actually a series of tools used to create quest scripts much more efficiently. I will briefly outline for you some of the ideas on making quests.

First off you might be wondering what is a flag? Whenever a character completes a part of the quest we have to somehow keep track of it. This is done through flags also called triggers. An example would be, the player is told to go to a specific house. We decide that this will be quest 1 so we will use Flag1\. Flag1 is currently at a height of 0\. Once the person enters the house we raise Flag1 up one level. [ Call RaiseFlag(index, 1, 1) ] Now Flag1 = 1\. There are many things we can do with this such as provide a Flag check that says, If Flag1 = 1 then do this. That will allow us to seperate the various steps of the quest.

Alright so now you got a brief understanding of what the flags are but now we need to learn a bit of the actual coding structure. Lets make a scripted tile.

Case 0
' This is the first step of the quest.
If GetFlagHeight(index, 1) = 0 Then 'this checks the height of Flag1
Call PlayerMsg(index, "Hi, could you do this quest for me? I need you to go to the forest and see if it is muddy.", 10)
Call RaiseFlag(index, 1, 1) 'raises the flag a level so the event cannot be repeated.
End If

' This runs after the player has begun the quest but has not yet completed its next step.

If GetFlagHeight(index, 1) = 1 Then
Call PlayerMsg(index, "Please hurry to the forest!", 10)
End If

' This is the end of the quest where the player comes back to recieve his/her reward.
If GetFlagHeight(index, 1) = 2 Then
Call PlayerMsg(index, "Oh thank you please take this reward.", 10)
If FindItemSlot(index, 0) = 0 Then 'looks for an empty slot
'runs if inventory is full
Call PlayerMsg(index, "I am sorry but your inventory is full.", 12)
Else
'runs if there is atleast one empty item slot
Call GiveItem(index, 20, 1) 'gives them item 20
Call PlayerMsg(index, "You recieved item 20." 14)
Call RaiseFlag(index, 1, 1) 'raises the flag a level so the event cannot be repeated.
End If
End If

Case 1
' This represents the Forest Trigger.
If GetFlagHeight(index, 1) = 1 Then
Call PlayerMsg(index, "You notice that the forest is not very muddy." 10)
Call RaiseFlag(index, 1, 1)
End If

Now if you look through those two cases which are both scripted tiles, you will see the basic form of the quests as well as how to use some of the commands. There are many ways to take advantage of the quest system and all of them are limited only by your imagination. I hope this helps your understanding of this script
Link to comment
Share on other sites

  • 4 weeks later...
Thanks for the great tutorial/guide here. I have been running into some issues though with these functions not working properly. I did notice that I don't have a "OnPlayerJoin" in ES, only a "JoinGame", which is where I implemented the script that should be in OnPlayerJoin sub.

Would that effect the script and cause the flag system not to work? I've played with the implementing the flag script into ScriptedNPC for nearly an hour. Just looking for a little insight into my situation.  :cheesy:

Here is where I posted it:

>! Sub JoinGame(Index)
>! If GetPlayerLevel(index) = 1 Then
If GetPlayerExp(index) = 0 Then
NUM = 1
'change the 30 to number of flags you want per player
Do While NUM <= 30
Call PutVar("FLAGS.ini", GetPlayerName(index), "Flag"&NUM, 0)
NUM = NUM+1
Loop
Call SetPlayerExp(index, 1)
End If
End If
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...