SA-MP Forums Archive
Respawn Idea - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Respawn Idea (/showthread.php?tid=141774)



Respawn Idea - Tony1337 - 15.04.2010

Hello Again, I was wondering if anyone knows how to make it so when the player dies they spawn exactly back were they died. I'm guessing this is quiet simple but it would be awsome if i had a little help. Thanks again Guys!


Re: Respawn Idea - Calgon - 15.04.2010

I think, you can use GetPlayerPos() in the OnPlayerDeath callback, once you've done that, log if they've died in a variable/float (for example) and then set their position:

pawn Код:
new Float: PlayerPosX[ MAX_PLAYERS ], Float: PlayerPosY[ MAX_PLAYERS ], Float: PlayerPosZ[ MAX_PLAYERS ];

public OnPlayerDeath( playerid, killerid, reason )
{
    GetPlayerPos( playerid, PlayerPosX[ playerid ], PlayerPosY[ playerid ], PlayerPosZ[ playerid ] );
    return 1;
}

public OnPlayerSpawn( playerid )
{
    SetPlayerPos( playerid, PlayerPosX[ playerid ], PlayerPosY[ playerid ], PlayerPosZ[ playerid ] );
    return 1;
}
This may not work.


Re: Respawn Idea - Correlli - 15.04.2010

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
  new
      Float:pos[3];
  GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
  SetPVarFloat(playerid, "X_pos", pos[0]);
  SetPVarFloat(playerid, "Y_pos", pos[1]);
  SetPVarFloat(playerid, "Z_pos", pos[2]);
  return true;
}

public OnPlayerSpawn(playerid)
{
  SetPlayerPos(playerid, GetPVarFloat(playerid, "X_pos"), GetPVarFloat(playerid, "Y_pos"), GetPVarFloat(playerid, "Z_pos"));
  return true;
}



Re: Respawn Idea - Jay_ - 15.04.2010

Personally I would use OnPlayerStateChange for this. That way it can be handled within one callback. Although I'm not certain if OnPlayerStateChange would get called before OnPlayerSpawn. Spawn positions from AddPlayerClass function calls are stored client side.


Re: Respawn Idea - Simon - 15.04.2010

Some different ways you could tackle this. Depending on your gamemode setup you could possibly also use SetSpawnInfo and then you'd just have to use the OnPlayerDeath callback. Take into account that this does not account for dying inside an interior, so will not be the best solution if players can die inside.

pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
  new Float:x, Float:y, Float:z, Float:a;

  GetPlayerPos(playerid, x, y, z);
  GetPlayerFacingAngle(playerid, a);

  SetSpawnInfo(GetPlayerSkin(playerid), GetPlayerTeam(playerid), x, y, z, -1, -1, -1, -1, -1, -1);

  return 1;
}



Re: Respawn Idea - Tony1337 - 15.04.2010

Awsome, Thank you alot!!