Vehicle Autofix
#1

Hey. I got a little problem. I added vehicle autofix for my server, and it works only for ID 0. Could anyone solve this? Thanks.

OnGameModeInIt:

Код:
SetTimer("VehicleHealth", 3000, true);
Under the script:

Код:
forward VehicleHealth (vehicleid);
public VehicleHealth (vehicleid)
{
	SetVehicleHealth(GetPlayerVehicleID(vehicleid),1000);
	return 1;
}
Reply
#2

pawn Код:
new v = GetPlayerVehicleID(playerid);
SetTimerEx("VehicleHealth", 3000, true, "i", v);
:P

hope it helps
Reply
#3

I see it's wrong for now. Playerid doesn't work in OnGameModeInIt

EDIT: Or I should put it in OnPlayerConnect?
Reply
#4

Here is a better way:
GameModeInit:
pawn Код:
SetTimer( "VehicleHealth", 3000, true );
pawn Код:
forward VehicleHealth( );
public VehicleHealth( )
{
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( IsPlayerConnected( i ) )
        {
            if( IsPlayerInAnyVehicle( i ) )
            {
                new vehicleid = GetPlayerVehicleID( i );
                RepairVehicle( vehicleid );
            }
        }
    }
    return 1;
}
About SetTimerEx, it's crazy because every one will run that timer.

And OnPlayerConnect will be the same, because SetTimer sets a GLOBAL timer, and SetTimerEx sets a timer for only one playerid. Use that code, it's gonna loop through all players and REPAIR the vehicle, not just set the HP to 1000.
Reply
#5

Shouldnt
pawn Код:
for( new i = 0; i < MAX_PLAYERS; i++ )
be
pawn Код:
for( new i = 0; i < MAX_VEHICLES; i++ )
Reply
#6

No, it should loop through all PLAYERS and get their vehicle IDs. Then repair it.
Also, edited, made a mistake.
Reply
#7

No, its looping through all the players and getting their vehicle ID and then repairs their vehicle ID.

EDIT
Damn i was like 10 seconds late
Reply
#8

Yea, and I edited, I forgot to put if( IsPlayerInAnyVehicle( i ) )
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)