Jump to content

Tables - Another doubt


Anubhav

Recommended Posts

Hello guyz:

I did something like this:

  
addCommandHandler("turflist", 
    function(p) 
        local turfs = {} 
        for k,v in ipairs(turfPos) do 
            local turfGang = executeSQLQuery("SELECT GangOwner FROM BoDTurfSystem WHERE Turfs=?", "Turf["..tostring(k).."]" ) 
            if turfs[turfGang[1].GangOwner] then 
                turfs[turfGang[1].GangOwner] = turfs[turfGang[1].GangOwner]+1 
            else 
                turfs[turfGang[1].GangOwner] = 1 
            end 
        end 
        for i, v in ipairs(turfs) do 
            outputChatBox("Group:"..tostring(i).." Value:"..tostring(k)) 
        end 
        triggerClientEvent(p, "openList", p, turfs) 
    end 
) 
  

No outputs, why?

Link to comment

Hmm, I am not using that method, now one more doubt.

  
addCommandHandler("turflist", 
    function(p) 
        local turfs = {} 
        for k,v in pairs(turfPos) do 
            local turfGang = executeSQLQuery("SELECT GangOwner FROM BoDTurfSystem WHERE Turfs=?", "Turf["..tostring(k).."]" ) 
            if k ~= 0 then 
                for l, i in pairs(turfs) do 
                    if turfs[k][1] == turfs[i][1] then 
                        turfs[k] = {turfGang[1].GangOwner, turfs[k][2]+1} 
                    else 
                        turfs[k] = {turfGang[1].GangOwner,1} 
                    end 
                end 
            else 
                turfs[k] = {turfGang[1].GangOwner,1} 
            end 
        end 
        for i, v in pairs(turfs) do 
            outputChatBox("Group:"..tostring(turfs[i][1]).." Value:"..tostring(turfs[i][2])) 
        end 
        triggerClientEvent(p, "openList", p, turfs) 
    end 
) 
  

no outputs no errors

Link to comment
  
addCommandHandler("turflist", 
    function(p) 
        local turfs = {} 
        for k,v in pairs(turfPos) do 
            local turfGang = executeSQLQuery("SELECT GangOwner FROM BoDTurfSystem WHERE Turfs=?", "Turf["..tostring(k).."]" ) 
             
            if k ~= 0 then 
                for l, i in pairs(turfs) do 
                    if turfs[k][1] == turfs[i][1] then 
                        turfs[k] = {turfGang[1].GangOwner, turfs[k][2]+1} 
                    else 
                        turfs[k] = {turfGang[1].GangOwner,1} 
                    end 
                end 
            else 
                turfs[k] = {turfGang[1].GangOwner,1} 
            end 
        end 
        for i, v in pairs(turfs) do 
            outputChatBox("Group:"..tostring(turfs[i][1]).." Value:"..tostring(turfs[i][2])) 
        end 
        triggerClientEvent(p, "openList", p, turfs) 
    end 
) 
  

EDIT: Why don't it output something? Because table is empty?

Link to comment
  
addCommandHandler("turflist", 
    function(p) 
        local turfs = {} 
        for k,v in pairs(turfPos) do 
            local turfGang = executeSQLQuery("SELECT GangOwner FROM BoDTurfSystem WHERE Turfs=?", "Turf["..tostring(k).."]" )            
                
             for i=1, #turfs do  
                   if turfs[i][1] == turfs[k][1] then 
                        turfs[k] = {turfGang[1].GangOwner, turfs[k][2]+1} 
                                break 
                        else 
                        turfs[k] = {turfGang[1].GangOwner, 1} 
                           break 
                    end 
             end 
        end 
        for i, v in pairs(turfs) do 
            outputChatBox("Group:"..tostring(turfs[i][1]).." Value:"..tostring(turfs[i][2])) 
        end 
        triggerClientEvent(p, "openList", p, turfs) 
    end 
) 

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