Adding and subtracting how much damage is dealt. (solved)

Started by Icey, Fri 30/12/2011 00:42:27

Previous topic - Next topic

Icey

In my game when you attack the target at row 1[r1] you are supposed to hit him with your normal ATK strength and +3 extra points cause your attacking from row 1. And if you were attack from r3 then you would attack with your normal ATK strength and -3 extra points cause you attacked from row 3.

The problem is that the target is gaining life from the +3. Instead what happens is the player is dealing the dmg but instead f dealing less dmg he is dealing normal dmg and the enemy is add the +3 to it's life.

Also I think it's the +3 but it could be the -3 but ether way the problem remains and I would like to keep this cool effect with the adding/subtracting dmg without this annoying problem.

Code: ags

if(rows.NormalGraphic == 163){ real  close to the target
    Target_Hp -= daveATK+3;
    GiveScore(daveATK+3);
  }
else if(rows.NormalGraphic == 162){ mid-distance
    Target_Hp -= daveATK;
    GiveScore(daveATK);
  }
else if(rows.NormalGraphic == 163){  far away from target
    Target_Hp -= daveATK-3;
  GiveScore(daveATK-3);
  }

Khris

The lines that change Target_Hp seem fine.

What I noticed is that it says 163 in the third condition, too; this is probably not the reason for what you describe but it's a bit hard to tell without seeing the rest of the code.

Icey

Ohh that's not supposed to be like that however it wouldn't really matter seeing how you can only do physical dmg at row 1. That code may be for up close attacks but it the same problem is happening with distant attacks as well like magic and stuff.


Icey

Ohh and here is the is 1 of the atk codes taken from the list of available commands.

Code: ags

