Making exceptions for autorepair
#1

Code:
new warplane[MAX_PLAYERS];
forward AutoRepair(playerid);
Code:
public OnPlayerConnect(playerid)
SetTimerEx("AutoRepair",100,true,"d",playerid);
warplane[playerid] = 0;
Code:
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);
	}
	}
  }
}
The vehicles I don't want the autorepair to fix are the Hydra, Hunter, Seasparrow and RC plane. But it still repairs them and I don't know why
Reply
#2

GetPlayerVehicleID(playerid);

Replace with GetVehicleModel(GetPlayerVehicleID(playerid));

And maybe instead of using OnPlayerEnterVehicle use OnPlayerStateChange, I heard it was more reliable at detecting if a player is in a vehicle or not (plus you can make sure the player is the driver rather than the passenger)
Reply
#3

Quote:
Originally Posted by Weirdosport
(plus you can make sure the player is the driver rather than the passenger)
OnPlayerEnterVehicle dedects in which seats the player enters...

@topic
first of all, use [pawn][/pawn] tags

pawn Code:
new AutoRepairTimer[MAX_PLAYERS] = {-1, ...};
pawn Code:
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);
            }
        }
}
pawn Code:
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;
}
That code is better because the timer isnt the whole time active like in your code
Reply
#4

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

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

Quote:
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."
this post is kind of useless, noone asked that...

Quote:
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..
Exactly both need 1 if check and none would be better to check if he is the driver...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)