SA-MP Forums Archive
Player can have more than 100 hp.. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Player can have more than 100 hp.. (/showthread.php?tid=438727)



Player can have more than 100 hp.. - kubeba59 - 21.05.2013

How can I disable this ?


Re: Player can have more than 100 hp.. - Scenario - 21.05.2013

pawn Код:
public OnPlayerUpdate(playerid)
{
    new
        Float:fHealth;
   
    GetPlayerHealth(playerid, fHealth);
    if(fHealth > 100.0) SetPlayerHealth(playerid, 100.0);
    return 1;
}



Re: Player can have more than 100 hp.. - Pottus - 21.05.2013

That would probably be better on a timer RC.


Re: Player can have more than 100 hp.. - Scenario - 21.05.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
That would probably be better on a timer RC.
I didn't put it in a timer because we wouldn't want anyone on the server to have over 100 HP and possibly get a tiny advantage over everyone else because the timer didn't call for them yet or something.

But, it would be simple to convert to a timer..

pawn Код:
public OnGameModeInit()
{
    SetTimer("HealthCheck", true, 1000);
    return 1;
}

forward HealthCheck();
public HealthCheck()
{
    foreach(new i : Player)
    {
        new
            Float:fHealth;
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}



Re: Player can have more than 100 hp.. - Pottus - 21.05.2013

You know what would be even better than a timer would be to check it in OnPlayerTakeDamage() then =)


Re: Player can have more than 100 hp.. - Scenario - 21.05.2013

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
You know what would be even better than a timer would be to check it in OnPlayerTakeDamage() then =)
I'm not writing that code.. lol


Re: Player can have more than 100 hp.. - kubeba59 - 21.05.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
I didn't put it in a timer because we wouldn't want anyone on the server to have over 100 HP and possibly get a tiny advantage over everyone else because the timer didn't call for them yet or something.

But, it would be simple to convert to a timer..

pawn Код:
public OnGameModeInit()
{
    SetTimer("HealthCheck", true, 1000);
    return 1;
}

forward HealthCheck();
public HealthCheck()
{
    foreach(new i : Player)
    {
        new
            Float:fHealth;
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}
Its not working bro ..


Re: Player can have more than 100 hp.. - IstuntmanI - 21.05.2013

Change
pawn Код:
forward HealthCheck();
public HealthCheck()
{
    foreach(new i : Player)
    {
        new
            Float:fHealth;
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}
to
pawn Код:
forward HealthCheck();
public HealthCheck()
{
    for( new i = 0; i < MAX_PLAYERS; i ++ ) if( IsPlayerConnected( i ) )
    {
        new
            Float:fHealth;
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}
You'd better include foreach.


Re: Player can have more than 100 hp.. - Joe Staff - 21.05.2013

Don't place variable calls inside of loops, it's very redundant (like creating a new variable for every connected player, when you could just create one variable and then use it for each.)

pawn Код:
forward HealthCheck();
public HealthCheck()
{
    new Float:fHealth;
    for( new i = 0; i < MAX_PLAYERS; i ++ ) if( IsPlayerConnected( i ) )
    {
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}

There's no reason why that code shouldn't be working for you, OP.


Re: Player can have more than 100 hp.. - kubeba59 - 22.05.2013

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
Don't place variable calls inside of loops, it's very redundant (like creating a new variable for every connected player, when you could just create one variable and then use it for each.)

pawn Код:
forward HealthCheck();
public HealthCheck()
{
    new Float:fHealth;
    for( new i = 0; i < MAX_PLAYERS; i ++ ) if( IsPlayerConnected( i ) )
    {
       
        GetPlayerHealth(i, fHealth);
        if(fHealth > 100.0) SetPlayerHealth(i, 100.0);
    }
    return 1;
}

There's no reason why that code shouldn't be working for you, OP.
Not working bro,and everything is set ..