Vehicle Autofix - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Vehicle Autofix (
/showthread.php?tid=227813)
Vehicle Autofix -
Libra_PL - 18.02.2011
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;
}
Re: Vehicle Autofix -
Sascha - 18.02.2011
pawn Код:
new v = GetPlayerVehicleID(playerid);
SetTimerEx("VehicleHealth", 3000, true, "i", v);
:P
hope it helps
Re: Vehicle Autofix -
Libra_PL - 18.02.2011
I see it's wrong for now. Playerid doesn't work in OnGameModeInIt
EDIT: Or I should put it in OnPlayerConnect?
Re: Vehicle Autofix -
Mean - 18.02.2011
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.
Re: Vehicle Autofix - Unknown123 - 18.02.2011
Shouldnt
pawn Код:
for( new i = 0; i < MAX_PLAYERS; i++ )
be
pawn Код:
for( new i = 0; i < MAX_VEHICLES; i++ )
Re: Vehicle Autofix -
Mean - 18.02.2011
No, it should loop through all PLAYERS and get their vehicle IDs. Then repair it.
Also, edited, made a mistake.
Re: Vehicle Autofix -
[WF]Demon - 18.02.2011
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
Re: Vehicle Autofix -
Mean - 18.02.2011
Yea, and I edited, I forgot to put if( IsPlayerInAnyVehicle( i ) )