Jump to content

[Help ] createObject [ in ipairs ] randomPosition and Id


Cocodrilo

Recommended Posts

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()  

Link to comment

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 }

Link to comment
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 ( ) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...