new warplane[MAX_PLAYERS]; forward AutoRepair(playerid);
public OnPlayerConnect(playerid) SetTimerEx("AutoRepair",100,true,"d",playerid); warplane[playerid] = 0;
public OnPlayerEnterVehicle(playerid) { new vehid; vehid = GetPlayerVehicleID(playerid); switch(vehid) { case 425: {warplane[playerid] = 1;} case 520: {warplane[playerid] = 1;} case 447: {warplane[playerid] = 1;} case 476: {warplane[playerid] = 1;} default:{warplane[playerid] = 0;} } return 0; } //-------------------------------------------------------- public AutoRepair(playerid) { if (IsPlayerInAnyVehicle(playerid)) { if(warplane[playerid] == 0) { new Float:health; new vehicleid = GetPlayerVehicleID(playerid); GetVehicleHealth(vehicleid, health); if (health <= 300) { SetVehicleHealth(vehicleid,1000); GameTextForPlayer(playerid,"~g~Car Auto-Repaired!",5000,5); PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0); } } } }
Originally Posted by Weirdosport
(plus you can make sure the player is the driver rather than the passenger)
|
new AutoRepairTimer[MAX_PLAYERS] = {-1, ...};
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
switch(GetVehicleModel(GetPlayerVehicleID(playerid)))
{
case 425, 447, 476, 520: {} //do nothing
default:
{
if(AutoRepairTimer[playerid] != -1) KillTimer(AutoRepairTimer[playerid]);
AutoRepairTimer[playerid] = SetTimerEx("AutoRepair", 1000, true, "d", playerid);
}
}
}
forward AutoRepair(playerid);
public AutoRepair(playerid)
{
if(IsPlayerInAnyVehicle(playerid))
{
new
Float:health;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, health);
if(health <= 300.0)
{
SetVehicleHealth(vehicleid, 1000.0);
GameTextForPlayer(playerid, "~g~Car Auto-Repaired!", 5000, 5);
PlayerPlaySound(playerid, 1133, 0.0, 0.0, 0.0);
}
}
else KillTimer(AutoRepairTimer[playerid]), //kills the timer if the exist the vehicle or disconnects!
AutoRepairTimer[playerid] = -1;
}
Originally Posted by Weirdosport
OnPlayerEnterVehicle calls the second the player presses f to get in the vehicle, whereas OnPlayerStateChange changes to PLAYER_STATE_DRIVER only when they're in the car and ready to drive away.
Wiki - OnPlayerEnterVehicle: "This callback is called when a player starts to enter a vehicle." |
Originally Posted by Weirdosport
Using OnPlayerEnterVehicle you would then have to check that the seat was the correct one, whereas with OnPlayerStateChange you can just check to see if they've become a driver.. There's very little in it either way..
|