SA-MP Forums Archive
Detecting if a player died... - 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: Detecting if a player died... (/showthread.php?tid=550615)



Detecting if a player died... - Eyce - 13.12.2014

Hey everyone,

I'm doing a role-play game mode and I currently have a death and hospital system. If the player dies (the first time), they spawn right where they died without being able to move. If the player gets killed again, they are sent to the hospital. What's weird about this, is; if the player gets killed while being inside a vehicle, they go straight to the hospital. Is there a way to detect if a player dies while being inside a vehicle?

Thanks!


Re: Detecting if a player died... - FullCircle - 13.12.2014

Use GetPlayerState in OnPlayerDeath


Re: Detecting if a player died... - Eyce - 13.12.2014

Thanks for the tip. Though it still remains the same, the player goes straight to the hospital. I noticed that this only happens if the player is the driver of the vehicle. It works fine for passengers. Anymore thoughts?


Re: Detecting if a player died... - Abagail - 13.12.2014

pawn Code:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
       new vehicleid = GetPlayerVehicleID(playerid);
       new Float: pos[3];
       GetVehiclePos(vehicleid, pos[0], pos[1], pos[2]);
       SetPlayerPos(playerid, pos[0], pos[1]+1.75, pos[2]);
       RemovePlayerFromVehicle(playerid);
       return 1;
}



Re: Detecting if a player died... - Eyce - 13.12.2014

I had the same idea. But I'm using
pawn Code:
OnPlayerSpawn
This is what I actually have under OnPlayerDeath:
pawn Code:
if(IsPlayerInAnyVehicle(playerid))
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
                    {
                        new veh = GetPlayerVehicleID(playerid);
                        new Float:vdPos[4];
                        GetVehiclePos(veh, vdPos[0], vdPos[1], vdPos[2]);
                        GetVehicleZAngle(veh, vdPos[3]);

                        RemovePlayerFromVehicle(playerid);
                        SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], vdPos[0], vdPos[1], vdPos[2], vdPos[3], 0, 0, 0, 0, 0, 0);
                    }
                }



Re: Detecting if a player died... - FullCircle - 13.12.2014

You want to send the player to the hospital, but no the car, no?
Sorry for my bad english...


Re: Detecting if a player died... - Eyce - 13.12.2014

Quote:
Originally Posted by FullCircle
View Post
You want to send the player to the hospital, but no the car, no?
Sorry for my bad english...
It's okay. Here's what I mean, if the player dies while being the driver of the vehicle - he stays in his position but not sent to the hospital.


Re: Detecting if a player died... - FullCircle - 13.12.2014

Quote:
Originally Posted by Eyce
View Post
It's okay. Here's what I mean, if the player dies while being the driver of the vehicle - he stays in his position but not sent to the hospital.
You tried to remove player from the vehicle before teleport?
You freeze the player when the player is teleported?