Simple variable problem
#1

Hey guys, I am having some issues setting a variable and I have no idea what I am doing wrong. I've tried doing this a bunch of ways but for some reason nothing seems to work. I feel ridiculous asking such a simple question but like i said I just cant get it.

I want to pay a player based on how much health their vehicle has when they enter a checkpoint. So I have everything done except for setting the price to the health. What I want is for the variable price to be set to a quarter of what the current vehicles health is. I have:
pawn Код:
new price, Float:Health; // How much you'll earn & vehicle HP
new vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, Health);
if(Health < 255) format(string,sizeof(string),"Vehicle is too damaged to receive a bonus.");
else
{
    price = Health/4;
    format(string,sizeof(string),"+ ~g~$%d~w~ added to your next paycheck.",price);
}
Something like this, what I am having trouble with is literally setting price to a quarter of health.. Thanks guys..
Reply
#2

You are using the string but you are not sending the client message..
Reply
#3

No thats not the issue, I havnt posted the entire code because its sending the string just fine. The problem is with setting the variable price to the amount of Health. Whats happening is its paying TONS of money.
pawn Код:
if(Health <= 255) SendClientMessage(playerid, COLOR_LIGHTRED, "The truck is too damaged to receive a bonus.");
            else price += (Health / 4);
I'm not sure what the issue is or how to fix it. Like I said, I've tried it many ways. I'm just missing something here?
EDIT: When I use:
pawn Код:
if(Health < 250) SendClientMessage(playerid, COLOR_LIGHTRED, "The truck is too damaged to receive a bonus.");
else if(Health > 250 ) price = 50;
else if(Health > 500) price = 100;
else if(Health > 700) price = 125;
else if(Health > 800) price = 150;
else if(Health > 900) price = 175;
else if(Health > 950) price = 200;
It works just fine, but thats predefined. Im trying to make it so price is calculated off a quarter of the vehicles health. What am I doing wrong?
Reply
#4

It's because 'price' is an Integer and you're trying to assign it as a float. Try this:

pawn Код:
price = floatround(Health/4);
Reply
#5

See, I knew it was something simple. Ahh. Thank you alot MP2 that worked and I'm so grateful.
Reply
#6

Tbh, shouldn't it be '(1000.0 - Health) / 4' ?

That way, you earn more money the more damaged the vehicle is.
Reply
#7

if(Health < 250) SendClientMessage(playerid, COLOR_LIGHTRED, "The truck is too damaged to receive a bonus.");
else if(Health > 250 ) return GivePlayerMoney(playerid,50);
else if(Health > 500) return GivePlayerMoney(playerid,100);
else if(Health > 700) return GivePlayerMoney(playerid,125);
else if(Health > 800) return GivePlayerMoney(playerid,150);
else if(Health > 900) return GivePlayerMoney(playerid,175);
else if(Health > 950) return GivePlayerMoney(playerid,200);
Reply
#8

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Tbh, shouldn't it be '(1000.0 - Health) / 4' ?

That way, you earn more money the more damaged the vehicle is.
He want the price to increase when the damage decrease or health increase.
Reply
#9

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Tbh, shouldn't it be '(1000.0 - Health) / 4' ?

That way, you earn more money the more damaged the vehicle is.
Why would you want to give them MORE money for a DESTROYED vehicle..? What kind of backwards logic is that?
Reply
#10

Quote:
Originally Posted by MP2
Посмотреть сообщение
Why would you want to give them MORE money for a DESTROYED vehicle..? What kind of backwards logic is that?
Repairman/Mechanic... As the post wasn't too clear, seeing 'payday' I assumed this was the desired effect.
But now after reading it fully, I see the 'checkpoint' part.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)