#cw-rep issue on login

1 messages · Page 1 of 1 (latest)

gusty gazelle
#

@pine forge , I'm using cw-rep for weapon skill. I have the below code:

Server

RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
    local src = source
    TriggerClientEvent("haven-recoil:client:updateWeaponSkills", src, nil, true)
end)

Client

weaponSkillLevels = {}

RegisterNetEvent("haven-recoil:client:updateWeaponSkills", function(weapon, login)
    if not weapon then
        for _, weaponName in pairs(Config.Shared.WeaponSkills) do
            local level = exports["cw-rep"]:getCurrentLevel(weaponName) or 0
            -- Clamp to 0–100
            weaponSkillLevels[weaponName] = math.max(0, math.min(100, level))

            print(weaponName .. "(" .. weaponSkillLevels[weaponName] .. "): " .. level)
        end
    else
        local level = exports["cw-rep"]:getCurrentLevel(weapon) or 0
        weaponSkillLevels[weapon] = math.max(0, math.min(100, level))
    end

    -- Optional: print or notify for debugging
    print("^2Updated weapon skills:^0", json.encode(weaponSkillLevels))
end)

For some reason, this always returns a 0 for all skills. However, by the time the character fully loads, /skills shows the actual level. Should I be adding a wait timer somewhere, or am I missing osmething in how the skills are loaded on login ?

#

I'm using the wepaonSkillLevels table as a cache, so I don't have to keep making constant requests to cw-rep

pine forge
#

The event is probably triggered before the character fetch has happened

gusty gazelle
#

So, maybe a 500 Wait ?

pine forge
#

So yeah I'd add a wait before triggering it

gusty gazelle
#

or is there a better event ?

#

K, Thanks!

pine forge
#

If you feel down for it, you can add an event trigger in cw-rep that triggers when it has loaded the character data probably

#

So what when fetched you can fill wherever needed

gusty gazelle
#

Will add

    if login then
        Wait(500)
    end```
to the client event
pine forge
#

otherwise a Wait is probably enough yeah

gusty gazelle
#

Bandaid First, then a Jira ticket for tech-debt cleanup

#

Man.. It's like.. I'm at my day job

#

;P

pine forge