Respawn Idea
#1

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

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

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;
}
Reply
#4

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

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;
}
Reply
#6

Awsome, Thank you alot!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)