SA-MP Forums Archive
Spawn in the same area were you 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: Spawn in the same area were you died? (/showthread.php?tid=579825)



Spawn in the same area were you died? - Cheesus - 30.06.2015

Hi i would like to create something,

When i die i would like to respawn in the same area were i died.

Like when i die in downtown, i respawn in downtown.

What should i use?


Re: Spawn in the same area were you died? - Roko_foko - 30.06.2015

You should save coordinates, virtual world and interior in OnPlayerDeath() callback
https://sampwiki.blast.hk/wiki/OnPlayerDeath

you can get info using: GetPlayerPos, GetPlayerInterior, GetPlayerVirtualWorld
https://sampwiki.blast.hk/wiki/Function:GetPlayerPos
https://sampwiki.blast.hk/wiki/GetPlayerInterior
https://sampwiki.blast.hk/wiki/GetPlayerVirtualWorld

store to into a global player variable
new Float: playerDeathCoordinates[MAX_PLAYERS][3];
new playerDeathInterior[MAX_PLAYERS];
new playerDeathVirtualWorld[MAX_PLAYERS];

and once you did that set player position, virtual world, interior in OnPlayerSpawn() callback
another option is you can set SetSpawnInfo in OnPlayerDeath() callback
https://sampwiki.blast.hk/wiki/SetSpawnInfo

if you try with the second option, test if it works in interiors, I don't remember is playerInterior (or playerVirtualWorld) set to default on death.


Re: Spawn in the same area were you died? - Cheesus - 30.06.2015

but how do i check in what area the player is..


Re: Spawn in the same area were you died? - Hessu - 30.06.2015

Use ZONES INCLUDE : https://sampforum.blast.hk/showthread.php?tid=27598

Wery handy tool.


Re: Spawn in the same area were you died? - Cheesus - 30.06.2015

Nice, thanks


Re: Spawn in the same area were you died? - Roko_foko - 30.06.2015

Quote:
Originally Posted by Cheesus
Посмотреть сообщение
but how do i check in what area the player is..
Yea, you can try what person above said, but I don't know where you want to spawn person? at hospital, some point you specified before?

In my first response, I thouhgt you want to spawn at exact location where person died.
In case you have points where you would like to spawn. And on player's death get the closest one:
Код:
new Float:distance; 
new respawnID;

distance = GetPlayerDistanceFromPoint(playerid, respawnPoints[0][0], respawnPoints[0][1], respawnPoints[0][2]);
respawnID = 0;
for(new i = 1; i < MAX_RESPAWN_POINTS; ++i) 
{
    new tempDistance = GetPlayerDistanceFromPoint(playerid, respawnPoints[i][0], respawnPoints[i][1], respawnPoints[i][2]);
    if(tempDistance < distance) 
    {
        distance = tempDistance;
        respawnID = i;
    }
}
// and after this loop your coordinates you need are stored inside respawnPoints[respawnID]



Re: Spawn in the same area were you died? - Cheesus - 30.06.2015

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
Yea, you can try what person above said, but I don't know where you want to spawn person? at hospital, some point you specified before?

In my first response, I thouhgt you want to spawn at exact location where person died.
In case you have points where you would like to spawn. And on player's death get the closest one:
Код:
new Float:distance; 
new respawnID;

distance = GetPlayerDistanceFromPoint(playerid, respawnPoints[0][0], respawnPoints[0][1], respawnPoints[0][2]);
respawnID = 0;
for(new i = 1; i < MAX_RESPAWN_POINTS; ++i) 
{
    new tempDistance = GetPlayerDistanceFromPoint(playerid, respawnPoints[i][0], respawnPoints[i][1], respawnPoints[i][2]);
    if(tempDistance < distance) 
    {
        distance = tempDistance;
        respawnID = i;
    }
}
// and after this loop your coordinates you need are stored inside respawnPoints[respawnID]
This is were i was looking for


Re: Spawn in the same area were you died? - Roko_foko - 30.06.2015

Quote:
Originally Posted by Cheesus
Посмотреть сообщение
This is were i was looking for
Glad to be of help. If you need anything else, let me know