Player can have more than 100 hp..
#1

How can I disable this ?
Reply
#2

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

That would probably be better on a timer RC.
Reply
#4

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

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

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

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

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

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)