Server Scripts
From Sagramore Wiki
Scripts are read from files. [Indentation] is very important to the Main Programmer, so scripters are forced to write scripts with proper indentation.
Contents |
Classes
At the first level come the scripts. Scripts are grouped into class instances. Valid classes are
Methods
On the 2nd level come methods of scripts. There are some default methods that automatically get called, like
- onLoad : Gets called when the script is loaded
- onClick : Gets called when the user clicks this NPC
- onTouch : Gets called when the user approaches this NPC (range specified with setnpc("touchrange", RANGE) in the constructor)
- onChat : Gets called when the user says something near this NPC (range specified with setnpc("range", RANGE) in the constructor)
- onKill : Gets called when this NPC is killed
- onHit : Gets called when someone is hit with this skill
- onUse : Gets called when someone uses this skill or item
- onEquip : Gets called when this equipment is changed, this method is used to give bonusstats
Statements
On the 3rd level come statements. These can be nested on deeper levels too (for instance with the if statement). Current script statements are:
- if
- message
- debug
- assignment
- setnpcoption
- npctext
- npcvar
- warp
- effect
- heal
- healmagic
- addskill
- addquest
- updatequest
- finishquest
- statbonus
- setlook
- damage
- shopclear
- shopadditem
- shopshow
- shopshowsell
- addmoney
- additem
- delitem
- sqrt
- save
- addexp
A method call is the name of the method, followed by the parameters as expressions inbetween brackets (). If no parameters have to be specified, empty brackets must be added.
Example:
additem(ITEM.SWORD)
This would give the player an item
Expressions
An expression are constants or variables, combined with operators. Constants can either be a number, a string or a defined constant, which is resolved to a number. Strings are enclosed by "" and can be escaped with \. Defined constants always consist of 2 parts, a group and the constant name, and are defined in the const table in the database. There are some predefined constant groups though
- ITEMS : all item constants (loaded from the item_db)
- QUESTS : all quest constants (loaded from the quest_db)
- MOBS : all monster constants (loaded from the mob_db)
Variables
Variablenames start with $ and end with a specific symbol to show their type.
- $ : accountbased variable
- @ : characterbased variable
- # : global variable (for all users)
- anything else: temporary variable
Binary Operators
Sagrascript supports the following binary operators:
- x + y : returns the sum of x and y
- x - y : returns the difference of x and y
- x / y : returns the quotient of x and y
- x * y : returns the product of x and y
- x % y : returns the modulo of x and y
- x ++ y : returns the concatenation of x and y
- x && y : returns true if x and y are both true
- x || y : returns true if either x or y is true
- x == y : returns true if x and y are equal
- x < y : returns true if x is smaller then y
- x > y : returns true if x is larger then y
Functions
Functions can be called from expressions to return a value.
Functions are:
Example
cNPC cFightingQuest
cFightingQuest()
setnpc("x",25)
setnpc("y",17)
setnpc("map","demo_town")
setnpc("model",3)
setnpc("name","Pericles Talfryn")
onClick
npctext("demo/pericles/welcome.php")
if(hasquest(QUEST.PERICLES) && !finishedquest(QUEST.PERICLES))
if(finishedsubquest(QUEST.PERICLES,6))
npctext("demo/pericles/congratulations.php")
finishquest(QUEST.PERICLES)
addmoney(150)
else
npctext("demo/pericles/questprogress.php")
elseif (finishedquest(QUEST.PERICLES))
npctext("demo/pericles/questdone.php")
else
npctext("demo/pericles/questintro.php")
if(npcvar("option") == 0)
npctext("demo/pericles/getsword.php")
additem(ITEM.IRON_SWORD)
addquest(QUEST.PERICLES)
else
npctext("demo/pericles/toobad.php")
