So hi, im trying to work out how i would make a command only available for users with the Police job, ive done alot of googling and scouring but i carnt seem to find anything which works for my case, ive tried adding it directly to the function which is ran when the command is ran, but it didnt work nor when i added it to the Event Handler. The function id like to add it to is
function giveWeapon(hash)
GiveWeaponToPed(GetPlayerPed(-1), GetHashKey(hash), 100, false, true)
end
any help would be greatly appriciated, im not the best with lua so some visual examples, code examples would be greatly appreciated! Thank you.
This is the command for unracking weapons, is there anything i need to predefine etc or no?
AddEventHandler('unrack', function(userName, args)
local player = GetPlayerPed(-1)
if RequireInVehicleToUnrack == true then
if IsPedInAnyVehicle(player, true) then
if args[1] == "1" and weaponTaken == false then
GiveAR(userName)
elseif args[1] == "2" and weaponTaken == false then
giveShotgun(userName)
elseif args[1] == nil and weaponTaken == false then
notify("~r~Please specify a weapon type. /unrack 1 or 2 (1 = Carbine Rifle, 2 = Shotgun)")
elseif weaponTaken == true then
notify("~r~You already have a weapon unracked.")
end
else
notify('~r~You must be in a vehicle to unrack your weapon.')
end
else
if args[1] == "1" and weaponTaken == false then
giveShotgun(userName)
elseif args[1] == nil and weaponTaken == false then
notify("~r~Please specify a weapon type. /unrack 1 or 2 (1 = Carbine Rifle, 2 = Shotgun)")
elseif weaponTaken == true then
notify("~r~You already have a weapon unracked.")
end
end
end)
This is the error im getting when i have it checking if the user is police like this
RegisterCommand("loadout", function ()
if xPlayer.job.name == police then
RemoveAllPedWeapons(GetPlayerPed(-1), true)
giveWeapon("weapon_combatpistol")
weaponComponent("weapon_combatpistol", "COMPONENT_AT_PI_FLSH")
giveWeapon("weapon_flashlight")
giveWeapon("weapon_nightstick")
giveWeapon("weapon_stungun")
AddArmourToPed(GetPlayerPed(-1), 100)
notify("~b~Police loadout has been loaded.")
notify("~r~To receive a rifle or shotgun, you must type /unrack by a police vehicle.")
else
notify("~b~You are not Police.")
Citizen.Wait(0)
end
end)