if(player.ActiveInventory == spark){
  if(DaveMp <= 0){
    DisplayAt(115, 10, 200, "No more MP!");
  }
  else if(DaveMp >= 0){
 commandmenu.TweenTransparency(0.2, 100, eLinearTween, eNoBlockTween);
  gStatusline.TweenTransparency(0.3, 100, eLinearTween, eBlockTween);
  
 player.StopMoving();
  player.FaceObject(target, eBlock);
  DisplayAt(115, 10, 200, "Shock");//Distant attack name
  
  Dave.ChangeView(33);
  Dave.Animate(0, 4, eOnce, eBlock, eForwards);
  bolt.SetPosition(target.X+30, target.Y-40);
  bolt.SetView(34);
  bolt.Transparency = 0;
  bolt.Visible = true;
  bolt.Animate(0, 3, eOnce, eBlock, eForwards);
  bolt.TweenTransparency(0.2, 100, eLinearTween, eNoBlockTween);
  
  //target.Tint(
  target.Transparency = 100;
  Wait(1);
  target.Transparency = 0;

  
  
    if(rows.NormalGraphic == 163){
        rows.NormalGraphic = 163;
  Target_Hp -= DaveMGK+3;
  //GiveScore(daveATK+3);
  GiveScore(DaveMGK+1);
  }
  else if(rows.NormalGraphic == 164){
      rows.NormalGraphic = 164;
  Target_Hp -= DaveMGK;
  //GiveScore(daveATK);
  GiveScore(DaveMGK);
  }
  else if(rows.NormalGraphic == 165){
      rows.NormalGraphic = 165;
  Target_Hp -= DaveMGK-3;
  GiveScore(DaveMGK-1);
  }
  PlayerEXP += 2;
     player.FaceObject(target, eBlock);
     player.ChangeView(24);
     player.FaceObject(target, eBlock);
     
       ////////////////////////////////////////////////////////////////////////////////////////
      indi.SetPosition(target.X+70, target.Y-120);
      Label28.Visible = false;
      Label39.Visible = false;
      Label29.Visible = false;
      Label3.Visible = true;
      indi.Visible = true;
      indi.Transparency = 0;
      indi.TweenTransparency(0.5, 100, eLinearTween, eNoBlockTween);
      indi.TweenPosition(0.3, target.X+70, target.Y-135, eLinearTween, eBlockTween);
      indi.Visible = false;
  /////////////////////////////  
  DaveMp -= 4;
     
   if(Target_Hp <= 0){//killed enemy
    mouse.Mode = eModeWalkto;
     target.Tint(204, 0, 0, 50, 100);
     target.TweenTransparency(1.0, 100, eLinearTween, eBlockTween);
     itemorb1.Visible = true;
     itemorb2.Visible = true;
     itemorb3.Visible = true;
     itemorb1.Transparency = 100;
     itemorb2.Transparency = 100;
     itemorb3.Transparency = 100;
     
     itemorb1.TweenTransparency(0.2, 0, eLinearTween, eNoBlockTween);
     itemorb2.TweenTransparency(0.2, 0, eLinearTween, eNoBlockTween);
     itemorb3.TweenTransparency(0.2, 0, eLinearTween, eBlockTween);
     
     itemorb1.TweenPosition(0.4, itemorb1.X, 142, eEaseOutTween, eNoBlockTween);
     itemorb2.TweenPosition(0.4, itemorb2.X, 138, eEaseOutTween, eNoBlockTween);
     itemorb3.TweenPosition(0.4, itemorb3.X, 145, eEaseOutTween, eBlockTween);
    if(Game.DoOnceOnly("victory")){
     Dave.Say("Yeah I did it!");
     //? view
     Dave.Say("But what are those orb?");
     Display("Reward Orbs");
     Display("After defeating a Boss you will be rewarded with a few items.");
     Display("Random items will be selected by the game to give to the player");
     //Display("");
    }
     
     enemyset0=Random(2);
     itemorb1.TweenTransparency(0.2, 100, eLinearTween, eBlockTween);
if (enemyset0==0){//Potion
  player.AddInventory(potion);
  Label7.Text = "Potion";
  Display("Got Potion!");
}
if (enemyset0==1){//ether
  player.AddInventory(ether);
  Label7.Text = "ether";
  Display("Got ether!");
}
if (enemyset0==2){//elixer
  player.AddInventory(elixer);
  Label7.Text = "elixer";
 Display("Got elixer!");
}

enemyset1=Random(2);
itemorb2.TweenTransparency(0.2, 100, eLinearTween, eBlockTween);
if (enemyset1==0){//Potion
  player.AddInventory(ether);
  Label8.Text = "ether";
  Display("Got ether!");
}
if (enemyset1==1){//ether
  player.AddInventory(elixer);
  Label8.Text = "elixer";
 Display("Got elixer!");
}
if (enemyset1==2){//elixer
  player.AddInventory(potion);
  Label8.Text = "Potion";
  Display("Got Potion!");
 }
  
enemyset2=Random(2);
itemorb3.TweenTransparency(0.2, 100, eLinearTween, eBlockTween);
if (enemyset2==0){//Potion
player.AddInventory(elixer);
  Label32.Text = "elixer";
 Display("Got elixer!");
}
if (enemyset2==1){//ether
  player.AddInventory(potion);
  Label32.Text = "Potion";
  Display("Got Potion!");
}
if (enemyset2==2){//elixer
    player.AddInventory(ether);
  Label32.Text = "ether";
  Display("Got ether!");
 }
  
  
//victory pose    
  
  tokens += 25;
  Poly_points += 45;
  
  if(game.score == 1 - 30){
    Button43.NormalGraphic = 277;
  }
  else if(game.score == 31 - 60){
    Button43.NormalGraphic = 276;
  }
  else if(game.score == 61 - 90){
    Button43.NormalGraphic = 275;
  }
  else if(game.score >= 91){
    Button43.NormalGraphic = 274;
  }
  
  
resultsbg.Transparency = 0;  
  resultsbg.Visible = true;
  
  resultsbg.TweenTransparency(0.5, 0, eEaseInTween, eBlockTween);
  
  results.Visible = true;
  
  
}
   else if(Target_Hp >= 1){
   
   
  //target.SetView(21);//damage view

  
   if(mouse.IsButtonDown(eMouseLeft)){//blocking/chance
  

int defend = Random(chance) <= BaseChance;   // 3 - 10
  bool block = (Random(99) < chance);  // 99% chance of the hit connecting
  if (block) {
    bubble.Visible = true;
  Dave.ChangeView(29);
}
else {
  
  
}
  }

  
  
    if(rows.NormalGraphic == 163){//Close range : on row [r1]
  target.SetView(32);
  target.TweenPosition(0.3, player.x, player.y, eLinearTween, eBlockTween);//move in to atack
  
if(player.View == 29){
    
}
else{
   Dave.ChangeView(40);
}
    
  target.SetView(21, 2);
  target.TweenPosition(0.3, 157, 150, eLinearTween, eBlockTween);
  target.SetView(21);
     
     
}
if(rows.NormalGraphic == 164){//distant attack [row 2]
    DisplayAt(115, 10, 200, "Flash Ray");//Distant attack name
    target.SetView(22);
    target.Animate(0, 3, eOnce, eBlock, eForwards);
    ray.Transparency = 0;
    

    //ray.TweenTransparency(0.5, 100, eLinearTween, eNoBlockTween);
    ray.TweenPosition(0.2, player.x-30, player.y, eEaseInTween, eBlockTween);
    
    //ray.SetPosition(128, 6);
  
if(player.View == 29){
    
}
else{
   Dave.ChangeView(40);
}
  

  
  
}
  
if(rows.NormalGraphic == 165){//distant attack [row 3]
    DisplayAt(115, 10, 200, "Flash Ray");//Distant attack name
    target.SetView(22);
    target.Animate(0, 3, eOnce, eBlock, eForwards);
    ray.Transparency = 0;
    ray.SetPosition(128, 6);

    ray.TweenTransparency(0.3, 100, eLinearTween, eNoBlockTween);
    ray.TweenPosition(0.2, player.x-30, player.y, eEaseInTween, eBlockTween);
    ray.SetPosition(128, 6);

if(player.View == 29){
    
}
else{
   Dave.ChangeView(40);
}
  
}
  

  //make a randomizer script for AGS heroes. This can be used to fire the 2 diferent attacks the enemie has.
  bubble.Visible = false;
 

if(Dave.View == 29){
  Label292.Visible = true;
  Label282.Visible = false;
  indi2.SetPosition(player.x, player.y-70);
  indi2.Transparency = 0;
  indi2.Visible = true;
  indi2.TweenTransparency(0.5, 100, eLinearTween, eNoBlockTween);
  indi2.TweenPosition(0.3, player.x-30, player.y-125, eLinearTween, eBlockTween);
  target.SetView(21);
  indi2.Visible = false;
}
else{
  Label282.Visible = true;
  Label292.Visible = false;
  indi2.SetPosition(player.x, player.y-100);
  indi2.Transparency = 0;
  indi2.Visible = true;
  indi2.TweenTransparency(0.5, 100, eLinearTween, eNoBlockTween);
  indi2.TweenPosition(0.3, player.x, player.y-115, eLinearTween, eBlockTween);
  indi2.Visible = false;
  
  //DaveHP -= BossATK;
  if(rows.NormalGraphic == 163){
  DaveHP -= BossATK+1;
  }
  else if(rows.NormalGraphic == 164){
  DaveHP -= BossATK;
  }
  else if(rows.NormalGraphic == 165){
  DaveHP -= BossATK-1;
  }
  
  target.SetView(21);
  
}
   }
   if(DaveHP <= 1){
     StopMusic();
     Dave.Tint(204, 0, 0, 50, 100);
     Dave.TweenTransparency(1.0, 100, eLinearTween, eBlockTween);
        DisplayAt(115, 10, 200, "You have no more HP left to contnue.");
        DisplayAt(115, 10, 200, "GAME OVER");
        mouse.Mode = eModePointer;
     restp.Visible = true;
     
     
   }
  
     //end of Magic command
   
gStatusline.TweenTransparency(0.3, 0, eLinearTween, eNoBlockTween);
commandmenu.TweenTransparency(0.2, 0, eLinearTween, eNoBlockTween);

//
   player.FaceObject(target, eBlock);
        player.ChangeView(24);

}
if(player.ActiveInventory == assualtcmd){
    commandmenu.TweenTransparency(0.2, 100, eLinearTween, eNoBlockTween);
  gStatusline.TweenTransparency(0.3, 100, eLinearTween, eNoBlockTween);
  
  
  
}
}

