The Dink Network

mathmod

January 27th 2006, 01:48 AM
duckdie.gif
Sorry I'm such a n00b, but if I was correct this piece of code in item-eli.c would restore half of your max health:

if (&life == 0)
return;
&life = int math_mod(int &lifemax, int 2);

Am I correct?
January 27th 2006, 06:21 AM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
No.

First, you don't need those 'int' keywords, so...

if (&life == 0)
return;
&life = math_mod(&lifemax, 2);

math_mod returns the remainder of a division operation. If &lifemax is 8, 8 divided by 2 is 4 with no remainder, so it would return 0. If &lifemax was 27, 27 divided by 2 is 13 with a remainder of 1, so it would return 1. In fact, this use of math_mod will only return 0 or 1, which isn't what you're looking for.

You'd probably want to do something like this:

if (&life == 0)
return;

int &halflifemax = &lifemax;
&lifemax / 2;
&life += &halflifemax;
if (&life > &lifemax)
{
&life = &lifemax;
}
January 27th 2006, 01:43 PM
knightg.gif
cypry
Peasant He/Him Romania
Chop your own wood, and it will warm you twice. 
int &halflifemax = &lifemax;
&halflifemax / 2;//here, I corrected redink1's script
&life += &halflifemax;
if (&life > &lifemax)
{
&life = &lifemax;
}

I guess you wanted to use math_div instead of math_mod, but this way, if dink's life was higher than half of his lifemax, it would lower dink's life(and I guess you didn't want that).
January 27th 2006, 04:26 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
Nice catch.
January 27th 2006, 04:43 PM
duckdie.gif
Sorry for causing you trouble.