Spawn in the same area were you died?
#1

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?
Reply
#2

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

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

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

Wery handy tool.
Reply
#5

Nice, thanks
Reply
#6

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]
Reply
#7

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
Reply
#8

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)