Spawns - 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: Spawns (
/showthread.php?tid=590057)
Spawns -
Cheesus - 25.09.2015
Hello,
im looking for a way to spawn a player in the region he died.
Like: A player spawns in LS, he drives to LV and dies. Then he get random spawned at LV.
Like finding the closest spawn point.
+rep
Re: Spawns -
Crystallize - 25.09.2015
Код:
new Float:X,Float:Y,Float:Z;
public OnPlayerDeath(playerid , killerid , reason)
{
GetPlayerPos(playerid,X,Y,Z);
return 1;
}
public OnPlayerSpawn(playerid)
{
SetPlayerPos(playerid,X,Y,Z);
return 1;
}
Re: Spawns -
Cheesus - 25.09.2015
Thats for spawning at the same point after death.
i created a code using GetPlayerDistanceFromPoint
Код:
enum spawn_
{
Float:s_X,
Float:s_Y,
Float:s_Z
};
new Spawns[][spawn_] = // List of spawns
{
{0.0, 0.0, 0.0},
{123.0, 456.0, 789.0},
{500.0, 500.0, 500.0}
};
stock ClosestSpawnPoint(playerid) // Get closest spawn
{
new SpawnPointid, Float:closest = GetPlayerDistanceFromPoint(playerid, Spawns[0][s_X], Spawns[0][s_Y], Spawns[0][s_Z]);
for(new i=1; i<sizeof(Spawns); i++)
{
if(GetPlayerDistanceFromPoint(playerid, Spawns[i][s_X], Spawns[i][s_Y], Spawns[i][s_Z]) < closest)
{
closest = GetPlayerDistanceFromPoint(playerid, Spawns[i][s_X], Spawns[i][s_Y], Spawns[i][s_Z]);
SpawnPointid = i;
}
}
return SpawnPointid;
}
public OnPlayerDeath(playerid, killerid, reason)
{
SetPVarInt(playerid, "Dead", 1);
SetPVarInt(playerid, "SpawnPoint", ClosestSpawnPoint(playerid));
}
public OnPlayerSpawn(playerid)
{
if(GetPVarInt(playerid, "Dead"))
{
new sp = GetPVarInt(playerid, "SpawnPoint");
SetPlayerInterior(playerid, 0);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerPos(playerid, Spawns[sp][s_X], Spawns[sp][s_Y], Spawns[sp][s_Z]);
SetPVarInt(playerid, "Dead", 0);
}
}
I posted this so it might be usefull for other players looking for this