Jump to content

Using table to create spawn points


knightscript

Recommended Posts

Hello, i was using a script that would let me add 3 spawn points but not more, and i would like to add more, i have the following table:

  
local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
 local random = math.random ( #spawns ) 
  

but after this, i have no idea what to do,

my current code is this:

  
function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) 
  if not( isGuestAccount (getPlayerAccount(source)) ) then 
     number2 = {216, 220, 222, 226, 230} 
       numberskin2 = number2 [ math.random ( #number2 ) ] 
       skins = {} 
     fadeCamera (source, true) 
     setTimer (spawnPlayer, 1000, 1, source, 2036.1735839844, -1413.0563964844, 16.9921875, 0, numberskin2, 0, 0, getPlayerTeam(source)) 
     setTimer (setCameraTarget, 1250, 1, source, source) 
     setTimer (fadeCamera, 2000, 1, source, true) 
  end 
end 
addEventHandler ("onPlayerWasted", getRootElement(), onWasted) 

I tried using the same structure as my random skin function, but it doesnt work.

Link to comment

Overwrite spawn function or just change name to this...

  
function spawnPlayer(thePlayer) 
    local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
  
    local lucky = math.random ( #spawns ) 
    spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) 
  
    return true 
end 
  

Link to comment

True.. Forgot save original function.

  
local _spawnPlayer = spawnplayer 
function spawnPlayer(thePlayer) 
    local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
  
    local lucky = math.random ( #spawns ) 
    _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) 
  
    return true 
end 
  

Link to comment

Im getting this error on my debugscript:

ERROR: [gamemodes]/knightsv1/broph.lua:183: attempt to call upvalue '

_spawnPlayer' (a nil value)

The code I have:

  
local _spawnPlayer = spawnplayer 
function spawnPlayer(thePlayer) 
    local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
  
    local lucky = math.random ( #spawns ) 
    _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) 
  
    return true 
end 
addEventHandler ("onPlayerWasted", getRootElement(), spawnPlayer) 

Thanks, :)

Link to comment

vx89:

  
local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
 function onWasted(totalAmmo, killer, killerWeapon, bodypart, stealth) 
      number2 = {216, 220, 222, 226, 230} 
      numberskin2 = number2 [ math.random ( #number2 ) ] 
       skins = {} 
      local theWeapon = getPedWeapon (source) 
      local weaponAmmo = getPedTotalAmmo (source) 
      fadeCamera (source, true) 
      local randomSpawn = spawns[math.random( #spawns)] 
      local sX, sY, sZ = unpack(randomSpawn) 
      setTimer (spawnPlayer, 1000, 1, source, sX, sY, sZ, 0, numberskin2, 0, 0, getPlayerTeam(source)) 
      --setTimer (setCameraTarget, 1250, 1, source, source) 
      --setTimer (fadeCamera, 2000, 1, source, true) 
      setTimer (giveWeapon, 2000, 1, source, 24, 100, true) 
      setTimer (giveWeapon, 2000, 1, source, 25, 100, true) 
      setTimer (giveWeapon, 2000, 1, source, 30, 100, true) 
 end 
 addEventHandler ("onPlayerWasted", getRootElement(), onWasted) 
  

I commented out SetCameraTarget and fadeCamera because it didnt solve my problem, what do you think?

Link to comment
Im getting this error on my debugscript:
ERROR: [gamemodes]/knightsv1/broph.lua:183: attempt to call upvalue '

_spawnPlayer' (a nil value)

The code I have:

  
local _spawnPlayer = spawnplayer 
function spawnPlayer(thePlayer) 
    local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
  
    local lucky = math.random ( #spawns ) 
    _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) 
  
    return true 
end 
addEventHandler ("onPlayerWasted", getRootElement(), spawnPlayer) 

Thanks, :)

local _spawnPlayer = spawnPlayer 
function spawnPlayer(thePlayer) 
    local thePlayer = source or thePlayer 
    local spawns = 
    { 
        { 816.59997558594, -7209.2998046875, 32.799999237061 }, 
        { 707.20001220703, -7272.6000976563, 32.700000762939 }, 
        { 710.5, -7412.8999023438, 32.799999237061 }, 
        { 798.70001220703, -7654, 32.5 }, 
        { 816.09997558594, -7471.3999023438, 30 }, 
        { 812.40002441406, -7321.6000976563, 32.799999237061 }, 
    } 
  
    local lucky = math.random ( #spawns ) 
    _spawnPlayer(thePlayer,spawns[lucky][1],spawns[lucky][2],spawns[lucky][3]) 
     
    return true 
end 
setTimer(function() addEventHandler("onPlayerWasted", getRootElement(), spawnPlayer) end,100,1) 

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...