[RELEASE] Unrack and Rack simple reply script

RegisterCommand(“unrack”, function(source, args, rawCommand)

local vehicle = GetVehiclePedIsIn(GetPlayerPed(1), true)
local class = GetVehicleClass(vehicle)

if( class == 18) then

  GiveWeaponToPed(GetPlayerPed(1), "WEAPON_CARBINERIFLE", 1000, true, true)

end
end)

RegisterCommand(“rack”, function(source, args, rawCommand)

local vehicle = GetVehiclePedIsIn(GetPlayerPed(-1), true)
local class = GetVehicleClass(vehicle)

if( class == 18) then

  GiveWeaponToPed(GetPlayerPed(-1), "WEAPON_CARBINERIFLE", 1000, false, false)

end
end)

@Woopi

Show me the error your getting please

@Lukepollie

Error running call reference function for resource rack_unrack: citizen:/scripting/lua/scheduler.lua:379: server.lua:3: attempt to call a nil value (global ‘GetVehiclePedIsIn’)
stack traceback:
server.lua:3: in upvalue ‘ref’
citizen:/scripting/lua/scheduler.lua:365: in function citizen:/scripting/lua/scheduler.lua:364
[C]: in function ‘xpcall’
citizen:/scripting/lua/scheduler.lua:364: in function citizen:/scripting/lua/scheduler.lua:363
stack traceback:
[C]: in function ‘error’
citizen:/scriptinError running call reference function for resource rack_unrack: citizen:/scripting/lua/scheduler.lua:379: server.lua:3: attempt to call a nil value (global ‘GetVehiclePedIsIn’)
stack traceback:
server.lua:3: in upvalue ‘ref’
citizen:/scripting/lua/scheduler.lua:365: in function citizen:/scripting/lua/scheduler.lua:364
[C]: in function ‘xpcall’
citizen:/scripting/lua/scheduler.lua:364: in function citizen:/scripting/lua/scheduler.lua:363
stack traceback:
[C]: in function ‘error’
citizen:/scripting/lua/scheduler.lua:379: in function citizen:/scripting/lua/scheduler.lua:348g/lua/scheduler.lua:379: in function citizen:/scripting/lua/scheduler.lua:348

Okay, blame on @Woopi for changing the script without testing it. Not my issue anymore

That looks to me you are using the GetVehiclePedIsIn server sided, you need to use it client sided.

Also, I really wouldn’t bother using the class, if you wanna restrict just base it off the players skin or identifier through a function and a table.

If you wanna add this into a proximity try this

Client

RegisterNetEvent('proxUnrack')
AddEventHandler('proxUnrack', function(id, name)
  local ID = PlayerId()
  local plyID = GetPlayerFromServerId(id)
    if plyID == ID then
      TriggerEvent('chatMessage', "", {255, 255, 255}, " ^*".. name .. " Unracks ^1M4 ".." ")
    elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(ID)), GetEntityCoords(GetPlayerPed(plyID)), true) < 49.999 then
      TriggerEvent('chatMessage', "", {255, 255, 255}, " ^*".. name .. " Unracks ^1M4 ".." ")
    end
end)

RegisterNetEvent('proxRack')
AddEventHandler('proxRack', function(id, name)
  local ID = PlayerId()
  local plyID = GetPlayerFromServerId(id)
    if plyID == ID then
      TriggerEvent('chatMessage', "", {255, 255, 255}, " ^*".. name .. " Racks ^1M4 ".." ")
    elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(ID)), GetEntityCoords(GetPlayerPed(plyID)), true) < 49.999 then
      TriggerEvent('chatMessage', "", {255, 255, 255}, " ^*".. name .. " Racks ^1M4 ".." ")
    end
end)

Server

RegisterCommand('unrack', function(source, args, user)
    local name = GetPlayerName(source)
    TriggerClientEvent("proxUnrack", -1, source, name)
end, false)

RegisterCommand('rack', function(source, args, user)
    local name = GetPlayerName(source)
    TriggerClientEvent("proxRack", -1, source, name)
end, false)

Untested but just an idea.

Appriciate it
Thank you
this will help alot

BUMB

The Script now will give you the weapons + message is server side.
This will be the last version.

(not gonna do this for the civ version cause that makes no sense, just change the text message)

Yeah unfortunately it doesnt just remove the rifle for me but my whole inventory, not only that but also when someone stands *next to my cruiser and I rack mine, it also gets rid of all of his inventory.

*-edit; next meaning up to at least 30 meters actually

Any way I would be able to make this like a toggle. So when I press a key it racks the ar and when I press it again it unracks it

yeh just change the script to to a keybind instead of a chat command

I tried to edit the client.cfg to just remove the rifle instead of my whole inventory and it still removes my whole inventory any help?

RegisterNetEvent('proxRack')
AddEventHandler('proxRack', function(id, name)
  local ID = PlayerId()
  local plyID = GetPlayerFromServerId(id)
    if plyID == ID then
      TriggerEvent('chatMessage', "^4OFFICER", {255, 255, 255}, "^*".. name .. " RACKS ^8RIFLE ^7BACK INTO CRUISER ! ")
      RemovePedWeapon(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), 1000, false)
    elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(ID)), GetEntityCoords(GetPlayerPed(plyID)), true) < 49.999 then
      TriggerEvent('chatMessage', "^4OFFICER", {255, 255, 255}, " ^*".. name .. " RACKS ^8RIFLE ^7BACK INTO CRUISER ! ")
      RemovePedWeapon(GetPlayerPed(-1), GetHashKey("WEAPON_CARBINERIFLE"), 1000, false)
    end
end)

i am getting the error that it couldn’t load the __resource.lua