Anubhav Posted September 29, 2014 Share Posted September 29, 2014 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
Saml1er Posted September 29, 2014 Share Posted September 29, 2014 local val = turfs["myGang"] or local val = turfs.myGang Both will work. EDIT: You're using ipairs. Which will get only integer keys and it will not count string keys. Use pairs. Link to comment
Anubhav Posted September 29, 2014 Author Share Posted September 29, 2014 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
Saml1er Posted September 29, 2014 Share Posted September 29, 2014 for l, i in pairs(turfs) do You are looping while table is empty which probably won't insert anything in it. Link to comment
Anubhav Posted September 29, 2014 Author Share Posted September 29, 2014 I did that to no nothing! Link to comment
Saml1er Posted September 29, 2014 Share Posted September 29, 2014 I did that to no nothing! Show your new code. Link to comment
Anubhav Posted September 29, 2014 Author Share Posted September 29, 2014 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
Saml1er Posted September 29, 2014 Share Posted September 29, 2014 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
Anubhav Posted September 29, 2014 Author Share Posted September 29, 2014 Works, thank you. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now