Solved Modulus Operator

Question that is answered or resolved.

O Ilusionista

Captain 100K
I am trying to code a healing factor, which will heals the player from time to time.
I tried to use Modulus, but OpenBOR crashes. It isn't supported?

This is what I was doing (this is declared at SCRIPT):
void main(){
void self = getlocalvar("self"); //Get calling entity.
void health = getentityproperty(self,"health"); //get health
int time = openborvariant("elapsed_time");// get time
//int eta = openborvariant("game_speed")*0.5;
if ( time % 1000=0 )
{
changeentityproperty(self, "health", health+1);//add health
}
}

I was trying using simple division, works, but not as I wanted to be:

void main(){
void self = getlocalvar("self"); //Get calling entity.
void health = getentityproperty(self,"health"); //get health
int time = openborvariant("elapsed_time");// get time
//int eta = openborvariant("game_speed")*0.5;
if ( (time/1000)*2 )
{
changeentityproperty(self, "health", health+1);//add health
}
}

Any idea?
 
Hello O'!! ;)

CORRECT:
void main(){
  void self = getlocalvar("self"); //Get calling entity.
  void health = getentityproperty(self,"health"); //get health
  int time = openborvariant("elapsed_time");// get time

  if ( time % 1000 == 0 )
  {
  changeentityproperty(self, "health", health+1);//add health
  }
}

However your code can generate bugs when you are under frames of the game speed. Use this corrected code:
Code:
void main(){
   void self = getlocalvar("self"); //Get calling entity.
   void health = getentityproperty(self,"health"); //get health
   int time = openborvariant("elapsed_time");// get time
   int recovery_time = 1000;

   time %= recovery_time*2; // game time protection OPTIONAL!!

   if ( getlocalvar("time_flag") == NULL() ) setlocalvar("time_flag",time+recovery_time);  

   if ( time >= getlocalvar("time_flag") )
   {
        if ( health < getentityproperty(self, "maxhealth") )
        {
              changeentityproperty(self, "health", health+1); //add health
              setlocalvar("time_flag",NULL());
        }
   }
}

ps. I haven't tested the code.

Bye O'!!
 
oh man, tell me that I wasn't THAT stupid and had forgot the double EQUAL sign...lol
Thanks, I will check your code

btw: its the first time I saw a "bitwise AND" in a OpenBOR script
 
Back
Top Bottom