A new npcserver has been uploaded which uses new optimized onwall check and uses the "dummy" npcs for that too (npcs that don't have scripts or only clientside stuff, which were not blocking on serverside before). If possible restart both npcserver and gserver because they also use more precise player positions now (more smooth movement of other players).
In the new scripting engine you can also use setshape2 now. The weapons have been fixed:
Variables and functions for handling the weapon scripts:
player.weapons[] - array of objects
player.findweapon("name") - object
player.weapon - object, current weapon, clientside only
findweaponnpc("name") - object, find 'global' weapon object, serverside only
Automatic mappings for compatibility:
weaponscount -> player.weapons.size()
findweapon("name") -> player.findweapon("name")
hasweapon(name) -> (player.findweapon("name")!=NULL)
#w -> player.weapon.name (clientside only)
#w(index) -> player.weapons[index].name
#W -> player.weapon.image (clientside only)
#W(index) -> player.weapons[index].image
Update:
New stuff for new scripting engine:
- fixed the problem of local npc syntax errors being displayed on RC chat, they are all put into syntaxerrors.txt now
- variables like this.pi or this.switch are working now and dont give errors anymore (pi, switch etc. are reserved words and were not allowed inside variable names before)
Update2:
- optimized saving of npcs, it is not called anymore if not needed, so it's speeding up the npcserver start and taking less cpu time
- if the script exceeds the loop limit of 10000 (e.g. in a for-loop) or is not finding a function then it is displaying the script line (serverside only)
- the number of active npcs is correctly displayed
Update3:
- if you have a variable that is 0 then strlen will return 0. Example:
this.myvar = 0; setplayerprop #c,length: strlen(#s(this.myvar));
This should help for better compatibility, since in the new engine it is meant to be 0==false=="". If you do this.myvar = "0"; then it will display the length 1 like it should be (since it is a string then).
- player.join("classname") is working now, so you can let the player join a class (onCreated() will be invoked the first time it joins a class) and call scripting functions like player.additem("testitem") if you have defined a public function additem() in the joined class. Example:
Control-NPC:
PHP Code:
function onActionPlayerOnline() {
player.join("testclass");
player.dosomething();
player.trigger("attack",123);
}
testclass:
PHP Code:
function onCreated() {
echo("oncreated for " @ player.account);
}
public function dosomething() {
echo("dosomething for " @ player.account);
}
function onAttack(val) {
echo("onAttack for " @ player.account @ " - " @ val);
}
Remarks:
- obj.trigger(event,parameters) is a replacement for "callnpc" in the new scripting engine
- in the above code you actually don't need to do "player.account", you can also directly access the account name or other attributes of the player without using the "player." in front because the script is run for the player, so you could do echo("new player: " @ account)
Update4:
- number-to-string conversion modified again to fix problems with the update3: when outputing zero it is correctly displaying "0", but when an empty string is received from the client it is not longer converted to "0"
Update5:
- tiletype(x,y) and levelobject.tiletype(x,y) return the tile type for the giving position, works with both old and new tileset and also npcs that use setshape2. Set the newtilesets=true option in the server options if you are using the new tileset format, or list the levels that use new tilesets with newtilesetlevels=...,.. On clientside only tiletype(x,y) for new tilesets is working, except you are using the latest version of v4, then you have the same functionality like on serverside.
- findlevel(name) returns the level object for the specified level name. Gmaps are one big level, so don't use the name of map part levels with this.
- levelobject.tiles[x,y] works now (instead of just tiles[x,y] from the current level)