FWCentral Posted September 7, 2011 Posted September 7, 2011 I want to create random vehicle positions to use to spawn vehicle later but the way i tried does not work randompos = { } randompos[1] = (2514, 2396, 3) randompos[2] = (2133, 1009, 10) randompos[3] = (1674, 988, 10) but i get an error when i start the script?
FWCentral Posted September 7, 2011 Author Posted September 7, 2011 What you mean use random math? i used random math for the createVehicle, randompos[math.random(1,3)] but this is not the problem it is the randompos[1] = (2514, 2396, 3) i don't think i can use this on it own to get x y z i may need to change it.
JR10 Posted September 7, 2011 Posted September 7, 2011 local randPosTable = { { 0 , 0 , 0 } , { 1 , 1 , 1 } , --etc } function getRandomData ( table ) return table [ math.random ( #table ) ] end now use it like getRandomData ( randPosTable ) And the returned data will be a table, since the data in the table is several tables So you will use it like: local data = getRandomData ( randPosTable ) local x = data [ 1 ] local y = data [ 2 ] local z = data [ 3 ] Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
FWCentral Posted September 7, 2011 Author Posted September 7, 2011 Thanks JR10 i cant test it now ive got work but that looks right and your reply's usually fix most scripts.
Kenix Posted September 7, 2011 Posted September 7, 2011 you can also use unpack http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
JR10 Posted September 7, 2011 Posted September 7, 2011 Example for unpack: local dataTable = { 0 , 0 , 0 } -- dataTable = { posX , posY , posZ } local posX , posY , posZ = unpack ( dataTable ) unpack unpacks the table. If my code didn't work, post what you did. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
JR10 Posted September 7, 2011 Posted September 7, 2011 for index , player in ipairs ( getPlayersInTeam ( getTeamFromName ( "CarJacker" ) ) ) do outputChatBox("Go get the stolen car! It is marked on your map.", player, 255,0,0) end Sorry, my bad, I was mistaken at the team name. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Kenix Posted September 8, 2011 Posted September 8, 2011 this is more better: local randPosTable = { -- 1 x 2 y 3 z 4 rotation 5 skin 6 interior 7 dimension 8 team { 0 , 0 , 0 , 0 , 15 , 0 , 0 , nil } , { 1 , 1 , 1 , 0 , 25 , 0 , 0 , nil } , -- and etc } function randomSpawn(player,randPosTable) local random = math.random(1,#randPosTable) spawnPlayer(player, randPosTable[random][1], randPosTable[random][2], randPosTable[random][3], randPosTable[random][4], randPosTable[random][5], randPosTable[random][6], randPosTable[random][7], randPosTable[random][8]) end example: addEventHandler("onPlayerJoin",root, function() randomSpawn(source,randPosTable) fadeCamera(source, true) setCameraTarget(source, source) end ) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
JR10 Posted September 8, 2011 Posted September 8, 2011 He added all the arguments in spawnPlayer to the table. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
Haze Posted September 8, 2011 Posted September 8, 2011 Thx 4 Help EveryOne Ingame nick: FWC>Haze Server I play: FWCentral Job: FWCentral Developer Website: fwcentral.net
Kenix Posted September 8, 2011 Posted September 8, 2011 No problem http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
JR10 Posted September 8, 2011 Posted September 8, 2011 You welcome. Business System viewtopic.php?f=108&t=35797 Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726 SQLite Tutorial viewtopic.php?f=148&t=38203
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