0

I'm making a fivem server. But when i tru to pick the job.grade.name he says No grades.

QBShared.Jobs = {
["unemployed"] = {
    label = "Werkloos",
    grades = {
        [0] = {
            name = 'Werkloos',
            payment = 10,
        },
    },
    defaultDuty = true,
},
["police"] = {
    label = "Politie",
    grades = {
        [0] = {
            name = "Politie - Student", **Want to pick this**
            payment = 200,
        },

        [1] = {
            name = 'Aspirant',
            payment = 300,
        },

        [2] = {
            name = 'Agent',
            payment = 400,
        },

        [3] = {
            name = 'Hoofd Agent',
            payment = 400,
        },

        [4] = {
            name = 'Brigadier',
            payment = 400,
        },

        [5] = {
            name = 'Inspecteur',
            payment = 400,
        },

        [6] = {
            name = 'Hoofd Inspecteur',
            payment = 400,
        },

        [7] = {
            name = 'Commissaris',
            payment = 400,
        },

        [8] = {
            name = 'Hoofd Commissaris',
            payment = 400,
        },

        [9] = {
            name = 'Eerste Hoofd Commissaris',
            isboss = true,
            payment = 400,
        },
    },
    defaultDuty = true,

So people can type /baan and then the see Baan: Politie What i want is The must see Baan: Politie - Politie Student

QBCore.Commands.Add("baan", "Kijk wat je baan is", {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
TriggerClientEvent('chatMessage', source, "SYSTEM", "warning", "Baan: "..Player.PlayerData.job.label .. ' - ' ..Player.PlayerData.job.grade.name)

end)

Someone can help me? Because i want to learn more about lua but dont get this to work..

1 Answer 1

1

'Jobs' needs a string key to access it
and 'grades' needs a numerical index

Player .PlayerData .Jobs [job] .grades [grade] .name

TriggerClientEvent('chatMessage', source, "SYSTEM", "warning", "Baan: "..Player.PlayerData.job.label .. ' - ' ..Player.PlayerData.Jobs[job].grades[grade].name)


I'm assuming that somehow within your game engine, these values get parsed into PlayerData. That'll depend on the functions contained within fivem, and that you've used them properly. Otherwise, to access the raw table data, it's more like this:

print( QBShared.Jobs['police'].label )

Politie

print( QBShared.Jobs['police'].grades[0].name )

Politie - Student

print( QBShared.Jobs['police'].grades[0].payment )

200


if the game rearranges those during import into PlayerData, it might be

Player.PlayerData[job][grade].name

but it's very likely it remains in the original syntax illustrated above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.