### Manage Player Handcuff States with Lua State Bags Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt This snippet demonstrates how to access and manipulate player state bag properties in Lua for managing handcuff status, dragging, and inventory searching. It includes an example of checking if a player is handcuffed before allowing an action and server-side initialization of these states when the resource starts. Dependencies include ESX and FiveM's state bag system. ```lua -- Available state bag properties for each player: -- Player(serverId).state.klamer_PlayerIsCuffed - Is player handcuffed -- Player(serverId).state.klamer_PlayerIsDragged - Is player being escorted -- Player(serverId).state.klamer_PlayerDraggingSomeone - Is player escorting someone -- Player(serverId).state.klamer_HaveOpenedInventory - Is player's inventory being searched -- Player(serverId).state.klamer_IsPlayerSearchingInventory - Target ID being searched -- Player(serverId).state.klamer_isDead - Is player dead -- Example: Check if player is handcuffed before allowing action if Player(target).state.klamer_PlayerIsCuffed then -- Player is cuffed, allow search TriggerServerEvent("klamer_handcuffs:searchInventory", target) else klamer_notify("You can only search a handcuffed player") end -- Server-side state initialization on resource start CreateThread(function() for k, v in pairs(ESX.GetPlayers()) do Player(v).state.klamer_PlayerIsCuffed = false Player(v).state.klamer_HaveOpenedInventory = false Player(v).state.klamer_PlayerIsDragged = false Player(v).state.klamer_PlayerDraggingSomeone = false end end) ``` -------------------------------- ### Configuration for KL4M3R Handcuffs Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt The Config.lua file allows server administrators to customize handcuff behavior, notification systems, and required items. This includes enabling/disabling the hands-up requirement, setting key bindings, choosing a notification system, blocking vehicle interactions, and defining required items for handcuffing and lockpicking. ```lua Config = {} -- Enable/disable hands-up requirement before cuffing Config.HandsUp = true -- true/false -- Key binding for hands-up gesture (default: ~ key) Config.HandsUp_key = 'GRAVE' -- https://docs.fivem.net/docs/game-references/input-mapper-parameter-ids/keyboard/ -- Notification system: 'okokNotify' or 'ox_lib' Config.Notify = 'ox_lib' -- Block vehicle entry/exit when handcuffed Config.disable_vehicle = true -- Required items for handcuff interactions Config.req_items = { ['lockpick'] = 'lockpick', ['handcuff'] = 'handcuffs', } ``` -------------------------------- ### Attach Player Client Event Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Handles the client-side action of attaching a player ped to another player's ped for dragging. It freezes the dragged player's position and uses AttachEntityToEntity to create the visual connection. ```lua -- Client Event: Attach player to escort RegisterNetEvent("klamer_handcuffs:dragMe", function(cop) local playerPed = PlayerPedId() FreezeEntityPosition(playerPed, true) AttachEntityToEntity(playerPed, GetPlayerPed(GetPlayerFromServerId(cop)), 11816, 0.54, 0.54, 0.0, 0.0, 0.0, 0.0, false, false, false, false, 2, true) end) ``` -------------------------------- ### Custom Notification System (Lua) Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt A client-side notification function that acts as a wrapper for multiple notification resources like ox_lib and okokNotify. It allows for a unified way to display notifications with customizable titles, text, duration, and types. Includes placeholder for custom notification exports. ```lua -- Client-side notification function -- Supports ox_lib and okokNotify, with custom notification hook function klamer_notify(title, text, time, type) if not text then text = '' end if not time then time = 2500 end if not type then type = 'info' end if Config.Notify == 'okokNotify' then exports['okokNotify']:Alert(title, text, time, type) elseif Config.Notify == 'ox_lib' then lib.notify({title = title, description = text, type = type}) else -- Custom notification placeholder -- Add your notification export here end end -- Usage examples: klamer_notify("Handcuffed", "You have been handcuffed", 3000, "warning") klamer_notify("Search", "You are being searched", 2500, "info") klamer_notify("Error", "You can't do that", 2000, "error") ``` -------------------------------- ### Uncuff Player Client Event with Lockpick (ox_lib) Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Implements the client-side logic for uncuffing a player using a lockpick, incorporating an ox_lib skill check. It verifies if the target is cuffed, performs a skill check, and if successful, triggers the server event to uncuff. On failure, there's a chance to break the lockpick. ```lua -- Client Event: Lockpick uncuff with skill check (ox_lib) -- From qtarget action for "uncuff (lockpick)" option action = function(entity) local playerPed = PlayerPedId() local isCuffed = Player(GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity))).state.klamer_PlayerIsCuffed if isCuffed then -- ox_lib skill check: medium, medium, hard difficulty local success = lib.skillCheck({'medium', 'medium', 'hard'}, {'w', 'a', 's', 'd'}) if success then local playerheading = GetEntityHeading(playerPed) local playerlocation = GetEntityForwardVector(playerPed) local coords = GetEntityCoords(playerPed) TriggerServerEvent("klamer_handcuffs:uncuffPlayer", GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity)), playerheading, coords, playerlocation) else -- 50% chance to break the lockpick on failure if math.random(1, 2) == 1 then klamer_notify("You broke the lockpick") TriggerServerEvent("klamer_handcuffs:lockpickDelete") end end end end ``` -------------------------------- ### Search Player Inventory (Lua) Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Server-side event to open a target player's inventory for searching. It checks if the searching player is handcuffed, verifies the distance to the target, and then triggers a client event to open the ox_inventory. Requires ox_inventory. ```lua -- Server Event: klamer_handcuffs:searchInventory -- Opens target player's inventory for searching RegisterNetEvent("klamer_handcuffs:searchInventory", function(target) local player = source if Player(player).state.klamer_PlayerIsCuffed then TriggerClientEvent('klamer_notify_handcuff', player, "You can't search while you're handcuffed") return end local targetCoords = GetEntityCoords(GetPlayerPed(target)) local localCoords = GetEntityCoords(GetPlayerPed(player)) local distance = #(targetCoords - localCoords) if distance > 6.0 then TriggerClientEvent('klamer_notify_handcuff', player, "This person is too far away!") return end Player(target).state.klamer_HaveOpenedInventory = true Player(source).state.klamer_IsPlayerSearchingInventory = target TriggerClientEvent("klamer_handcuffs:getInventory", player, target) end) -- Client Event: Open ox_inventory for target player RegisterNetEvent("klamer_handcuffs:getInventory", function(target) exports["ox_inventory"]:openInventory("player", target) end) ``` -------------------------------- ### Drag Player Server Event Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Manages the server-side logic for initiating the dragging of a handcuffed player. It checks the distance between players and if the target is already being dragged, then updates player states and triggers a client event to visually attach the players. ```lua -- Server Event: klamer_handcuffs:dragPlayer -- Attaches cuffed player to the escorting player RegisterNetEvent("klamer_handcuffs:dragPlayer", function(target) local player = source local targetCoords = GetEntityCoords(GetPlayerPed(target)) local localCoords = GetEntityCoords(GetPlayerPed(player)) local dist = #(targetCoords - localCoords) if dist > 10.0 then TriggerClientEvent('klamer_notify_handcuff', player, "You are too far away!") return end if Player(target).state.klamer_PlayerIsDragged then TriggerClientEvent('klamer_notify_handcuff', player, "The player is already being transferred!") return end Player(target).state.klamer_PlayerIsDragged = true Player(player).state.klamer_PlayerDraggingSomeone = true TriggerClientEvent("klamer_handcuffs:dragMe", target, player) end) ``` -------------------------------- ### Hands Up Command and Keybind Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Registers a command '_handsup' that allows players to raise or lower their hands, playing corresponding animations. This functionality is conditional on 'Config.HandsUp' and can be bound to a configurable key using RegisterKeyMapping. ```lua -- Register hands-up command with configurable key mapping if Config.HandsUp then RegisterCommand('_handsup', function() if can_use then if hand_up == false then can_use = false local dict = 'random@mugging3' RequestAnimDict(dict) while not HasAnimDictLoaded(dict) do Citizen.Wait(10) end TaskPlayAnim(PlayerPedId(), dict, 'handsup_standing_base', 8.0, -8, .01, 49, 0, 0, 0, 0) hand_up = true Citizen.Wait(1000) can_use = true else can_use = false hand_up = false ClearPedTasks(PlayerPedId()) Citizen.Wait(1000) can_use = true end end end) -- Bind to configured key (default: GRAVE/~) RegisterKeyMapping("_handsup", "raise your hand", "keyboard", Config.HandsUp_key) end ``` -------------------------------- ### Vehicle Management for Handcuffed Players (Lua) Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Handles placing handcuffed players into vehicles and removing them. Includes server-side events to manage the process and client-side logic for finding suitable vehicles and seats. It checks distances, vehicle lock status, and seat availability. ```lua -- Server Event: klamer_handcuffs:setPedIntoVehicle -- Places cuffed player into nearest vehicle RegisterNetEvent("klamer_handcuffs:setPedIntoVehicle", function(target, vehicle, seat) local player = source local coords = GetEntityCoords(GetPlayerPed(player)) local targetCoords = GetEntityCoords(GetPlayerPed(target)) local dist = #(coords - targetCoords) if dist > 10.0 then TriggerClientEvent('klamer_notify_handcuff', player, "The player is too far away") return end TriggerClientEvent("klamer_handcuffs:setMeInVehicle", target, vehicle, seat) end) -- Client-side vehicle placement logic action = function(entity) local playerPed = PlayerPedId() local cuffed = Player(GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity))).state.klamer_PlayerIsCuffed if cuffed then local vehicle, distance = ESX.Game.GetClosestVehicle(GetEntityCoords(PlayerPedId())) if GetVehicleDoorLockStatus(vehicle) == 4 then klamer_notify("This vehicle is closed!") return end if not DoesEntityExist(vehicle) or distance > 6.0 then return end if not AreAnyVehicleSeatsFree(vehicle) then klamer_notify("There is no room in this vehicle") return end local seats = GetVehicleModelNumberOfSeats(GetEntityModel(vehicle)) if seats == 4 then for i = 1, 2 do if IsVehicleSeatFree(vehicle, i) then TriggerServerEvent("klamer_handcuffs:setPedIntoVehicle", GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity)), tostring(vehicle), i) return end end end end end -- Remove player from vehicle RegisterNetEvent("klamer_handcuffs:getPedFromVehicle", function(target) local player = source local dist = #(GetEntityCoords(GetPlayerPed(player)) - GetEntityCoords(GetPlayerPed(target))) if dist > 10.0 then return end TriggerClientEvent("klamer_handcuffs:leaveVehicle", target) end) ``` -------------------------------- ### Server-side Handcuffing Logic Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt This server-side event handles the logic for cuffing a player. It performs validation checks such as distance, player cuffed status, and then sets the target player's cuffed state and triggers client-side events for animations and state updates. ```lua -- Server Event: klamer_handcuffs:cuffPlayer -- Triggered when a player attempts to handcuff another player -- Parameters: target (server ID), playerheading, coords, playerlocation RegisterNetEvent("klamer_handcuffs:cuffPlayer", function(target, playerheading, coords, playerlocation) local player = source local xPlayer = ESX.GetPlayerFromId(player) local targetPed = GetPlayerPed(target) -- Validation checks if not DoesEntityExist(targetPed) then return end local targetCoords = GetEntityCoords(targetPed) local localCoords = GetEntityCoords(GetPlayerPed(player)) local distance = #(targetCoords - localCoords) if distance > 3.0 then return end -- Must be within 3 meters if Player(player).state.klamer_PlayerIsCuffed then return end -- Can't cuff while cuffed if Player(target).state.klamer_PlayerIsCuffed then return end -- Target already cuffed -- Set cuffed state and trigger animations Player(target).state.klamer_PlayerIsCuffed = true TriggerClientEvent("klamer_handcuffs:cuffMe", target, playerheading, coords, playerlocation) TriggerClientEvent("klamer_handcuffs:cuffHim", player, true) end) ``` -------------------------------- ### Client-side Handcuffing Interaction Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt This client-side event handler is triggered by a target menu interaction to initiate the handcuffing process. It checks if the target player has their hands up (if configured) before sending a server event to perform the cuff action. It also includes a notification for when the target doesn't have their hands up. ```lua -- Client-side trigger example (from target menu interaction) AddEventHandler("zakajdankuj", function(entity) local playerPed = PlayerPedId() local entity = entity.entity if Config.HandsUp then -- Check if target has hands up if IsEntityPlayingAnim(entity, "random@mugging3", "handsup_standing_base", 3) then local playerheading = GetEntityHeading(playerPed) local playerlocation = GetEntityForwardVector(playerPed) local coords = GetEntityCoords(playerPed) TriggerServerEvent("klamer_handcuffs:cuffPlayer", GetPlayerServerId(NetworkGetPlayerIndexFromPed(entity)), playerheading, coords, playerlocation) else klamer_notify('The person must raise their hands!') end end end) ``` -------------------------------- ### Un-Drag Player Server Event Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Manages the server-side logic for releasing a dragged player. It resets the 'klamer_PlayerIsDragged' and 'klamer_PlayerDraggingSomeone' states and triggers a client event to visually detach the players. ```lua -- Release escorted player RegisterNetEvent("klamer_handcuffs:unDragPlayer", function(target) local player = source Player(target).state.klamer_PlayerIsDragged = false Player(player).state.klamer_PlayerDraggingSomeone = false TriggerClientEvent("klamer_handcuffs:unDrag", target) end) ``` -------------------------------- ### Uncuff Player Server Event Source: https://context7.com/kl4m3r/klamer_handcuffs/llms.txt Handles the server-side logic for removing handcuffs from a target player. It checks if the target is actually cuffed and prevents the action if the source player is also cuffed. It then updates the player's state and triggers client events to visually uncuff the players. ```lua -- Server Event: klamer_handcuffs:uncuffPlayer -- Removes handcuffs from target player with proper animations RegisterNetEvent("klamer_handcuffs:uncuffPlayer", function(target, playerheading, coords, playerlocation) local player = source if Player(player).state.klamer_PlayerIsCuffed then return end -- Can't uncuff while cuffed if not Player(target).state.klamer_PlayerIsCuffed then return end -- Target not cuffed Player(target).state.klamer_PlayerIsCuffed = false TriggerClientEvent("klamer_handcuffs:uncuffMe", target, playerheading, coords, playerlocation) TriggerClientEvent("klamer_handcuffs:uncuffHim", player) end) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.