Jump to content

Settings > Table


Recommended Posts

Hey guys, reading over saw that you can set a table value to the settings, will admin panel be able to read and edit is as a table? also, should this work like this?

  
  
Dashboard = { 
    rankings = { 
        labels = { 
            "Kills", 
            "Deaths", 
            "Headshots", 
            "PlayTime", 
            "EXP", 
            "Level", 
            "Rank",            
        }, 
} 
  
function onResourseStart() 
set("Labels", Dashboard.rankings.labels) 
setTimer(CheckLabels, 1000,0) 
end 
onResourseStart() 
  
function CheckLabels() 
LabelTable = {unpack(get("Labels"))} 
Dashboard.rankings.labels = {} 
for i=1, #LabelTable do 
Dashboard.rankings.labels[i] = LabelTable[i] 
end 
for c,v in ipairs(getElementsByType("player")) do 
triggerClientEvent(c,"UpdateLocalLabels",resourceRoot, Dashboard.rankings.labels) 
end 
end 
  
  
  

Meta:

  
<settings> 
    <setting name="*Labels" value="{Kills, Deaths, Headshots, PlayTime, EXP, Level, Rank}" friendlyname="Dashboard Labels" group="" accept="" examples="cash, kills" desc="" /> 
</settings> 
  
  

Link to comment

That isnt a string itself?

Becouse if yes, i cannot unpack it normally..

  
function CheckLabels() 
LabelTable = {unpack(get("Labels"))} 
Dashboard.rankings.labels = {} 
for i=1, #LabelTable do 
Dashboard.rankings.labels[i] = LabelTable[i] 
end 
for c,v in ipairs(getElementsByType("player")) do 
triggerClientEvent(c,"UpdateLocalLabels",resourceRoot, Dashboard.rankings.labels) 
end 
end 

Link to comment

Well, that gives error upon unpack, no table.

This way it outputed Kills, as expected.

function CheckLabels() 
LabelTable = {unpack(get("Labels"))} 
outputServerLog(LabelTable[1]) 
Dashboard.rankings.labels = {} 
for i=1, #LabelTable do 
Dashboard.rankings.labels[i] = LabelTable[i] 
end 
for c,v in ipairs(getElementsByType("player")) do 
triggerClientEvent(c,"UpdateLocalLabels",resourceRoot, Dashboard.rankings.labels) 
end 
end 
  
function onResourseStart() 
set("Labels", Dashboard.rankings.labels) 
setTimer(CheckLabels, 1000,0) 
end 
onResourseStart() 
  

Now, my problem is how to edit it, but i'll figure it out..

Link to comment

Try this

Dashboard = { 
    rankings = { 
        labels = { 
            "Kills", 
            "Deaths", 
            "Headshots", 
            "PlayTime", 
            "EXP", 
            "Level", 
            "Rank",           
        }, 
    } 
} 
      
function onResourseStart() 
    set("Labels", toJSON ( Dashboard.rankings.labels ) ) 
    setTimer(CheckLabels, 1000,0) 
end 
onResourseStart() 
      
function CheckLabels() 
    LabelTable = fromJSON ( get ( "Labels" ) ) 
    outputChatBox ( "LabelTable Type -> "..type ( LabelTable ) ) 
    outputChatBox ( "LabelTable Value -> "..tostring ( LabelTable ) ) 
     
    Dashboard.rankings.labels = {} 
    --for i=1, #LabelTable do -> You can't use the "#" operator, since the index's aren't numeric values  
    for i, v in pairs ( LabelTable ) do 
        Dashboard.rankings.labels[i] = v 
    end 
    for c,v in ipairs(getElementsByType("player")) do 
        triggerClientEvent(c,"UpdateLocalLabels",resourceRoot, Dashboard.rankings.labels) 
    end 
end 

and reply what it's outputting.

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