Icey

Im not trying to bump this but I really need need to know if there is a way to fix or just drop the feature? Cause I don't wont to import the script into other rooms if this bug is still going to be there cause that means that I have to go back in and fix it in every, single script that contains that one little lines.

Tamanegi

#5
Guessing here, but have you tried:

Code: ags

if(rows.NormalGraphic == 163){
    Target_Hp -= (daveATK+3); // <- these parentheses
    GiveScore(daveATK+3);
  }
else if(rows.NormalGraphic == 162){
    Target_Hp -= daveATK;
    GiveScore(daveATK);
  }
else if(rows.NormalGraphic == 163){
    Target_Hp -= (daveATK-3); // <- these parentheses
  GiveScore(daveATK-3);
  }


Putting the calculated damage into parentheses might solve it. My guess is that "-=" is not a value assignment but a mathematical operation, which reads the same as
Code: ags

    Target_Hp = Target_Hp - daveATK + 3

And following left to right this would first substract daveATK and then add 3.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Icey

Thanks for the help. I really hope this works as it is the only thing stalling the game.

Icey


Tamanegi

Glad I could help :)

One more thought: You should check for the damage done so you won't do 1-3=-2 damage and instead heal the enemy when attacking from the third rank.

Code: ags

else if(rows.NormalGraphic == 163){
        corrected_damage = daveATK-3;
        if (corrected_damage) < 0 {
            corrected_damage = 0;
        }
      Target_Hp -= corrected_damage;
      GiveScore(corrected_damage);
  }
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Icey

