Quote:
Originally Posted by iDigzy
Thanks, I knew about fowlplay's but I'll check out the gscript dev one
I have another question, (I think it would be better just to post any questions I have under this thread instead of spamming forums, not sure). I am trying to make a staff block/spawn and npc. I somewhat know how to make it, but I'm not sure how you would do it. This is my current script so far.
NPC Code:
//#CLIENTSIDE
function onPlayerChats() {
if (player.chat = ":blockspawnon") {
enabled = true;
if (player.chat = ":blockspawnoff") {
enabled = false;
}
if (enabled = true) {
player.chat = "Block Spawned!";
putnpc("block.png","test",30,30);
this.chat = "block";
drawunderplayer();
block();
}
}
}
|
when comparing values you need to use '==' rather than '=', as '=' is for assigning values and when assigning values it always returns true
for this example you should be assigning the variable using the 'this.' prefix, otherwise it would apply globally which would cause conflict if there were multiple copies of this npc
its also good to avoid checking conditions you already know to be false, for example you can do -
PHP Code:
if (player.chat == ":blockspawnon") {
this.enabled = true;
}
else if(player.chat == ":blockspawnoff") {
this.enabled = false;
}
or -
PHP Code:
this.enabled = (player.chat == ":blockspawnon") ? true :
(player.chat == ":blockspawnoff") ? false : this.enabled
;