OnPlayerUpdate
#1

Would looping through all players checking if they are in a car and getting their car id, then ejecting them from the car if the health is lower then 450 cause lag? would it be better to set a 1 s timer?
Reply
#2

Depends on how many people are on the server.
OnPlayerUpdate gets called 30 times a second, so you do the math.
I would recommend a 1 second timer though.
Reply
#3

Alright thanks.
Reply
#4

Try this:

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

forward PlayersCheck();

public PlayersCheck()
{
    for(new i = 0; i <= GetMaxPlayers(); i++)
    {
        if(IsPlayerConnected(i))
        {
            if(isPlayerInAnyVehicle(i))
            {
                new vid, FLoat:vhealth;
                vid = GetPlayerVehicleID(i);
                GetVehicleHealth(vid, vhealth);
                if(vhealth < 450)
                {
                    RemovePlayerFromVehicle(i);
                }
            }
        }
    }
}
Reply
#5

Can't believe I didn't think of this, lol. Why don't you just use OnPlayerEnterVehicle and use your code there. No loop is necessary.

EDIT:

Nevermind. Antonio is right.
Reply
#6

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Can't believe I didn't think of this, lol. Why don't you just use OnPlayerStateChange and use
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
    // You would then add the vehicle health/id code here.
What about if the player's in a car with 1000 health and only afterwards, he makes an accident and the vehicles health is lowering under 450 ? That wouldn't work with your solution.

So, a timer is still the best solution. Use SpiritEvils code.
Reply
#7

-DELETE-

SORRY GUYS BUT I WROTE ON WRONG THREAD!!!! DAMN!
Reply
#8

Much more optimized version without all the redundant checks:
PHP код:
public PlayersCheck()
{
    for(new 
0GetPlayerPoolSize(), Float:vhealth<= ji++)
    {
        if(
GetVehicleHealth(GetPlayerVehicleID(i), vhealth))
        {
            if(
vhealth 450)
            {
                
RemovePlayerFromVehicle(i);
            }
        }
    }

Edit: crap, didn't see the dates. Was looking at date of last post. Oh well.
Reply
#9

Quote:
Originally Posted by Vince
Посмотреть сообщение
Much more optimized version without all the redundant checks:
PHP код:
public PlayersCheck()
{
    for(new 
0GetPlayerPoolSize(), Float:vhealth<= ji++)
    {
        if(
GetVehicleHealth(GetPlayerVehicleID(i), vhealth))
        {
            if(
vhealth 450)
            {
                
RemovePlayerFromVehicle(i);
            }
        }
    }

Edit: crap, didn't see the dates. Was looking at date of last post. Oh well.
Same happened to me hahahahah

NEXT PERSON THAT IS READING THIS! DO NOT WRITE ANYTHING ON THIS POST!!!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)