Scripting 102: Global Variables

Forum Archive - from http://theuniversal.net
Locked
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Scripting 102: Global Variables

Post by morbydvisns »

Please see http://theuniversal.net/worldmanual for all the latest info on world scripting.

Variable scripting is a way of controlling the flow of scripts per player, or serverwide.
Playervariables ( $gPlayervar1 - 64) are player specific to store data in a numeric fashion.
Servervariables ($gservervar1 - 128 (i think)) are server specific, a reference all players scripts to access.
playertimevariables ($gPlayertimevar1-4) are for using timed variables, on a per-player basis.

Along with the 3 above, there are also server refrences per player that you can call to the script. Those include: $gplayerkudos, $gplayerteam, $gplayerfamily, $gplayercash,$gplayerhealth, $gplayerlevel.

All variables SHOULD start at 0 by default.


SETTING VARIABLES

in order to set a variable, you would format it like this:

Code: Select all

Event( "Useitem", "Usable Item 1" )
{
*msg %player% Playervar1 set to 1
$playervar1 = 1  // <------------defines plavervar1
}
Now, you have something that sets a playervariable. Lets get a little more complicated.

Code: Select all

Event( "Useitem", "Usable Item 2" )
{
  if ( $playervar1 = 1 )
  {
   *msg %player% You may use this item.
   }
  else
  { 
   *msg %player% you must use Usable Item 1 before using this item.
  canceltransaction()
  }
}
In the above example, the script looks to see if playervariable 1 is 1 before it executes the script. If its not, it tells them it cannot, and gives the item back so it can be used again later.


Hope this helps some people. Ill make another post later of a more basic scripting instructions, with all the events possible etc.

----===========----------------------================

Time Variables


$gservertime is used with $playertimevar1 - 4
servertime is in seconds from the very start of planet time.

An example for using this. What this does is allow use of an item every 3 minutes.

Code: Select all


Event( "Useitem", "Usable Item 1" )
{
if ( $gservertime > $playertimevar1 + 180 ) // checks to see if time has                                     //lapsed. 180 seconds from previous use
  {
  $playertimevar1 = $gservertime      // <----- inputs current servertime                       // to playertimevar1
  *msg %player% Item used... you can use this item again in 3 minutes
  }
else
 {
  *msg %player% You cannot use this item again yet
 }
}

User avatar
zaroba
World Owner
World Owner
Posts: 7257
Joined: Fri Oct 10, 2003 11:06 pm
Location: Hereford, PA
Contact:

Post by zaroba »

kick :P
User avatar
morbydvisns
Posts: 1889
Joined: Sun Jan 30, 2005 12:51 am

Post by morbydvisns »

can one of staff move this over to the setup forum and sticky this and my scripting 101 plz =)
Locked