simple tutorial how create random spawns as in sa-mp
1.We need coordinates
local playerid = thePlayer -- playerid look much more better for me
local SpawnPoints = 30
SpawnPointsX = {
-2625.2864,
-2623.2029,
-2625.8347,
-2677.5947,
-2677.5938,
-2687.0095,
-2727.9255,
-2725.1943,
-2723.1816,
-2789.8159,
-2791.6599,
-2791.6638,
-2688.9690,
-2621.7439,
-2623.1860,
-2319.5371,
-2098.2395,
-2068.0857,
-1717.8177,
-1850.6150,
-1799.9431,
-1998.1191,
-1988.6193,
-2208.0051,
-2281.2798,
-2281.4077,
-2211.7302,
-2175.2139,
-2100.2197,
-2116.7268
}
SpawnPointsY = {
-191.1071,
-146.2787,
-99.2910,
-105.7311,
-96.3309,
-102.4076,
-188.0582,
-184.5052,
-92.8682,
4.3873,
183.8500,
194.5688,
218.6564,
197.8280,
168.7803,
376.5272,
578.8318,
715.4632,
782.9799,
1017.6947,
1028.3041,
1204.3224,
1190.2186,
1117.3044,
1106.6957,
1089.3551,
1070.7418,
1056.3667,
974.9451,
900.9063,
925.3539
}
SpawnPointsZ = {
7.2031,
7.2031,
7.2031,
7.2031,
7.2031,
7.2010,
7.2031,
7.2031,
7.2031,
7.2031,
10.0511,
10.0547,
7.8594,
7.2031,
7.1953,
6.1593,
31.2476,
69.5625,
71.8906,
17.5859,
46.0987,
25.1250,
45.4453,
54.4729,
80.0078,
80.2635,
81.5866,
80.0078,
80.0000,
76.7109,
86.0791
}
When player connect to server:
function Spawn(playerid)
spawnPlayer ( playerid, 0.0,0.0,5.0)
fadeCamera ( playerid,true)
end
function OnPlayerConnect(playerid)
setTimer ( Spawn, 1500, 1, source)
end
addEventHandler ( "onPlayerJoin", getRootElement(), OnPlayerConnect )
and events death/spawn:
function OnPlayerSpawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension )
-- play a frontend sound for him
playSoundFrontEnd ( source, 16 )
rand = randInt ( 1, 30 )
setElementPosition ( source, SpawnPointsX[rand], SpawnPointsY[rand], SpawnPointsZ[rand] + 1)
end
-- add the player_Spawn function as a handler for onPlayerSpawn
addEventHandler ( "onPlayerSpawn", getRootElement(), OnPlayerSpawn )
function OnPlayerDeath ( ammo, attacker, weapon, bodypart )
setTimer ( Spawn, 1500, 1, source)
end
addEventHandler ( "onPlayerWasted", getRootElement(), OnPlayerDeath )
PS - Random spawns are around SFyou can change it
PS 2 - It works