Jump to content

Tables


Xeno

Recommended Posts

Posted
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?

Posted
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?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

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

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

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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?

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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:

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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