SA-MP Forums Archive
Die outside the vehicle - 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)
+--- Thread: Die outside the vehicle (/showthread.php?tid=380780)



Die outside the vehicle - kbalor - 27.09.2012

Is that possible not to die inside a vehicle after it explodes? I want to eject outside the vehicle before I die.


Re: Die outside the vehicle - Mauzen - 27.09.2012

Probably, but not well. Time between vehicle starting to burn, and explosion should be fix for all vehicles afaik (except its exploding instantly because of certain other explosions). You could check the vehicle health for dropping below 250 in OnPlayerUpdate, and then start a timer that ejects the player some 100ms before the vehicle explodes. But you would also need to teleport him away a bit, as he will still die standing next to the explosion.


Re: Die outside the vehicle - clarencecuzz - 27.09.2012

On a timer:
pawn Код:
public OnGameModeInit() //Or OnFilterScriptInit()
{
    SetTimer("CarTimer", 1000, true);
    return 1;
}

forward CarTimer();
public CarTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInAnyVehicle(i))
            {            
                new vehicleid = GetPlayerVehicleID(i);
                new Float:health;
                GetVehicleHealth(vehicleid, health);
                if(health <= 250)
                {
                    RemovePlayerFromVehicle(i);
                }
            }
        }
    }
    return 1;
}



Re: Die outside the vehicle - kbalor - 27.09.2012

Quote:
Originally Posted by clarencecuzz
Посмотреть сообщение
On a timer:
pawn Код:
public OnGameModeInit() //Or OnFilterScriptInit()
{
    SetTimer("CarTimer", 1000, true);
    return 1;
}

forward CarTimer();
public CarTimer()
{
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInAnyVehicle(i))
            {            
                new vehicleid = GetPlayerVehicleID(i);
                new Float:health;
                GetVehicleHealth(vehicleid, health);
                if(health <= 250)
                {
                    RemovePlayerFromVehicle(i);
                }
            }
        }
    }
    return 1;
}
I think it works but in a different thing. What I mean is everytime time i'm in another world like VirtualWorld 1 and so on EXCEPT VirtualWorld 0. Everytime I died inside a vehicle it teleports me randomly sometimes in CJ near the house. Sometimes in ocean. Sometimes I fall from nowhere XD but when i'm onfoot I spawn in a place where I set the spawn point.

And the weird thing is that when i'm using the Lan server the problem is now gone after I died in vehicle it spawn me in the right place where I actually want to spawn.


Re: Die outside the vehicle - OnlyOne - 27.09.2012

i don't really recommend using a loop. this is the best way to do it.

pawn Код:
new timer[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
    timer[playerid] = SetTimerEx("vehicleup",1000,true,"i",playerid);
    return 1;
}
public OnPlayerDisconnect(playerid)
{
    KillTimer(timer[playerid]);
}
forward vehicleup(playerid);
public vehicleup(playerid)
{
    if(!IsPlayerInAnyVehicle(playerid)) return false; // is not in vehicle.
    static Float:health;
    GetVehicleHealth(GetPlayerVehicleID(playerid), health); // get vehicle health.
    if(health > 250) return false; // if it's bigger return 0.
    RemovePlayerFromVehicle(playerid); // he's inside a vehicle.
    return true;
}
By the way, i recommend you stop using/making useless variables.