Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Arc hitbox system for weapons triggering three times per swing. (https://forums.graalonline.com/forums/showthread.php?t=134263337)

Jiroxys7 05-25-2011 12:21 AM

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);
                    }
                  }
                }
              }
            }
      } 


DustyPorViva 05-25-2011 12:35 AM

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.

fowlplay4 05-25-2011 12:55 AM

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);
      }
    }
  }




All times are GMT +2. The time now is 01:18 AM.

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