Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-24-2011, 05:26 PM
BrianD BrianD is offline
Registered User
Join Date: Jun 2011
Posts: 2
BrianD is on a distinguished road
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.
Reply With Quote
  #2  
Old 06-24-2011, 06:16 PM
skillmaster19 skillmaster19 is offline
Registered User
Join Date: Oct 2010
Posts: 392
skillmaster19 will become famous soon enough
Can we see the next function? I may be able to come up with a better way to fix it.
Reply With Quote
  #3  
Old 06-24-2011, 06:18 PM
0PiX0 0PiX0 is offline
Coder
0PiX0's Avatar
Join Date: Jan 2011
Posts: 130
0PiX0 is a jewel in the rough0PiX0 is a jewel in the rough
Quote:
Originally Posted by BrianD View Post
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();

Reply With Quote
  #4  
Old 06-24-2011, 06:21 PM
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
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.
__________________
Reply With Quote
  #5  
Old 06-25-2011, 11:50 AM
BrianD BrianD is offline
Registered User
Join Date: Jun 2011
Posts: 2
BrianD is on a distinguished road
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!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:55 PM.


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