Jump to content

random Pos


Recommended Posts

Hello guys, i'm currently  working on pilot job, but i got some problems.

 

How can i make this work?

What i want: When player spawned the job vehicle, the player get a random checkpoint in another airport. When he hit the checkpoint, new checkpoint created from table.

local posTable = {
    {{-1341.5460205078, -149.02934265137, 14.1484375}},
    {{-1586.5443115234, -214.85159301758, 14.1484375}},
    {{-1478.2484130859, 12.554589271545, 14.369514465332}}
}

function createRandomPos()
    local rTable = posTable[math.random(#posTable)]
    spawnX, spawnY, spawnZ = unpack(rTable)
    jobMarker = createMarker(spawnX,spawnY,spawnZ,"checkpoint",2,255,255,0,100)
end

addEvent("startPilotMarkers",true) 
addEventHandler("startPilotMarkers",root,function()

    createRandomPos()

    
    
    addEventHandler("onClientMarkerHit",jobMarker,function()
        destroyElement(jobMarker)
        outputChatBox("Success")
        createRandomPos()
    end)
    
end)

 

Link to comment
local posTable = {
    {-1341.5460205078, -149.02934265137, 14.1484375},
    {-1586.5443115234, -214.85159301758, 14.1484375},
    {-1478.2484130859, 12.554589271545, 14.369514465332}
}

function createRandomPos()
    local x, y, z = unpack(posTable[math.random(#posTable)])
    jobMarker = createMarker(x,y,z,"checkpoint",2,255,255,0,100)
end

addEvent("startPilotMarkers",true) 
addEventHandler("startPilotMarkers",root,function()

    createRandomPos()

    
    
    addEventHandler("onClientMarkerHit",jobMarker,function()
        destroyElement(jobMarker)
        outputChatBox("Success")
        createRandomPos()
    end)
    
end)

 

Link to comment
local posTable = {
    {{-1341.5460205078, -149.02934265137, 14.1484375}},
    {{-1586.5443115234, -214.85159301758, 14.1484375}},
    {{-1478.2484130859, 12.554589271545, 14.369514465332}}
}

You have double {{  }} brackets, meaning if you wanted to get the first 3 positions, you'd need posTable[1][1][1], posTable[1][1][2], posTable[1][1][3] or with unpack( posTable [ math.random ( #posTable ) ] [ 1]  )

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