PDA

View Full Version : Trigger Server for another player


sssssssssss
01-11-2014, 08:16 PM
I could have sworn I've done this before, but maybe I'm wrong. pl.triggerServer just throws the error

Script: Function Player Indalecio_Azmaveth.triggerServer not found in function doPlayerSword in script of Weapon -System/Movement


I have to trigger the server to use findplayer with the params, then pl.triggerclient, then trigger back to the server with the player that got hurt so I can subtract the health server side. Isn't there a better way? I've already tried adding in a function to a class that's joined to the player and it was useless as well.


for (temp.pl: temp.closePlayers) {
if (pl == player || pl.guild == player.guild || pl.isdead || pl.ispause) continue;

if ((pl.x + 1.5) in |myx1, myx2| && (pl.y + 2) in |myy1, myy2|) {
pl.triggerServer("weapon", this.name, "hurtPlayer", pl, killer, killerg);
}
}

fowlplay4
01-11-2014, 08:22 PM
It's just triggerserver. also since you're looping go through and add the players to an array and send that to the serverside instead of 1 or more triggers.

In theory all you should need is:


for (temp.pl: temp.closePlayers) {
if (pl == player || pl.guild == player.guild || pl.isdead || pl.ispause) continue;
if ((pl.x + 1.5) in |myx1, myx2| && (pl.y + 2) in |myy1, myy2|) {
temp.hurt.add(temp.pl.account);
}
}
if (temp.hurt.size() > 0) {
triggerserver("gui", this.name, "hurtplayers", temp.hurt);
}


then on the server-side:


temp.hurtplayers = params[1];
for (temp.pl: temp.hurtplayers) {
temp.pl = findplayer(temp.pl);
if (temp.pl == NULL || !(temp.pl in players)) continue;
if (pl == player || pl.guild == player.guild || pl.isdead || pl.ispause) continue;
temp.dist = vectordist({temp.pl.x, temp.pl.y, 0},{player.x, player.y, 0});
if (temp.dist < 5) {
temp.pl.hp--;
temp.pl.setani("hurt", "");
temp.pl.triggerclient("gui", "-System/Damage", "washurt");
}
}

sssssssssss
01-11-2014, 08:26 PM
does vectordist kill the need for my to calculate the xy for the sword distance and if the other player is in it?

Not sure why it's there to be honest.

Also I'm using clientr.vars for the hp, so wouldn't I have to trigger a weapon function for each player hurt to update that, since it's not accessible for anything like pl.clientr.hp?

sssssssssss
01-12-2014, 02:14 AM
I got it triggering back to the client for the pl again, then back serverside to change the clientr.vars, then back clientside to handle death or anything else. If there's a better way someone please let me know.

Thanks!

fowlplay4
01-12-2014, 02:24 AM
does vectordist kill the need for my to calculate the xy for the sword distance and if the other player is in it?

Not sure why it's there to be honest.

Also I'm using clientr.vars for the hp, so wouldn't I have to trigger a weapon function for each player hurt to update that, since it's not accessible for anything like pl.clientr.hp?

Serverside positions aren't always going to match with the clientside so it does a proximity check.

Replace temp.pl.hp--; with your own variable or whatever you do to 'damage' the player. You shouldn't have to trigger the client then back to the server again.

sssssssssss
01-12-2014, 03:01 AM
I would just be taking out of clientr.hp, but it's not accessible by pl.clientr.hp correct?

cbk1994
01-12-2014, 03:54 AM
I would just be taking out of clientr.hp, but it's not accessible by pl.clientr.hp correct?

Yes, that's exactly how you should access it. Serverside you can use findPlayer to get another player object. The only difference between "temp.pl" and "player" in this case is that player is available automatically. They're both TServerPlayer objects, and you can do the same things to etiher of them. There's no reason to trigger clientside and then back.

It might help to remember that clientr.hp is really the same thing as player.clientr.hp. So you can also do findPlayer("fowlplay4").clientr.hp.

If you want to do it properly you should move this into a player class so you can just do findPlayer("fowlplay4").attack(9999, player) or whatever and not have to recycle the same logic everywhere you need to do damage.

sssssssssss
01-12-2014, 04:10 AM
thanks for the help you guys. :)