View Single Post
  #12  
Old 05-08-2012, 06:34 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Once again, please put your code in PHP tags. Cleaning up a little bit and commenting some basic problems:
PHP Code:
function onActionServerSide(NULL) { // camel case; don't use NULL here, use some named argument, e.g. "cmd"
  
switch (params[0]) { // don't use params[0], use your named argument like "cmd"
    
case "givekey"// general consensus is don't use braces here, they're misleading since they don't do anything
      
if (clientr.quest1 == NULL) { // no reason to do this check
        
clientr.quest1 1;     // use true instead of 1 in this case, it's
        
clientr.items.key1 1// clearer to those trying to read your script
      
}
    break;
  }
}

//#CLIENTSIDE
function onPlayerTouchsMe() { // camel case
  
player.chat "Test";
  
this.chat "Test"// don't use GS1; in addition, don't use message, even in GS2 (set this.chat instead)
  
triggerserver("gui"this.name"givekey");

Now that the code is clean and readable, we can talk about why it's not working. I'm guessing you're putting this in a weapon script, but even if you are putting it into an NPC, it won't work.

Assuming it's in a weapon, when would onPlayerTouchsMe ever get called? A weapon isn't an object in-game; it's a background script that runs on the client. It has no physical representation, and hence nothing to touch. This will never be called.

So, the best way to do this is to move your code into an NPC. Then, when the NPC is touched, you'll notice that the player and the NPC both say "Test", but that the trigger never reaches serverside.

If you've read about triggers, you'll know why. The trigger is being sent to a weapon with the NPC's name, but that weapon doesn't exist. In addition to that, level NPC names are arbitrary and somewhat unpredictable.

Normally you'd need to trigger serverside on the NPC instead, but this is a pain. In your case, it's actually a lot simpler than that: onPlayerTouchsMe is called serverside in addition to clientside, so there's no need to communicate between them. We can simplify your code:

PHP Code:
function onPlayerTouchsMe() {
  
player.chat "I completed the quest!";
  
  
// set the player flags
  
player.clientr.quest1 true// prefixing with player. is somewhat less ambiguous
  
player.clientr.items.key1 true;

Then if we want to check if the player has completed the quest later on...

PHP Code:
if (player.clientr.quest1) {
  
player.chat "You've already completed the quest!";
} else {
  
player.chat "You haven't completed the quest yet!";

(if your onPlayerTouchsMe still isn't being called on the serverside, make sure to give it a proper shape—normally this isn't necessary if you're using an image for the NPC)
__________________
Reply With Quote