Float doesn't work for more than 250
#1

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;
}
Reply
#2

Check for a max health in your script. Most gamemodes have that, if you use an edit then that might be the problem.
Reply
#3

This is a gamemode I started from scratch, I have never defined maximum health.
Reply
#4

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:
pawn Код:
Health: 144.000000
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;
}
Reply
#5

Kinda cheers me up that it has nothing to do with my scripting.
But I'd still like to fix it.
Reply
#6

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.
Reply
#7

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.
Reply
#8

Then it's GetPlayerHealth's problem.
Reply
#9

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!
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)