bzuco Posted January 4, 2008 Share Posted January 4, 2008 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 1 Link to comment
Franc[e]sco Posted January 4, 2008 Share Posted January 4, 2008 I tryed to improve your random spawn system and implement it in my gamemode but i dunno whats wrong... when i join the game i get fatal error, and when i go back to the server's window it says: [16:46:37] CONNECT: Franc[e]sco connected (IP: CENSORED)[16:46:49] JOIN: Franc[e]sco joined the game (IP: CENSORED) [16:46:49] QUIT: Franc[e]sco left the game [Quit] [16:46:49] ERROR: Invalid element specified. [16:46:51] WARNING: server.lua: Bad 'player' pointer @ 'spawnPlayer'(1) - Line: 4 [16:46:51] WARNING: server.lua: Bad 'player' pointer @ 'fadeCamera'(1) - Line: 5 [16:47:59] CLOSE: Server stopped! Here's the gamemode code: -- Simple DM - coded by Franc[e]sco --//--------------------------------------------------------------------------// function spawnThePlayer (thePlayer) spawnPlayer(thePlayer, 0.0,0.0,5.0) fadeCamera(thePlayer, true) end --//--------------------------------------------------------------------------// function onMapStartHandler ( startedMap ) local playersToSpawn = getElementsByType ("player") for k,player in ipairs ( playersToSpawn ) do spawnThePlayer( player ) end end addEventHandler ( "onGamemodeMapStart", getRootElement (), onMapStartHandler ) --//--------------------------------------------------------------------------// function onPlayerConnect (thePlayer) local playerName = getClientName(source) outputChatBox("Welcome, " .. playerName .. ", this server is actually running Simple Deathmatch by Franc[e]sco", source) setTimer(spawnThePlayer, 1500, 1, source) end addEventHandler("onPlayerJoin", getRootElement (), onPlayerConnect) --//--------------------------------------------------------------------------// function onPlayerDeath (ammo, attacker, weapon, bodypart) outputChatBox("You died! Please wait 10 seconds to respawn", source) setTimer(spawnThePlayer, 10000, 1, source) end addEventHandler("onPlayerWasted", getRootElement (), onPlayerDeath) --//--------------------------------------------------------------------------// function OnPlayerSpawn (posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension) playSoundFrontEnd(source, 16) local effectivespawns = spawnPoints-1 local rand = randInt(0, effectivespawns) setElementPosition(source, rSpawnPoints[rand].x, rSpawnPoints[rand].y, rSpawnPoints[rand].z + 1) setPlayerRotation(source, rSpawnPoints[rand].f) giveWeapon(source, rSpawnPoints[rand].fist, 1) giveWeapon(source, rSpawnPoints[rand].melee, 1) giveWeapon(source, rSpawnPoints[rand].handgun, 200) giveWeapon(source, rSpawnPoints[rand].shotgun, 20) giveWeapon(source, rSpawnPoints[rand].smgun, 5000) giveWeapon(source, rSpawnPoints[rand].mgun, 5000) giveWeapon(source, rSpawnPoints[rand].rifle, 15) giveWeapon(source, rSpawnPoints[rand].heavy, 5) giveWeapon(source, rSpawnPoints[rand].projectile, 5) giveWeapon(source, rSpawnPoints[rand].special1, 30) giveWeapon(source, rSpawnPoints[rand].gift, 1) giveWeapon(source, rSpawnPoints[rand].special2, 1) giveWeapon(source, rSpawnPoints[rand].detonator, 1) end addEventHandler ( "onPlayerSpawn", getRootElement(), OnPlayerSpawn ) --//--------------------------------------------------------------------------// and here's the map code (only a lua scrpt, no .map) function mapLoad(name) createObject(3983, 3404.731201, -1526.936523, 23.624731, 0.0000, 0.0000, 0.0000) createObject(3983, 3387.905518, -1527.186768, 32.624733, 0.0000, 90.2409, 0.0000) createObject(3983, 3420.326904, -1521.111694, 32.624733, 0.0000, 90.2409, 182.0965) createObject(3983, 3408.901611, -1503.010376, 32.624733, 0.0000, 91.1003, 272.3375) createObject(3983, 3408.926514, -1547.310669, 32.624733, 0.0000, 91.1003, 90.2409) createObject(3983, 3404.731201, -1526.936523, 51.374733, 0.0000, 180.4820, 0.0000) createObject(3983, 3404.731201, -1542.187012, 40.549725, 0.0000, 0.0000, 0.0000) createObject(3983, 3404.955322, -1541.737305, 36.499649, 0.0000, 180.4820, 0.0000) createObject(3399, 3411.878662, -1503.062012, 24.215816, 0.0000, 0.0000, 188.6717) createObject(3399, 3400.371826, -1504.812500, 28.765804, 0.0000, 0.0000, 188.6717) createObject(3399, 3400.294189, -1507.640747, 32.965858, 0.0000, 0.0000, 0.5587) createObject(969, 3391.658691, -1500.882324, 31.092058, 266.3214, 3.4377, 282.9689) createObject(3399, 3409.544189, -1507.640747, 36.240875, 0.0000, 0.0000, 0.5587) createObject(969, 3414.442871, -1507.829468, 38.517120, 266.3214, 0.0000, 270.0000) createObject(925, 3420.059814, -1540.482178, 22.689754, 0.0000, 0.0000, 0.0000) createObject(925, 3415.954346, -1537.199219, 22.663198, 0.0000, 0.0000, 0.0000) createObject(925, 3406.375977, -1536.315063, 22.663198, 0.0000, 0.0000, 0.0000) createObject(925, 3401.902100, -1534.704834, 22.705301, 0.0000, 0.0000, 0.0000) createObject(925, 3401.406494, -1525.278442, 22.742367, 0.0000, 0.0000, 0.0000) createObject(925, 3403.253418, -1523.866577, 22.720238, 0.0000, 0.0000, 0.0000) createObject(925, 3394.223145, -1514.075562, 22.904266, 0.0000, 0.0000, 0.0000) createObject(944, 3413.396973, -1526.512817, 22.486080, 0.0000, 0.0000, 33.7500) createObject(944, 3405.102539, -1517.788452, 22.535776, 0.0000, 0.0000, 0.0000) createObject(944, 3411.190430, -1512.399536, 22.486080, 0.0000, 0.0000, 22.5000) createObject(931, 3411.395264, -1548.199219, 22.677711, 0.0000, 0.0000, 90.0000) createObject(931, 3411.469238, -1543.873779, 22.663198, 0.0000, 0.0000, 90.0000) createObject(931, 3411.449707, -1545.996338, 22.665375, 0.0000, 0.0000, 90.0000) createObject(931, 3393.603271, -1548.425537, 22.683208, 0.0000, 0.0000, 90.0000) createObject(931, 3393.624268, -1543.861694, 22.694653, 0.0000, 0.0000, 90.0000) createObject(931, 3393.605713, -1546.098633, 22.693037, 0.0000, 0.0000, 90.0000) createObject(931, 3392.800293, -1526.011597, 22.864033, 0.0000, 0.0000, 90.0000) createObject(931, 3390.443359, -1531.249023, 22.881367, 0.0000, 0.0000, 90.0000) createObject(931, 3392.669922, -1527.212036, 22.869278, 0.0000, 0.0000, 90.0000) createObject(1685, 3396.818848, -1501.971680, 22.451813, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.824707, -1502.770630, 22.478695, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.857422, -1502.978760, 22.480766, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.781982, -1503.509644, 22.487837, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.928223, -1503.794189, 22.489529, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.919922, -1504.314209, 22.495720, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.972168, -1509.989990, 39.314728, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.887207, -1510.801270, 39.300499, 0.0000, 0.0000, 0.0000) createObject(1685, 3396.930420, -1512.523071, 39.306656, 0.0000, 0.0000, 0.0000) createObject(1685, 3412.490723, -1509.977539, 39.330223, 0.0000, 0.0000, 0.0000) createObject(1685, 3412.512207, -1511.089355, 39.326435, 0.0000, 0.0000, 0.0000) createObject(1685, 3412.515625, -1512.690552, 39.321869, 0.0000, 0.0000, 0.0000) createObject(1685, 3398.325684, -1547.600708, 39.596134, 0.0000, 0.0000, 0.0000) createObject(1685, 3398.283691, -1546.101807, 39.388889, 0.0000, 0.0000, 0.0000) createObject(1685, 3398.431396, -1544.215088, 39.399426, 0.0000, 0.0000, 0.0000) createObject(1685, 3414.454590, -1546.656494, 39.276287, 0.0000, 0.0000, 0.0000) createObject(1685, 3414.440186, -1548.381226, 39.276287, 0.0000, 0.0000, 0.0000) createObject(1685, 3414.484131, -1544.940674, 39.276287, 0.0000, 0.0000, 0.0000) createObject(2567, 3396.681641, -1533.894531, 40.630146, 0.0000, 0.0000, 33.7500) createObject(2567, 3409.271240, -1534.916748, 40.453888, 0.0000, 0.0000, 348.7500) createObject(2567, 3412.967041, -1522.562744, 40.453888, 0.0000, 0.0000, 11.2500) createObject(2567, 3393.853516, -1520.749268, 40.646645, 0.0000, 0.0000, 0.0000) createObject(944, 3403.388672, -1529.018799, 39.502983, 0.0000, 0.0000, 0.0000) createObject(944, 3390.986084, -1537.586670, 39.653366, 0.0000, 0.0000, 348.7500) createObject(944, 3418.504395, -1525.017090, 39.411076, 0.0000, 0.0000, 348.7500) createObject(944, 3394.825439, -1509.170898, 31.884966, 0.0000, 0.0000, 6.7982) spawnPoints = 16 rSpawnPoints = { {x=3421.267090, y=-1546.364136, z=39.248020, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3407.545898, y=-1546.580078, z=39.186665, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3387.096191, y=-1547.516724, z=39.454590, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3420.681641, y=-1510.488159, z=39.239620, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3404.905029, y=-1511.002686, z=39.237484, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3387.964844, y=-1510.464355, z=39.271309, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3419.712402, y=-1502.146362, z=22.285946, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3405.734131, y=-1503.052856, z=22.277327, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3387.575195, y=-1503.615845, z=22.485300, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3386.568115, y=-1546.704590, z=22.263044, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3399.408203, y=-1546.596802, z=22.269600, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3421.499512, y=-1547.485474, z=22.283976, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3393.754883, y=-1505.973511, z=31.660557, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3400.283936, y=-1507.614502, z=33.657486, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3400.341064, y=-1504.529297, z=29.457432, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0}, {x=3406.293213, y=-1507.656006, z=35.860611, f=0, fist=0, melee=0, handgun=24, shotgun=0, smgun=29, mgun=30, rifle=0, heavy=0, projectile=0, special1=0, gift=0, special2=0, detonator=0} } end --//--------------------------------------------------------------------------// addEventHandler("onResourceStart", getRootElement(), mapLoad) it's strange... i'm quite sure the variables are passed well but it doesnt work è_é Link to comment
eAi Posted January 4, 2008 Share Posted January 4, 2008 Avoid coding maps as scripts. It's considerably slower to load and uses more bandwidth. It also means that anyone wanting to create maps for your gamemode has to know how to script, plus it won't work with the soon-to-be-released editor. I'd say this is certainly NOT the way to do this and I'd really encourage you to spend a few minutes to work out how to use maps - it's really very easy. Link to comment
bzuco Posted January 4, 2008 Author Share Posted January 4, 2008 in my gamemode work my random spawn properly, maybe i forgot something put there... Link to comment
BrokenGlass Posted January 4, 2008 Share Posted January 4, 2008 Whats with all the code? You don't need that much to accomplish this. Link to comment
Franc[e]sco Posted January 4, 2008 Share Posted January 4, 2008 Yea i know it's slower but i'll keep it as a script cause its faster to write... btw could u explain why it doesnt work? Link to comment
Recommended Posts