I have a target scan enabled for the player it works cause magic is 2 and row3 + 3 so 100 - 5 = 95 so yeah it works :)

monkey0506

I'm surprised that the parenthesis actually resolved the issue, but it's possible that AGS does expand the -= operator to = and - before it calculates anything. In any case, I am a fan of using parenthesis any time there is more than one operator at hand, just so you know exactly what order they're being processed in. IMO it makes your code safer, especially if, like I regularly do, you're planning on reusing or letting others use it for general purpose reasons.

Oh, and icey, not sure if you got the point Tamanegi was making about the "corrected_damage" variable. If you're ever going to have the player's HP low enough that doing damage would set it below 0, then you may need to check those bounds.

Tamanegi

I also use parentheses whenever I have several operators, that's probably why I never encountered this problem.

Quote from: monkey_05_06 on Sun 01/01/2012 08:06:57
Oh, and icey, not sure if you got the point Tamanegi was making about the "corrected_damage" variable. If you're ever going to have the player's HP low enough that doing damage would set it below 0, then you may need to check those bounds.
Actually no :) My point was that if there is ever damage below 3, then substracting 3 from the damage will make the attack actually heal the target.
I don't think that HP below 0 will be a problem other than displaying a negative value.
Don't Look! MAGS 12-2010
Mediocre Expectations Current development blog

Icey

Daves ATK = 4

Dave's MGK is 2

using magic at row 3 will subtract 5(2-3)

using magic at row 1 will subtract...

Ok I got the + and - mixed up however I see what he means now cause it does - 2 on the target HP however the 3 is taking the attack away and healing him.

SMF spam blocked by CleanTalk