eAthena NPC Script Variables

Variables
———

The meat of every programming language is variables – places where you store
data.

Variables are divided into and uniquely identified by the combination of:
prefix – determines the scope and extent (or lifetime) of the variable
name – an identifier consisting of ‘_’ and alfanumeric characters
postfix – determines the type of the variable: integer or string

Scope can be:
global – global to all servers
local – local to the server
account – attached to the account of the character identified by RID
character – attached to the character identified by RID
npc – attached to the NPC
scope – attached to the scope of the instance

Extent can be:
permanent – They still exist when the server resets.
temporary – They cease to exist when the server resets.

Prefix: scope and extent
nothing – A permanent variable attached to the character, the default
variable type.
“@” – A temporary variable attached to the character.
SVN versions before 2094 revision and RC5 version will also treat
‘l’ as a temporary variable prefix, so beware of having variable
names starting with ‘l’ if you want full backward compatibility.
“$” – A global permanent variable.
They are stored in “save\mapreg.txt” or database table mapreg,
depending on server type.
“$@” – A global temporary variable.
This is important for scripts which are called with no RID
attached, that is, not triggered by a specific character object.
“.” – A NPC variable.
They exist in the NPC and dissapear when the server restarts or the
npc is reloaded. Can be accessed from inside the NPC or by calling
‘getvariableofnpc’.
“.@” – A scope variable.
They are unique to the instance and scope. Each instance has it’s
own scope that ends when the script ends. Calling a function with
callsub/callfunc starts a new scope, returning from the function
ends it. When a scope ends, it’s variables are converted to values
(‘return .@var;’ returns a value, not a reference).
“#” – A permanent local account variable.
They are stored with all the account data in “save\accreg.txt” in
TXT versions and in the SQL versions in the ‘global_reg_value’
table using type 2.
“##” – A permanent global account variable stored by the login server.
They are stored in “save\account.txt” and in the SQL versions in the
‘global_reg_value’ table, using type 1. The only difference you will
note from normal # variables is when you have multiple char-servers
connected to the same login server. The # variables are unique to
each char-server, while the ## variables are shared by all these
char-servers.

Postfix: integer or string
nothing – integer variable, can store positive and negative numbers, but only
whole numbers (so don’t expect to do any fractional math)
‘$’ – string variable, can store text

Examples:
name – permanent character integer variable
name$ – permanent character string variable
@name – temporary character integer variable
@name$ – temporary character string variable
$name – permanent global integer variable
$name$ – permanent global string variable
$@name – temporary global integer variable
$@name$ – temporary global string variable
.name – npc integer variable
.name$ – npc string variable
.@name – scope integer variable
.@name$ – scope string variable
#name – permanent local account integer variable
#name$ – permanent local account string variable
##name – permanent global account integer variable
##name$ – permanent global account string variable

If a variable was never set, it is considered to equal zero for integer
variables or an empty string (“”, nothing between the quotes) for string
variables. Once you set it to that, the variable is as good as forgotten
forever, and no trace remains of it even if it was stored with character or
account data.

Some variables are special, that is, they are already defined for you by the
scripting engine. You can see the full list somewhere in ‘db/const.txt’, which
is a file you should read, since it also allows you to replace lots of numbered
arguments for many commands with easier to read text. The special variables most
commonly used are all permanent character-based variables:

StatusPoint – Amount of status points remaining.
BaseLevel – Current base level
SkillPoint – Amount of skill points remaining
Class – Current job
Upper – 1 if the character is an advanced job class.
Zeny – Current amount of zeny
Sex – Character’s gender, 0 if female, 1 if male.
Weight – The weight the character currently carries.
MaxWeight – The maximum weight the character can carry.
JobLevel – Character’s job level
BaseExp – The amount of base experience points the character has.
Notice that it’s zero (or close) if the character just got a level.
JobExp – Same for job levels
NextBaseExp – Amount of experience points needed to reach the next base level.
NextJobExp – Same for job levels.
Hp – Current amount of hit points.
MaxHp – Maximum amount of hit points.
Sp – Current spell points.
MaxSp – Maximum amount of spell points.
BaseJob – This is sneaky, apparently meant for baby class support.
This will supposedly equal Job_Acolyte regardless of whether the
character is an acolyte or a baby acolyte, for example.
Karma – The character’s karma. Karma system is not fully functional, but
this doesn’t mean this doesn’t work at all. Not tested.
Manner – The character’s manner rating. Becomes negative if the player
utters words forbidden through the use of ‘manner.txt’ client-side
file.

While these behave as variables, do not always expect to just set them – it is
not certain whether this will work for all of them. Whenever there is a command
or a function to set something, it’s usually preferable to use that instead. The
notable exception is Zeny, which you can and often will address directly –
setting it will make the character own this number of zeny.
If you try to set Zeny to a negative number, the script will be terminated with an error.

发布留言

发布留言必须填写的电子邮件地址不会公开。 必填字段标示为 *