Cost cash according to lost health -
Jeamie - 06.06.2018
Hello there everyone,
Actually i'm trying to script that if a player purchases Health from any shop ingame, he should cost the money according to his lost health.
for example if player has 30% health and he need to refile 70% to full his health.
So it cost money of 70% health not the 100% health money.
Thank you in advance.
Re: Cost cash according to lost health -
Verc - 06.06.2018
Use GetPlayerHealth.
Re: Cost cash according to lost health -
ISmokezU - 06.06.2018
And subtract the health from a 100 which would be x (100 - 70 = 30, x = 30)
Re: Cost cash according to lost health -
Jeamie - 06.06.2018
Quote:
Originally Posted by ISmokezU
And subtract the health from a 100 which would be x (100 - 70 = 30, x = 30)
|
case 0:
{
new Float:Health, string[128];
GetPlayerHealth(playerid,Health);
new Health3 = 100 - GetPlayerHealth(playerid,Health);
if (GetPlayerMoney(playerid) < Health3*100) return SendScreenMessage(playerid, LOCALE_MESSAGE_CANNOTAFFORD);
TakePlayerCash(playerid, Health3*100);
SetPlayerHealth(playerid, Health3);
format(string,sizeof(string),"You have bought a %s First-Aid Kit and used it for $%d.",Health3,Health3*100);
SendClientMessage(playerid, COLOR_NOTIFY,string);
DisplayPlayerDialog(playerid, DIALOG_SHOP);
}
here is the code, can you setup the code for me please?
thank you
Re: Cost cash according to lost health -
ISmokezU - 06.06.2018
PHP код:
case 0:
{
new x, Float:Health, string[128];
GetPlayerHealth(playerid, Health);
x = Health - 100;
if(GetPlayerMoney(playerid) < x) return SendScreenMessage(playerid, LOCALE_MESSAGE_CANNOTAFFORD);
TakePlayerCash(playerid, x);
SetPlayerHealth(playerid, Health + x);
format(string, sizeof string, "You have bought a %s First-Aid Kit and used it for $%d.", x, x);// %s is for strings, x is an integer %i instead
SendClientMessage(playerid, COLOR_NOTIFY,string);
DisplayPlayerDialog(playerid, DIALOG_SHOP);
}