MaRcell Posted March 6, 2020 Share Posted March 6, 2020 how do I pull the value from the table, for the spawn? I have doubts I thought it was so but it was not lol local spawnLocation = { {2028.17480 ,-1405.71252 ,17.22696} } function spawn() spawnPlayer(source,spawnLocation) fadeCamera(source, true) setCameraTarget(source, source) end addEventHandler( "onPlayerWasted", getRootElement(), spawn ) Link to comment
Moderators Patrick Posted March 6, 2020 Moderators Share Posted March 6, 2020 First of all, check the syntax of spawnPlayer. (https://wiki.multitheftauto.com/wiki/SpawnPlayer) Quote player thePlayer, float x, float y, float z You need x, y and z, not a table. I don't know why you want to use table only for 1 spawn, but then: x, y, z = spawnLocation[1][1], spawnLocation[1][2], spawnLocation[1][3] -- Why? -- spawnLocation => its the table -- [1] => its the first row of the table -- [2] => its the second value in the first row (the Y coord) And here is a Lua tutorial, you should read that, if you want to learn. Link to comment
MaRcell Posted March 6, 2020 Author Share Posted March 6, 2020 it is because afterwards I will put other values in the table so from the table otherwise I would only do a spawnPlayer (source, x, y, z) Link to comment
Skuleris Posted March 6, 2020 Share Posted March 6, 2020 You can do spawnLocation[1][1], spawnLocation[1][2]... as Patrick told you to. Or use unpack: spawnPlayer(source,unpack(spawnLocation[1])) Link to comment
MaRcell Posted March 6, 2020 Author Share Posted March 6, 2020 would i have to use a spawn player for each value in the table? Link to comment
Moderators Patrick Posted March 6, 2020 Moderators Share Posted March 6, 2020 I don't understand what you want, but I think select a random spawnpoint in every time. If yes, here is an example: local rows = #spawnLocation -- example, returns 2 if have 2 spawnpoints in the table local randomRowIndex = math.random(1, rows) -- return a number between 1 and length of the table. (what can be 1 or 2, if have 2 spawnpoints in the table) local x, y, z = spawnLocation[randomRowIndex][1], spawnLocation[randomRowIndex][2], spawnLocation[randomRowIndex][3] -- get values like in previous example Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now