29.08.2012, 13:57
I am making a /heal command and it should be pretty simple but for some reason all of the values are so fucked up.
Here's the code:
And, for reference, what the values are actually used in (this is stored in a one-second timer that repeats)
No idea why it isn't working. I think it is something to do with the values that are being stored & I don't know why they would be wrong, they just seem to be crazily high numbers. Also... My timer doesn't work, the GameText that counts down the seconds remaining. It worked before I made a few adjustments. Any help on that too?
Here's the code:
pawn Код:
CMD:heal(playerid, params[])
{
new Float:Health, Float:tbhealedhealth, Float:healprice, Float:healtime, string[128];
GetPlayerHealth(playerid, Float:Health); //Setting the value for health
tbhealedhealth = 100-Health; //Health to be healed
//healprice = tbhealedhealth*10;
//healtime = tbhealedhealth*3000;
/*format(string, sizeof(string), "health: %.4f | tbhealedhealth: %.4f | healprice: %.4f | healtime: %.4f", Health, tbhealedhealth, healprice, healtime);
SendClientMessage(playerid, -1, string);*/
if(IsPlayerInRangeOfPoint(playerid, 5, HealPos1X, HealPos1Y, HealPos1Z))
{
if(Health == 100)
{
SendClientMessage(playerid, GREY, "You already have full health.");
}
else if(Health >= 41)
{
if(Health <= 99)
{
Player[playerid][HealTime] = tbhealedhealth; //Stores the to be healed health as a time in seconds to a player stat
Player[playerid][HealPrice] = tbhealedhealth*3; //Triples the to be healed health, this is the amount they must pay then stores it to a player stat
Player[playerid][BeingHealed] = 1; //Being healed at hospital 1 (Will put in hospital 2 if this can be fixed)
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %.0f seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19); // Everything below is just setting cam pos etc. whilst they are in hospital
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
}
else if(Health <= 40) // Same as above, only difference is the price is doubled here
{
if(Health >= 1)
{
Player[playerid][HealTime] = tbhealedhealth;
Player[playerid][HealPrice] = tbhealedhealth*6;
Player[playerid][BeingHealed] = 1;
format(string, sizeof(string), "You are now undergoing hospital treatment. You will be released in %.0f seconds.", Player[playerid][HealTime]);
SendClientMessage(playerid, -1, string);
SetPlayerPos(playerid, 1161.2238, -1321.6235, 19);
SetPlayerVirtualWorld(playerid, playerid);
TogglePlayerControllable(playerid, false);
SetPlayerCameraPos(playerid, 1217.4056, -1321.4524, 31.1270);
SetPlayerCameraLookAt(playerid, 1173.2889, -1322.7111, 19.4345);
}
}
}
return 1;
}
pawn Код:
if(Player[i][BeingHealed] != 0)
{
new string[128], Float: Health;
GetPlayerHealth(i, Health);
if(Health == 100)
{
Player[i][Money] -= Player[i][HealPrice];
format(string, sizeof(string), "You have been released from hospital. Your were billed $%.0f.", Player[i][HealPrice]);
SendClientMessage(i, -1, string);
Player[i][BeingHealed] = 0;
Player[i][HealPrice] = 0;
Player[i][HealTime] = 0;
SetCameraBehindPlayer(i);
SetPlayerVirtualWorld(i, 0);
SetPlayerInterior(i, 0);
TogglePlayerControllable(i, true);
SetPlayerPos(i, 1177.6462, -1323.7413, 14.0810);
}
else
{
SetPlayerHealth(i, Health+1);
format(string, sizeof(string), "~y~Time remaining:~n~~n~~r~%.0f seconds", Player[i][HealTime]);
Player[i][HealTime] -= -1;
GameTextForPlayer(i, string, 1000, 3);
}
}