Lloyd Logan Posted January 23, 2013 Share Posted January 23, 2013 Hey, how do i make it so that when a player enters a marker (picks up ped) its displays a random drop off marker from an array/list? Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 Create a table, place many coordinates there, get a random index and unpack the coordinates, then create the marker. Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 Create a table, place many coordinates there, get a random index and unpack the coordinates, then create the marker. Right, i am kind of confused, I will try and create some code to show you. Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 Create a table, place many coordinates there, get a random index and unpack the coordinates, then create the marker. Sorry, I am totally confused, so far i have, local dropOffs = { [1]={1813.51733, -1889.07434, 14.54434}, [2]={1825.07617, -1821.19128, 14.55475}, [3]={1824.75806, -1715.95935, 14.49071}, [4]={1843.08228, -1526.89624, 14.60579}, [5]={1853.63428, -1413.55920, 14.53299}, [6]={1855.38696, -1311.96008, 14.65701}, [7]={1827.38684, -1257.55383, 14.68799}, [8]={1760.68250, -1289.40527, 14.60042}, [9]={1711.00635, -1319.90845, 14.53422}, [10]={1738.90808, -1444.43054, 14.50528}, [11]={1841.47546, -1503.76233, 14.59137}, [12]={1822.14709, -1564.29834, 14.52254}, [13]={1817.74731, -1665.99097, 14.60268}, [14]={1818.21057, -1777.69324, 14.57040} } for k, v ipairs(dropOffs) do Thats all I have got right now ( I feel i might give up on scripting altogether now! Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 You don't need a loop to get a random value. Use: math.random to get a random index of the table. Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 You don't need a loop to get a random value.Use: math.random to get a random index of the table. I understand what you mean now! So if I create two tables, one to pick up, and one to drop off, how would i use math.random to pick out one from each table and set them on the map? Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 math.random returns a random number from another number, e.g: result = math.random ( 10 ) outputChatBox ( result ) that'll get a random number of 10. With #table you can get the total amount of items inside a table ( NOTE: IT MUST BE AN INDEXED TABLE ). Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 math.random returns a random number from another number, e.g: result = math.random ( 10 ) outputChatBox ( result ) that'll get a random number of 10. With #table you can get the total amount of items inside a table ( NOTE: IT MUST BE AN INDEXED TABLE ). A couple of points. 1. Will it get 1 random co-ordinates out 10? 2. I dont understand how i could use #, and what's and indexed table? Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 Replace that 10 with #dropOffs. Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 Replace that 10 with #dropOffs. Replace it to get a random co-ordinate? Link to comment
Baseplate Posted January 23, 2013 Share Posted January 23, 2013 unpack(math.random(#dropoffs)) Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 unpack(math.random(#dropoffs)) So if I wanted to create a random marker with this Array would it be, dropO = unpack(math.random(#dropoffs)) createMarker( dropO, "cylinder", 1.5, 255, 0, 0) Something like that:/ Link to comment
Baseplate Posted January 23, 2013 Share Posted January 23, 2013 (edited) createMarker(unpack ( fireLocations [ math.random ( #dropoffs ) ] ), "cylinder", 1.5, 255, 0, 0) or function unpackPos() return unpack ( fireLocations [ math.random ( #dropoffs ) ] ) end local x, y, z=unpackPos() createMarker(x, y, z, "cylinder", 1.5, 255, 0, 0) Edited January 23, 2013 by Guest Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 createMarker(unpack(math.random(#dropoffs)), "cylinder", 1.5, 255, 0, 0) Ahh, thanks! Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 Both wrong, you are trying to unpack a number. createMarker ( unpack ( dropoffs [ math.random ( #dropoffs ) ] ), "cylinder", 1.5, 255, 0, 0 ) Link to comment
Baseplate Posted January 23, 2013 Share Posted January 23, 2013 Already edited my post slightly before you post that. Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 Both wrong, you are trying to unpack a number. createMarker ( unpack ( dropoffs [ math.random ( #dropoffs ) ] ), "cylinder", 1.5, 255, 0, 0 ) I done this, but nothing happens? local dropoffs = { [1]={1802.951171875, -1889.1865234375, 13.185905456543}, [2]={1784.349609375, -1890.255859375, 13.176010131836} } function rMarker() createMarker ( unpack ( dropoffs [ math.random ( #dropoffs ) ] ), "cylinder", 1.5, 255, 0, 0 ) end addCommandHandler("heyy", rMarker) Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 local dropoffs = { [1]={1802.951171875, -1889.1865234375, 13.185905456543}, [2]={1784.349609375, -1890.255859375, 13.176010131836} } function rMarker() local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) createMarker ( x, y, z, "cylinder", 1.5, 255, 0, 0 ) end addCommandHandler("heyy", rMarker) 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