Jump to content
  • 0

Editing Play resource to add more spawnpoints


alwSmokE

Question

Let me preface this by saying I don't know much about coding. I want to add more spawnpoints to my freeroam server. I found the lua file (I think) that needs to be edited in the Play resource. I've edited it so it looks like this:

addEventHandler("onResourceStart", resourceRoot,

function()

for i,player in ipairs(getElementsByType("player")) do

spawn(player)

end

end

)

function spawn(player)

repeat until spawnPlayer ( player, -711+math.random(1,5), 957+math.random(5,9), 12.4, 90, math.random(9,288) )

fadeCamera(player, true)

setCameraTarget(player, player)

repeat until spawnPlayer ( player, 2058+math.random(1,5), -3122+math.random(5,9), 18, 90, math.random(9,288) )

fadeCamera(player, true)

setCameraTarget(player, player)

repeat until spawnPlayer ( player, 2017+math.random(1,5), -2540+math.random(5,9), 14, 90, math.random(9,288) )

fadeCamera(player, true)

setCameraTarget(player, player)

end

addEventHandler("onPlayerJoin", root,

function()

spawn(source)

end

)

addEventHandler("onPlayerWasted", root,

function()

setTimer(spawn, 1800, 1, source)

end

)

This has worked to change the spawnpoint to one of the new ones. But it only uses one spawnpoint. I want it to randomly select one. I also want to add more spawnpoints when I get this working.

Any help would be greatly appreciated.

Link to comment

3 answers to this question

Recommended Posts

  • 0

Using math.random you can let Lua pick a random number. Like:

local randomNum=math.random(1,3)
if randomNum==1 then
outputChatBox("Cookie")
elseif randomNum==2 then
outputChatBox("Cake")
else
outputChatBox("Crackers")
end

You can use pretty much the same method as I described above to make the spawns random.

Link to comment
  • 0

g_SpawnPoints = { }
g_SpawnPoints[1] = { x= -711, y=  957, z=12.4, dx=5, dy=5 }
g_SpawnPoints[2] = { x= 2058, y=-3122, z=18,   dx=5, dy=5 }
g_SpawnPoints[3] = { x= 2017, y=-2540, z=14,   dx=5, dy=5 }
 
function spawn(player)
  math.randomseed(getTickCount())
  -- choose a spawnpoint
  local sp = g_SpawnPoints[math.random(#g_SpawnPoints)]
  --spawn player using spawnpoint params
  repeat until spawnPlayer (player, sp.x+math.random(sp.dx), sp.y+math.random(sp.dy), sp.z, math.random(360), math.random(9,288))
  fadeCamera(player, true)
  setCameraTarget(player, player)
end

Thanks to DazzaaJay and Benji on the potholestudios site! This works.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...