View Single Post
  #20  
Old 02-07-2010, 12:17 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 Engine View Post
And yet another problem, I cannot seem to get this to work. I have tried multiple variations of it but nothing I could conjure up in my head seems to work. Could someone point me in the right direction.
PHP Code:
function onActionServerSide(){
  for(
pl:allplayers){
    if (
players[pl.id].x in player.-5player.| && players[pl.id].y in player.y-5player.+| ) {     
      
findplayer(pl).chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"nameNULL);
  }

Try this:

PHP Code:
function onActionServerSide(cmd) {
  if (
cmd == "hitPlayers") {
    
// before you were using 'allplayers' which is an array of every player on the server
    // 'players' is an array of every player in the current level
    // 'findNearestPlayer(x, y)' just returns every player within a level or so of the x/y given. It's a lot more efficient when used on GMAPs.
    
for (temp.pl findNearestPlayers(player.xplayer.y)) {
      if (
pl.x in |player.5player.5| && pl.y in |player.5player.5|) {
        
pl.chat "oww!!!";
        
player.chat "I hit " pl.communityname "!";
      }
    }
  }
}
//#CLIENTSIDE
function onKeyPressed() {
  if (
keydown(6)) {
    
triggerserver("gui"this.name"hitPlayers"); // it is customary to always send a command for verification purposes
  
}

Quote:
Originally Posted by DustyPorViva View Post
You need to pass the player data serverside. On the serverside your player is not the only player object, thus you need to give the script scope.

PHP Code:
function onActionServerSide(){
  for(
temp.p:allplayers){
    
temp.pl findplayer(p);
    
temp.mypl findplayer(params[0]);
    if (
pl.x in mypl.-5mypl.| && pl.y in mypl.y-5,mypl.+| ) {     
      
pl.chat pl.account;
    }
  }
}
//#CLIENTSIDE
function onKeyPressed(){
  if(
keydown(6)){
    
triggerserver("gui"name,player.account);
  }

Also, you can instead on the clientside use findnearestplayers(x,y), loop through, find the players you wish to send the chat and send the array to the serverside, instead of letting the server handle the loop.
No offense intended to Dusty, but I would ignore everything he said. You should always do things like hit detection serverside. You should always assume that the player can change any clientside code, and do everything you can serverside to prevent against hackers.

Second, if you trigger serverside, your player object is always in scope. Sending your player account with it is a huge security risk because a hacker could change this to make other players do something.

Third, this is completely unnecessary:

PHP Code:
  for(temp.p:allplayers){
    
temp.pl findplayer(p); 
p in this case is already a TServerPlayer object. Technically findPlayer(String account) shouldn't even find the player correctly. The only reason it does work is because it interprets the object as object.name, which happens to be the account name of the player. For example, you can do:

PHP Code:
for (temp.pl allplayers) {
  
pl.chat "hello";
  
pl.setlevel2("start.nw"3030);
  
  if (
pl.32) {
    
pl.16// example
  
}

Again, sorry if I give off the feeling of being offensive, just trying to help
__________________
Reply With Quote