Quote:
Originally Posted by Mark Sir Link
thiso.price and thiso.weapon are undefined on the serverside, you need to use the params you are sending in triggerserver, you need to invoke the object for addweapon (player.addweapon())
You also really shouldn't define the weapon name and cost on the clientside since it opens it up for all sorts of abuse.
|
He says he's using a class and a level npc, therefore using triggerserver won't work for what he's trying to do.
Also there's no problem with defining it client-side (saves a trip for sending the data via triggerclient, attribute or similar), the problem comes into play when you're not validating it on the server-side or when you don't keep them in sync (the same).
So we can setup a weapon system to do this or use the simple triggeraction method which is a little more newbie friendly.
Syntax:
triggeraction(x, y, actionName, param0, param1, [...])
x - The x coordinate to trigger
y - The y coordinate to trigger
actionName - The actionEvent to hit. I.e: Passing "Buy" will trigger onActionBuy on the server-side
param0, param1, ... - Parameter data/message to send to the server.
Example usage:
PHP Code:
function onCreated() {
// Give the object shape on the server-side
// This is very important or else the triggeraction won't "hit" it.
this.setshape(1, 32, 32);
}
function onActionBuy() {
// Check the ID passed
// Prevents stacked NPCs from reacting to triggers that don't concern them.
if (params[0] == this.id) {
player.chat = "Bought an " @ params[1] @ "!";
}
}
//#CLIENTSIDE
function onCreated() {
this.chat = "Say '/buy' to execute this example!";
}
function onPlayerChats() {
if (player.chat == "/buy") {
// Sends a "Buy" trigger to the coordinates
// this calls onActionBuy on both server and client sides.
triggeraction(this.x + 1, this.y + 1, "Buy", this.id, "example");
}
}