Jump to content

Table question


mjau

Recommended Posts

If i have a table

stopTable{ 
[1]={1812.65198, -1889.86047, 13.41406}, 
[2]={1825.22791, -1635.03711, 13.38281}, 
[3]={1855.01685, -1430.47449, 13.39063}, 
[4]={1732.81580, -1296.87122, 13.44294}, 
[5]={1473.19226, -1295.77124, 13.48315}, 
[6]={1443.60376, -1498.26660, 13.37650}, 
[7]={1426.37280, -1716.12439, 13.38281}, 
[8]={1315.06909, -1656.43799, 13.38281}, 
[9]={1359.06250, -1432.39734, 13.38281}, 
[10]={1169.82983, -1392.34473, 13.41728}, 
[11]={930.76508, -1392.92627, 13.26561}, 
[12]={815.24756, -1317.91345, 13.44460}, 
[13]={585.04199, -1320.53748, 13.40609}, 
[14]={526.99365, -1624.20361, 16.63225},} 
  

I am creating markers on theese cordinates but i want the next marker to be created when i hit the first one like when i hit the first one in the list then the second shows up and the first goes away

And this creates the first marker again when i finsihed the table and goes like this

Now how to do this ? xD

Link to comment
  
--First, you need to properly format your table.  
stopTable = { 
    {1812.65198, -1889.86047, 13.41406}, 
    {1825.22791, -1635.03711, 13.38281}, 
    {1855.01685, -1430.47449, 13.39063}, 
    {1732.81580, -1296.87122, 13.44294}, 
    {1473.19226, -1295.77124, 13.48315}, 
    {1443.60376, -1498.26660, 13.37650}, 
    {1426.37280, -1716.12439, 13.38281}, 
    {1315.06909, -1656.43799, 13.38281}, 
    {1359.06250, -1432.39734, 13.38281}, 
    {1169.82983, -1392.34473, 13.41728}, 
    {930.76508, -1392.92627, 13.26561}, 
    {815.24756, -1317.91345, 13.44460}, 
    {585.04199, -1320.53748, 13.40609}, 
    {526.99365, -1624.20361, 16.63225} 
} 
  
--Create the first marker. I am assuming this is a clientside bus mission? 
function startBusMission() 
    local stopMarker = createMarker(unpack(stopTable[1])) 
    setElementData(stopMarker, "stopID", 1, false) 
    addEventHandler("onClientMarkerHit", stopMarker, stopMarkerHit) 
end 
  
--Then, each time a marker is hit, create the next one (or, end the mission if the last one has been hit). 
function stopMarkerHit(hitPlayer, matchingDimension) 
    if hitPlayer ~= localPlayer or not matchingDimension then 
        return false 
    end 
     
    local stopID = getElementData(source, "stopID") 
    if stopID == #stopTable then 
        outputChatBox("* Mission complete!", 0, 255, 0) 
    else 
        local nextID = stopID + 1 
        outputChatBox("* Stop "..stopID.." of "..#stopTable.." complete!", 0, 255, 0) 
        local nextMarker = createMarker(unpack(stopTable[nextID])) 
        setElementData(nextMarker, "stopID", nextID, false) 
        addEventHandler("onClientMarkerHit", nextMarker, stopMarkerHit) 
    end 
     
    destroyElement(source) 
end 
  

Link to comment
I know this is not my topic, but, how would you just make it so it creates all the markers in the table..?

I think no...

You must do a while like that:

  
stopTable = { 
    {1812.65198, -1889.86047, 13.41406}, 
    {1825.22791, -1635.03711, 13.38281}, 
    {1855.01685, -1430.47449, 13.39063}, 
    {1732.81580, -1296.87122, 13.44294}, 
    {1473.19226, -1295.77124, 13.48315}, 
    {1443.60376, -1498.26660, 13.37650}, 
    {1426.37280, -1716.12439, 13.38281}, 
    {1315.06909, -1656.43799, 13.38281}, 
    {1359.06250, -1432.39734, 13.38281}, 
    {1169.82983, -1392.34473, 13.41728}, 
    {930.76508, -1392.92627, 13.26561}, 
    {815.24756, -1317.91345, 13.44460}, 
    {585.04199, -1320.53748, 13.40609}, 
    {526.99365, -1624.20361, 16.63225} 
} 
  
--Create the first marker. I am assuming this is a clientside bus mission? 
function startBusMission() 
for i, value in ipairs(stopTable)do 
    local stopMarker[i] = createMarker(unpack(stopTable[i])) 
    setElementData(stopMarker[i], "stopID", 1, false) 
    addEventHandler("onClientMarkerHit", stopMarker[i], stopMarkerHit) 
end 
end 
  

I think it work :|

Link to comment

Correct

  
stopTable = { 
    {1812.65198, -1889.86047, 13.41406}, 
    {1825.22791, -1635.03711, 13.38281}, 
    {1855.01685, -1430.47449, 13.39063}, 
    {1732.81580, -1296.87122, 13.44294}, 
    {1473.19226, -1295.77124, 13.48315}, 
    {1443.60376, -1498.26660, 13.37650}, 
    {1426.37280, -1716.12439, 13.38281}, 
    {1315.06909, -1656.43799, 13.38281}, 
    {1359.06250, -1432.39734, 13.38281}, 
    {1169.82983, -1392.34473, 13.41728}, 
    {930.76508, -1392.92627, 13.26561}, 
    {815.24756, -1317.91345, 13.44460}, 
    {585.04199, -1320.53748, 13.40609}, 
    {526.99365, -1624.20361, 16.63225} 
} 
  
function stopMarkerHit( Element,dim ) 
    -- code  
end 
  
function startBusMission( ) 
    for i, _ in pairs( stopTable ) do 
        local stopMarker = createMarker( unpack( stopTable[i] ) ) 
        setElementData( stopMarker, "stopID", i, false ) 
        addEventHandler( "onClientMarkerHit", stopMarker, stopMarkerHit ) 
    end 
end 
  

Link to comment

How do i make the table start on first line again when table is finished ? i wanna make i mean im making a train system wich you drive around SA as many times you want how to do this ? i know how to create the trains money and that shit i just need help getting the table values in order and startinng on first value again whem im done with all

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