View Single Post
  #17  
Old 02-23-2011, 03:28 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by Mark Sir Link View Post
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(13232);
}

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.1this.1"Buy"this.id"example"); 
  }

__________________
Quote:

Last edited by fowlplay4; 02-23-2011 at 03:49 AM..
Reply With Quote