| cbk1994 |
02-07-2010 12:17 AM |
Quote:
Originally Posted by Engine
(Post 1554676)
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.x -5, player.x + 5 | && players[pl.id].y in | player.y-5, player.y +5 | ) { findplayer(pl).chat = pl.account; } } } //#CLIENTSIDE function onKeyPressed(){ if(keydown(6)){ triggerserver("gui", name, NULL); } }
|
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.x, player.y)) { if (pl.x in |player.x - 5, player.x + 5| && pl.y in |player.y - 5, player.y + 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
(Post 1554678)
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.x -5, mypl.x + 5 | && pl.y in | mypl.y-5,mypl.y +5 | ) { 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", 30, 30); if (pl.x > 32) { pl.x = 16; // example } }
Again, sorry if I give off the feeling of being offensive, just trying to help :)
|