Jump to content

Tables


Xeno

Recommended Posts

local objects = { 
    {model=1210, x=-1318, y=-145, z=13.25, rot=90, rot2=0,rot3=90}, 
    {model=1210, x=-1322, y=-145, z=13.25, rot=90, rot2=0,rot3=90}, 
   {model=1210, x=-1330, y=-145, z=13.25, rot=90, rot2=0,rot3=90} 
} 
  
for index, object in ipairs(objects) do 
    myobject = createObject(object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot) 
local x,y,z = getElementPosition(myobject) 
mymarker = createMarker(x,y,z,"cylinder",4,200,0,0,255) 
  
end 

at the moment it spawns all objects, but I want it so it only spawns 1, how do I do this?

Link to comment
local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
local object = objects [ math.random ( #objects ) ] 
myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
local x,y,z = getElementPosition ( myobject ) 
mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 

Did you mean that?

Link to comment

Thank you, thats what I wanted.

I'm trying to make it so when you hit the marker it sets a new location for the object,

local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
local object = objects [ math.random ( #objects ) ] 
myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
local x,y,z = getElementPosition ( myobject ) 
mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 
  
function giveCash(player) 
givePlayerMoney(player, 20000) 
destroyElement(mymarker) 
destroyElement(myobject) 
myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
end 
addEventHandler("onMarkerHit", mymarker, giveCash) 

But this doesn't seem to work..

Link to comment
local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
function giveCash ( player ) 
    givePlayerMoney ( player, 20000 ) 
    destroyElement ( mymarker ) 
    destroyElement ( myobject ) 
    createRandomLocation ( ) 
end 
  
function createRandomLocation ( ) 
    local object = objects [ math.random ( #objects ) ] 
    myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
    local x, y, z = getElementPosition ( myobject ) 
    mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 
    addEventHandler ( "onMarkerHit", mymarker, giveCash ) 
end 
createRandomLocation ( ) 

Link to comment
local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
function giveCash ( player ) 
    givePlayerMoney ( player, 20000 ) 
    destroyElement ( mymarker ) 
    destroyElement ( myobject ) 
    createRandomLocation ( ) 
end 
  
function createRandomLocation ( ) 
    local object = objects [ math.random ( #objects ) ] 
    myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
    local x, y, z = getElementPosition ( myobject ) 
    mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 
    addEventHandler ( "onMarkerHit", mymarker, giveCash ) 
end 
createRandomLocation ( ) 

Why "createRandomLocation ( )" in the end?

Link to comment

Because if you put it at the top, the function won't exist yet, other way would be using onResourceStart event.

local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        createRandomLocation ( ) 
    end 
) 
  
function giveCash ( player ) 
    givePlayerMoney ( player, 20000 ) 
    destroyElement ( mymarker ) 
    destroyElement ( myobject ) 
    createRandomLocation ( ) 
end 
  
function createRandomLocation ( ) 
    local object = objects [ math.random ( #objects ) ] 
    myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
    local x, y, z = getElementPosition ( myobject ) 
    mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 
    addEventHandler ( "onMarkerHit", mymarker, giveCash ) 
end 

Link to comment
Because if you put it at the top, the function won't exist yet, other way would be using onResourceStart event.
local objects = 
    { 
        { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, 
        { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } 
    } 
  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        createRandomLocation ( ) 
    end 
) 
  
function giveCash ( player ) 
    givePlayerMoney ( player, 20000 ) 
    destroyElement ( mymarker ) 
    destroyElement ( myobject ) 
    createRandomLocation ( ) 
end 
  
function createRandomLocation ( ) 
    local object = objects [ math.random ( #objects ) ] 
    myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) 
    local x, y, z = getElementPosition ( myobject ) 
    mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) 
    addEventHandler ( "onMarkerHit", mymarker, giveCash ) 
end 

Oh, I just didn't understand this. I thought it should just run "createRandomLocation" when something would happen, you know, not when resource start. Dumbass head :mrgreen:

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...