Matevsz Posted November 16, 2017 Posted November 16, 2017 Hello, how do you make random objects appear and blips on them? Objects: createObject(1264, -2168.7001953125, 1879.7998046875, -69.199996948242, 3, 1644) createObject(926, -2198.599609375, 1853.400390625, -57.599998474121, 0, 353.99597167969, 0, 3, 2033) createObject(1356, -2156.6796875, 1838.1103515625, -65.067947387695, 3, 2037) createObject(1442, -2159.599609375, 1827.900390625, -64.300003051758, 3, 2060) createObject(924, -2134.8994140625, 1838.2001953125, -63.599998474121, 349.99694824219, 0, 1.99951171875, 3, 2033) createObject(928, -2085.5, 1847.7998046875, -54.099998474121, 3, 1644) createObject(1230, -2154.7998046875, 1844.099609375, -49.099998474121, 3, 2033) createObject(916, -2131.7998046875, 1847.599609375, -51.5, 3, 2037) createObject(917, -2110.2998046875, 1847.7001953125, -42.299999237061, 3, 1644) createObject(1265, -2104.099609375, 1852.099609375, -36.700000762939, 350.01892089844, 355.93505859375, 1.2908935546875, 3, 2060) createObject(1371, -2123.099609375, 1842, -54.799999237061, 2037, 3, 2060) createObject(1357, -2146.5, 1851.7001953125, -60.200000762939, 0, 353.99597167969, 0, 3, 1644) createObject(926, -2156, 1860.7001953125, -61.400001525879, 3, 2033) so the id of the object is local objects = { {1264}, {926}, {1356}, {1442}, {924}, {928}, {1230}, {916}, {917}, {1265}, {1371}, {1357} } And now how do you make the objects appear randomly? And the blips on them? I tried: createBlipAttachedTo(objects, 0) Error:Bad argument "Expected element at argument 1, got table"
Dimos7 Posted November 16, 2017 Posted November 16, 2017 First heat do you mean random ? random object I'd and second the objects is table you need a loop for that
MaurO^ Posted November 16, 2017 Posted November 16, 2017 objects = { {1264, -2168.7001953125,1879.7998046875,-69.199996948242}, {926, -2198.599609375,1853.400390625,-57.599998474121}, {1356, -2156.6796875,1838.1103515625,-65.067947387695} } function createRandomObject() if isElement(object) then destroyElement(object) end if isElement(blip) then destroyElement(blip) end randomObject = math.random(#objects) id, x, y, z = unpack(objects[randomObject]) object = createObject(id, x, y, z) blip = createBlipAttachedTo(object, 0) end addCommandHandler("create", createRandomObject) with this example, write /create will create a random object.
Moderators IIYAMA Posted November 16, 2017 Moderators Posted November 16, 2017 (edited) @Matevsz Why don't you start with learning how to interact with a table? Your table structure is incorrect created based on the data that is inside it. Either put more data inside each item(sub table) or make each item the value(number) and not a sub-table. If you do not understand about a word of what I just said, start this: Or boring, but useful: http://lua-users.org/wiki/TablesTutorial Edited November 16, 2017 by IIYAMA 1 Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
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