Help with a little battlescript

Started by Mouth for war, Thu 03/10/2013 19:52:16

Previous topic - Next topic

Mouth for war

Ok this is what I have.(Feel free to simplify this by all means...coding is NOT my strong side hehe)It seems to work  but I don't want the Maxdamage variable to deal max damage all the time. How can I write so that the Maxdamage deals a random number of damage between 1 and max? Thanks in advance!!

Code: ags

function room_RepExec()
{
  if(Damageenemy==1){
  Damageenemy=3;
  int dam=Random(7);
  if(dam==0){
  enemyhp-=1+blunt+strength+Maxdamage;
}
  else if(dam==1){
  enemyhp-=2+blunt+strength+Maxdamage;
}
  else if(dam==2){
  enemyhp-=3+blunt+strength+Maxdamage;
}
  else if(dam==3){
  enemyhp-=4+blunt+strength+Maxdamage;
}
  else if(dam==4){
  enemyhp-=5+blunt+strength+Maxdamage;
}
  else if(dam==5){
  enemyhp-=0;      //player miss
}
  else if(dam==4){
 enemyhp-=critical+blunt+strength+maxdamage;
}
}
}
mass genocide is the most exhausting activity one can engage in, next to soccer

Khris

#1
First of all, the Random parameter is included. This means Random(7) will generate a random number from 0 to 7, not 0 to 6.

You seem to want a base damage of 1 to 5, or a miss, or a critical hit.
The obvious thing to do is use the random value itself in the calculation.

Code: ags
    int base_damage = Random(6);

    if (base_damage == 0) {
      // player misses
    }
    else {
      if (base_damage == 6) base_damage = critical; // special case
      enemyhp -= base_damage + blunt + strength + Random(maxdamage - 1) + 1;
    }


Also, indentation.

Btw, if this code does nothing if the player misses, you can use if (base_damage > 0) and get rid of the else construct.

Mouth for war

Thanks that seemed to simplify it quite a lot :D
mass genocide is the most exhausting activity one can engage in, next to soccer

SMF spam blocked by CleanTalk