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 05-25-2011, 12:21 AM
Jiroxys7 Jiroxys7 is offline
Hazard to Graal
Jiroxys7's Avatar
Join Date: Apr 2009
Posts: 343
Jiroxys7 will become famous soon enough
Arc hitbox system for weapons triggering three times per swing.

Alright, so I incorporated this thing maybe a few months ago, and while testing something, I realized that it was triggering three times every attack. Oddly enough, it doesn't deal damage three times, but it interferes with things that trigger every time onDamage() is triggered. Weapons that do not have "arc" in the data do not use this system and therefore do not cause this problem. After some testing, I've concluded that the problem definately lies in this script, and is not caused by the initial key input nor post-onDamage() portions of the system.
Any idea as to what could be causing the issue?

PHP Code:
if(wdata[5].tokenize(",")[1] == "arc"){
    for (
temp.pl2 findNearestPlayers(player.xplayer.y)) {
      if (
dist(player.x+1player.y+1.5pl2.x+1pl2.y+1.5) <= wdata[5].tokenize(",")[2]) {
            if(!(
pl2.account in clientr.party)){
              if(
pl2.account != player.account){
                if(
player.dir == 0){
                  if(
pl2.player.y+0.5){
                    
triggeraction(pl2.x+0.5pl2.y+0.5"Damage"this.effectsplayer.account, {temp.damagetemp.criton}, temp.accuracy"Physical"100temp.armorpiercetemp.attackerlevelaxayazad);
                    if(
client.showhits){
                      
triggerserver("gui"this.name"putnpc""testblock",pl2.x+0.5pl2.y+0.5);
                    }
                  }
                }
                elseif(
player.dir == 1){
                  if(
pl2.player.x+0.5){
                    
triggeraction(pl2.x+0.5pl2.y+0.5"Damage"this.effectsplayer.account, {temp.damagetemp.criton}, temp.accuracy"Physical"100temp.armorpiercetemp.attackerlevelaxayazad);
                    if(
client.showhits){
                      
triggerserver("gui"this.name"putnpc""testblock",pl2.x+0.5pl2.y+0.5);
                    }
                  }
                }
                elseif(
player.dir == 2){
                  if(
pl2.player.y+0.5){
                    
triggeraction(pl2.x+0.5pl2.y+0.5"Damage"this.effectsplayer.account, {temp.damagetemp.criton}, temp.accuracy"Physical"100temp.armorpiercetemp.attackerlevelaxayazad);
                    if(
client.showhits){
                      
triggerserver("gui"this.name"putnpc""testblock",pl2.x+0.5pl2.y+0.5);
                    }
                  }
                }
                elseif(
player.dir == 3){
                  if(
pl2.player.x+0.5){
                    
triggeraction(pl2.x+0.5pl2.y+0.5"Damage"this.effectsplayer.account, {temp.damagetemp.criton}, temp.accuracy"Physical"100temp.armorpiercetemp.attackerlevelaxayazad);
                    if(
client.showhits){
                      
triggerserver("gui"this.name"putnpc""testblock",pl2.x+0.5pl2.y+0.5);
                    }
                  }
                }
              }
            }
      } 
__________________
MY POSTS ARE PRONE TO EDITS!
Reply With Quote
  #2  
Old 05-25-2011, 12:35 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Whenever you hit a player, do this:

continue;

this will tell the loop that you have accomplished what you needed to do in that loop instance(you hit the player, you no longer need to do the rest of the checks for the same player), and to go to the next loop.

Also, there is more that goes into hit detection than the player detection. For instance, you are probably triggering it with a keypress, which could also be the culprit.
Reply With Quote
  #3  
Old 05-25-2011, 12:55 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You might also want to move some of that code to functions. I.e:

PHP Code:
function sendTrigger(pl) {
  
triggeraction(pl.x+0.5pl.y+0.5"Damage"this.effectsplayer.account, {temp.damagetemp.criton}, temp.accuracy"Physical"100temp.armorpiercetemp.attackerlevelaxayazad); 
  if (
client.showhits){ 
    
triggerserver("gui"this.name"putnpc""testblock",pl.x+0.5pl.y+0.5); 
  }

Other functions may include:

PHP Code:
function inHittingRange(plmaxdist) {
  if (
pl == player) {
    return 
false;
  }
  if (
dist(player.1player.1.5pl.1pl.1.5) <= maxdist) {
    if (
player.dir == 0) {
      if (
pl.player.0.5) {
        return 
true;
      }
    }
    else if (
player.dir == 1) {
      if (
pl.player.0.5) {
        return 
true;
      }
    }
    else if (
player.dir == 2) {
      if (
pl.player.0.5) {
        return 
true;
      }
    }
    else if (
player.dir == 3) {
      if (
pl.player.0.5) {
        return 
true;
      }
    }
    return 
false;
  } else {
    return 
false;
  }
}

function 
inParty(pl) {
  return (
pl.account in clientr.party);

Also I would store the tokens in it's own variable, for clarity reasons and it's slightly more efficient.

Your code can then be re-factored to:

PHP Code:
temp.weapondata wdata[5].tokenize(",");
temp.weapontype temp.weapondata[1];
temp.weapondist temp.weapondata[2];
if (
temp.weapontype == "arc") {
  for (
temp.plfindNearestPlayers(player.xplayer.y)) {
    if (!
inParty(temp.pl)) {
      if (
inHittingRange(temp.pltemp.weapondist)) {
        
sendTrigger(temp.pl);
      }
    }
  }

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 09:18 AM.


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