Scorpious2k and I worked this out. It's a brand new extension to the quest system that is going to expand the what can be done in quests and in interracting with mobs. It works in both perl and old quest format. It is in use now on the Scorpious2k server and will be in CVS soon, if it isn't already.
I am going to break this into several parts to try to explain global variables.
What this does is give mobs the ability to "remember" events. Sort of like making a sticky note for future events or sending instant messages to other mobs. It allows the quest writer to save variables for use in future quests. It gives a lot of flexibility.
You will also have to make some changes to the database with the quest_globals.sql.
Here is how to use it..
It uses 3 commands: setglogal, targlobal and delglobal.
==========
Setglobal:
==========
[old quest format]
setglobal([varname],[value],[options],[duration]);
[perl format]
quest::setglobal([varname],[value],[options],[duration]); (perl format)
The setglobal command allows you to create or modify an existing global variable for the mob you are using the command on.
==========
targlobal:
==========
[old quest format]
targlobal([varname],[value],[duration],[npcid],[charid],[zoneid]);
[perl format]
quest::targlobal([varname],[value],[duration],[npcid],[charid],[zoneid]);
This is a way to "stick" a global variable to a mob. A quick and easy way to give information to a mob or communicate.
==========
delglobal:
==========
[old quest format]
delglobal([varname]);
[perl format]
quest::delglobal([varname]);
This command is used to delete global variables when they are no longer needed. You can only delete global variables that belong to the mob the variable is for.
===================
Command Parameters:
===================
[varname] the name of the variable you want to save. Do not include the variable prefix as part of the name. When the quest for the npc who recieves this variable begins, a variable with the name that you here preceeded by a "$" will be available. For example, if [varname] is "genius" then a variable named $genius will be available to the quest script of the npc with whatever you specified in it.
[value] this is what the variable will contain when the quest script begins.
[options] value determines the availability of global variables to NPCs when a quest begins
Code:
+--------+---------+---------+----------+
| value | npcid | player | zone |
+--------+---------+---------+----------+
| 0 | this | this | this |
| 1 | all | this | this |
| 2 | this | all | this |
| 3 | all | all | this |
| 4 | this | this | all |
| 5 | all | this | all |
| 6 | this | all | all |
| 7 | all | all | all |
+--------+---------+---------+----------+
this way you can decide what mobs can "see" the variable.
[duration] the amount of time this variable will be available. After this time, the variable goes away! It is a number preceeded by a letter, where the letter can be:
Code:
+--------+----------+------------------------------------------------+
| Letter | Time is | examples |
+--------+----------+------------------------------------------------+
| S |seconds| "S15" = 15 seconds |
| M |minutes| "M30" = 30 minutes |
| H | hours | "H12" = 12 hours |
| D | days l "D90" = 90 days |
| Y | years | "Y5" = 5 years |
| T | time | "T012345" = 1 hr, 23 min, 45 sec |
| C | calendar| "C010215" = 1 yr, 2 months, 15 days |
+--------+----------+------------------------------------------------+
[npcid] the id for the target npc from the npc_types table
[charid] the character id from the character_ table for the targetted player
[zoneid] the NUMBER of the zone where the targetted npc is located
In my next message I will give an example.