View Single Post
  #7  
Old 02-12-2010, 12:21 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
Quote:
Originally Posted by scriptless View Post
Revised. Still not working.
You can't call serverside functions like punch() directly. Instead you have to trigger serverside using the function triggerserver, like so:

PHP Code:
// this is the event invoked serverside by triggerserver
function onActionServerSide(cmd) {
  if (
cmd == "punch") {
    
punch(player.xplayer.y);
  }
}

function 
punch(dxdy) {
  
player.chat "2";
  if ( 
player.ani != "human2_swim" ) {
    if ( 
player.ani != "human2_hthc_punch" setani"human2_hthc_punch"null);
    
freezeplayer(.5);

  for (
temp.pl findNearestPlayers(dxdy)) {
    if (! (
dx in |player.xplayer.3| && dy in |player.yplayer.3|)) {
      continue;
    }
    if (
pl == player) {
      continue;
    }
    
    
pl.hit(0.5player);
  }

   
// I'm not sure what this is supposed to do?
   /* waitfor( GraalControl, "punch", .5);
    if ( this.keyb_d == true ) {
      setani( "human2_shield_hold", null );
      onshield();
    } else  setani( "human2_idle" , null );
  }*/
}

// normally it is best to use the onActionPlayerOnline even evoked in
// Control-NPC since onPlayerLogin() isn't called for each player
// if the NPC-server restarts, which causes problems since
// classes don't join
function onPlayerLogin(pl) { // onCreated is only called when the script is updated
  // allow ourselves to hurt :o
  
pl.join("hurt");
}

//#CLIENTSIDE
function onCreated() {
  
// all of this has to be done clientside
  
disableweapons();
  
addtiledef("picso2.png","psi_"0);
  
enablefeaturesallfeatures ---0x10 -0x20 );
  
showstats(256 512 1024);
}
function 
GraalControl.onKeyDown(keycodekeychar) {
  
this.("keyb_" keychar) = true;
  switch( 
keychar ) {
    case 
"s":
      
player.chat "1";
      
triggerServer("gui"this.name"punch"); // tell serverside to punch
    
break;
    case 
"d":
      
setani"human2_shield_hold"null );
      
this.playerdir player.dir;
      
onshield();
    break;
  }
  if ( 
keycode == ) {
    
this.keyb_d false;
    
setani"human2_idle"null );
    
shield();
  }

A brief explanation of clientside and serverside:

Clientside is code that is ran directly on the players computer. This allows you to create effects, show images for only that player (including things like health interfaces), do things when the player presses a key, etc. The benefit to clientside code is that there is no delay between when the player tries to do something and when it happens. For example, if you had a clientside punching system, they would immediately see the punch. The disadvantage to clientside code is that it is run on the player's computer, and therefore it can be modified to some degree. It is very easy to disable onwall checks in a clientside movement system, for example. Because clientside code is local, it can't communicate with other players.

Serverside is code that is ran on the NPC-server. This allows you to create solid systems that can interact with every player. An example of serverside code would be a "monster" like on GK which runs serverside and sends back the updates such as position, GANI, and so on, where it is displayed clientside. The advantage to serverside scripting is that it is secure and can't be tampered with by any player. You can also communicate with other players. The disadvantage is that there is a "lag" time between when the user does something and when it happens, depending on the player's internet connection.


To communicate between the two you have to use things called triggers. There's a pretty good explanation of those in this thread.
__________________
Reply With Quote