Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom fighting system..can't alter variable properly? (https://forums.graalonline.com/forums/showthread.php?t=134263652)

BrianD 06-24-2011 05:26 PM

Custom fighting system..can't alter variable properly?
 
I've designed a custom sword/fighting system for my server, and can't seem to work out the only real problem. I use findnearestplayers to recognize the closest player, and tokenize it, however this sometimes turns out in client.hurt[1] being my own account, and not the nearest account besides my own. in theory, client.hurt[0] should be my own account, and the second closest player to me besides myself is client.hurt[1]...however it's sporadic and i'm not sure why.

Anyways. I tried to make it so if it recognizes client.hurt[1] as the player's account it changes it to client.hurt[0] but this is not working. Any suggestions?
PHP Code:

//#CLIENTSIDE
function activePlayers() 
{
temp.player.x;
temp.player.y;
client.acc player.account;
client.hurtfindnearestplayers(temp.xtemp.y);
client.hurt.tokenize(",");
if (
client.hurt[1] == player.account) {
client.hurt[1] = client.hurt[0];
}
Attack(client.typeplayer.dir); //next function which would calculate 
                                          //if the player is close enough to client.hurt[1]
                                         //to hurt him.
 


with this script, after it does the attack function, it moves serverside to distribute health loss. Here's what it echos to show you how it screws up client.hurt[1] and client.hurt[0]:

PHP Code:

Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
Weapon
/GUI-script +Fighting added/updated by BrianD
Weapon
/GUI-script +Fighting added/updated by BrianD
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt pc:5390521 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 2
<b>Fighting:Graal778318 hurt Graal778318 for 

Forgive my sloppiness by the way haha, i'm not a neat scripter.

skillmaster19 06-24-2011 06:16 PM

Can we see the next function? I may be able to come up with a better way to fix it.

0PiX0 06-24-2011 06:18 PM

Quote:

Originally Posted by BrianD (Post 1655997)
I use findnearestplayers to recognize the closest player, and tokenize it, however this sometimes turns out in client.hurt[1] being my own account, and not the nearest account besides my own. in theory, client.hurt[0] should be my own account, and the second closest player to me besides myself is client.hurt[1]...however it's sporadic and i'm not sure why.

You do need to work on your styling, but anyway... Examine this.
PHP Code:

for (temp.plfindnearestplayers(temp.xtemp.y)) {
  
// make sure the player cannot hit self
  
if (temp.pl == player
    continue;
  
// break the loop if the target is not in range
  
if (vectordist({temp.pl.xtemp.pl.y0}, {temp.xtemp.y0}) > 3
    break;
  
// damage target
  
temp.pl.damageTarget();



cbk1994 06-24-2011 06:21 PM

There's a couple problems, but the main one is you're using it wrong. It's not returning a string of accounts, it's returning an array of players. The only reason tokenizing it works is because it's being coerced into a string of comma-separated accounts.

Try this instead:

PHP Code:

temp.closePlayers findNearestPlayers(temp.xtemp.y);
temp.playerToHit null;

for (
temp.closePlayer temp.closePlayers) {
  if (
temp.closePlayer == player) {
    continue; 
// can't hit yourself
  
}
  
  
temp.playerToHit temp.closePlayer;


Then you can use temp.playerToHit which is a player object of the closest player.

BrianD 06-25-2011 11:50 AM

Wow you guys responded really fast! was not expecting that.

I ended up using a slightly altered version of cbk's example. Thanks everyone who responded!


All times are GMT +2. The time now is 06:56 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.