Cocodrilo Posted January 22, 2014 Posted January 22, 2014 What is wrong here? I want to create items with random ID and Positions. --example for items .. items = { { "Tire!", 1073, -1428.4814453125, 2666.4931640625, 55.6875}, { "Engine!", 929, -1425.5595703125, 2654.69140625, 55.6875}, { "Hamburguer!", 2768, -1411.2607421875, 2635.3916015625, 55.6875}, } function mainFunction() local tiempo = 5000 if ( not isElement (items)) then setTimer ( function() for i,v in ipairs (items) do local randomPos = items[math.random(v[3],v[4],v[5],#items)] local randomID = items[math.random(v[2],#items)] object = createObject(randomID, randomPos, math.random(0, 360)) setElementData(object, v[1], true) end end, tiempo, 1 ) end end mainFunction()
Castillo Posted January 22, 2014 Posted January 22, 2014 What is the problem? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Cocodrilo Posted January 22, 2014 Author Posted January 22, 2014 ERROR: server.lua:18: wrong number of arguments
Castillo Posted January 22, 2014 Posted January 22, 2014 Well, because how you are using math.random is wrong. I don't understand something, you want to create the 3 items from the table? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Cocodrilo Posted January 22, 2014 Author Posted January 22, 2014 I really want : 1.- get objects positions: v[3] , v[4], v[5] from the table. Then create a call local all objects positions to then create the object with random positions. 2.- follow suit for objects ids v[2]
Castillo Posted January 22, 2014 Posted January 22, 2014 That doesn't make any sense to me. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Cocodrilo Posted January 22, 2014 Author Posted January 22, 2014 maybe, i am very confused. I found this code: local locations = { { -- ls_beach { x=529, y=-1884, z=3 }, { x=612, y=-1884, z=3 } }, { -- sf_beach { x=-2920, y=68, z=1 }, { x=-2913, y=159, z=3 } } } addEventHandler("onResourceStart", resourceRoot, function () setTimer(function() local randomResult = locations[math.random(1,#locations)] for i=1,#randomResult do local locationInfo = randomResult[i] createObject ( 1337, locationInfo.x, locationInfo.y, locationInfo.z) end end,60000,1) end) I want that but without x= , y=, z= just like this { -1428.4814453125, 2666.4931640625, 55.6875 }
Castillo Posted January 22, 2014 Posted January 22, 2014 items = { { "Tire!", 1073, -1428.4814453125, 2666.4931640625, 55.6875}, { "Engine!", 929, -1425.5595703125, 2654.69140625, 55.6875}, { "Hamburguer!", 2768, -1411.2607421875, 2635.3916015625, 55.6875}, } function mainFunction ( ) local tiempo = 5000 setTimer ( function ( ) for _, v in ipairs ( items ) do object = createObject ( v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ], 0, 0, math.random ( 0, 360 ) ) setElementData ( object, v [ 1 ], true ) end end ,tiempo, 1 ) end mainFunction ( ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Castillo Posted January 23, 2014 Posted January 23, 2014 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
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