qbcore-framework / qb-anticheat

Anticheat System For QB-Core
GNU General Public License v3.0
30 stars 116 forks source link

Qb-anticheat weapon information error #31

Closed Adrianmcmastergaming closed 2 years ago

Adrianmcmastergaming commented 2 years ago

Hi, I have an error that keeps cropping up on the client-side of the anticheat as displayed in the screenshot. I read throw the script but do not understand why the error appears,

This is what is in the client file from lines 173 to 183. Is it trying to flag players with weapons? My job is set as police and I have police weapons so should not be flagging me. I do not understand what is going on or how to fix the error.

        if WeaponInformation["name"] ~= "weapon_unarmed" then
            QBCore.Functions.TriggerCallback('qb-anticheat:server:HasWeaponInInventory', function(HasWeapon)
                if not HasWeapon then
                    RemoveAllPedWeapons(PlayerPed, false)
                    TriggerServerEvent("qb-log:server:CreateLog", "anticheat", "Weapon removed!", "orange", "** @everyone " ..GetPlayerName(player).. "** had a weapon on them that they did not have in his inventory. QB Anticheat has removed the weapon.")
                end
            end, WeaponInformation)
        end
    end
end

end)

anti

rhapidfyre commented 2 years ago

I have the same error occurring as well. Seems to be caused due to not checking if QBCore.Shared.Weapons[index] is nil or not. Since QBCore.Shared.Weapons is a table and not a function, giving it an index that doesn't exist (i.e if CurrentWeapon is zero or doesn't exist in the table) causes the variable to be nil, which results in WeaponInformation being a nil value, instead of a table.

To fix, simply add:

if WeaponInformation then

end

around line 173.

However, this is probably not the correct usage. If the client is reporting a weapon not in the QBCore Shared Weapons table, it needs to be handled properly... But it stops the error, which is important. If this error occurs, it stops the weapon checking loop altogether, resulting in the weapon anticheat not functioning.