Float doesn't work for more than 250 -
Tomer!.$ - 07.09.2013
Well, I have a /health command, that's supposed to set the player's health to the amount I choose.
It somewhat works, but if I set someone's health to somewhere above 250 (not sure if 250 is the EXACT number, but I've noticed that it's something about it) it just doesn't set the health properly.
So if I set someone's health to 400, it won't work properly, it will just set his health to random amount (usually around 100)
pawn Код:
CMD:health(playerid, params[])
{
if(gPlayerInfo[playerid][pAdmin] < 1) return SendClientMessage(playerid, COLOR_RED, "[Error] You are not authorised to use this command!");
new Float:health,
name[MAX_PLAYER_NAME+1],
idname[MAX_PLAYER_NAME+1],
id,
string[128];
if(sscanf(params, "uf", id, health)) return SendClientMessage(playerid, COLOR_WHITE, "[Usage] /health [ID] [Amount]");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "[Error] Invalid Player ID.");
GetPlayerName(playerid, name, sizeof(name));
GetPlayerName(id, idname, sizeof(idname));
for(new slots = GetMaxPlayers(), i; i < slots; i++)
{
if(!IsPlayerConnected(i)) continue;
if(gPlayerInfo[i][pAdmin] >= 1)
{
format(string, sizeof(string), "[AdmCmd] %s has set %s's health to %f", name, idname, health);
SendClientMessage(i, COLOR_RED, string);
}
}
format(string, sizeof(string), "[Info] Your health is now set to %f", health);
SendClientMessage(id, COLOR_WHITE, string);
SetPlayerHealth(id, health);
return 1;
}
Re: Float doesn't work for more than 250 -
damian123 - 07.09.2013
Check for a max health in your script. Most gamemodes have that, if you use an edit then that might be the problem.
Re: Float doesn't work for more than 250 -
Tomer!.$ - 07.09.2013
This is a gamemode I started from scratch, I have never defined maximum health.
Re: Float doesn't work for more than 250 -
Konstantinos - 07.09.2013
It seems that it's either because of sscanf or SetPlayerHealth function.
I just did a test in an empty gamemode and the result is:
When I set the health to 400 before.
pawn Код:
CMD:health( playerid, params[ ] )
{
new
Float: health_
;
if( !sscanf( params, "f", health_ ) ) SetPlayerHealth( playerid, health_ );
return 1;
}
CMD:gethealth( playerid, params[ ] )
{
new
Float: health_
;
GetPlayerHealth( playerid, health_ );
printf( "Health: %f", health_ );
return 1;
}
Re: Float doesn't work for more than 250 -
Tomer!.$ - 07.09.2013
Kinda cheers me up that it has nothing to do with my scripting.
But I'd still like to fix it.
Re: Float doesn't work for more than 250 -
Konstantinos - 07.09.2013
I just did few more tests and the conclusion is that SetPlayerHealth is not working like it should. I set the health to 400 in a command without sscanf in it and the health is still 144.0
Unless GetPlayerHealth returns wrong amount of health and the health is set fine.
Re: Float doesn't work for more than 250 -
Tomer!.$ - 07.09.2013
It's kinda weird though, I've seen many servers with godmode (where they set the health to 9999) and I also remember doing so in the far past.
Re: Float doesn't work for more than 250 -
Dragonsaurus - 07.09.2013
Then it's GetPlayerHealth's problem.
Re: Float doesn't work for more than 250 -
Konstantinos - 07.09.2013
I know, I set the health to Infinity and it works like it should. I guess the function
GetPlayerHealth returns wrong amount.
Don't worry, it's not something related to your mode!
Re: Float doesn't work for more than 250 -
Tomer!.$ - 07.09.2013
It is not, because not only that I have seen the value of the health after being set, through GetPlayerHealth.
I have also tested it by asking people to shoot me, and counting the number of shots taken, etc..
It either has something to do with SetPlayerHealth, or it has something to do with the health value in general.