function DebugPrint(args) if Config.DebugDisplay then print(args) end end function firstToUpper(str) return (str:gsub("^%l", string.upper)) end function ShowNotification(text) if Config.NotificationsAsChatMessage then TriggerEvent("chat:addMessage", { color = { 255, 255, 255 }, args = { tostring(text) } }) else BeginTextCommandThefeedPost("STRING") AddTextComponentSubstringPlayerName(text) EndTextCommandThefeedPostTicker(false, false) end end function IsPlayerAiming(player) return IsPlayerFreeAiming(player) or IsAimCamActive() or IsAimCamThirdPersonActive() end function CanPlayerCrouchCrawl(playerPed) if not IsPedOnFoot(playerPed) or IsPedJumping(playerPed) or IsPedFalling(playerPed) or IsPedInjured(playerPed) or IsPedInMeleeCombat(playerPed) or IsPedRagdoll(playerPed) then return false end return true end function PlayAnimOnce(playerPed, animDict, animName, blendInSpeed, blendOutSpeed, duration, startTime) LoadAnim(animDict) TaskPlayAnim(playerPed, animDict, animName, blendInSpeed or 2.0, blendOutSpeed or 2.0, duration or -1, 0, startTime or 0.0, false, false, false) RemoveAnimDict(animDict) end function ChangeHeadingSmooth(playerPed, amount, time) local times = math.abs(amount) local test = amount / times local wait = time / times for _i = 1, times do Wait(wait) SetEntityHeading(playerPed, GetEntityHeading(playerPed) + test) end end function EmoteChatMessage(msg, multiline) if msg then TriggerEvent("chat:addMessage", { multiline = multiline == true or false, color = { 255, 255, 255 }, args = { "^1Help^0", tostring(msg) } }) end end function pairsByKeys(t, f) local a = {} for n in pairs(t) do table.insert(a, n) end table.sort(a, f) local i = 0 -- iterator variable local iter = function() -- iterator function i = i + 1 if a[i] == nil then return nil else return a[i], t[a[i]] end end return iter end function LoadAnim(dict) if not DoesAnimDictExist(dict) then return false end local timeout = 2000 while not HasAnimDictLoaded(dict) and timeout > 0 do RequestAnimDict(dict) Wait(5) timeout = timeout - 5 end if timeout == 0 then DebugPrint("Loading anim dict " .. dict .. " timed out") return false else return true end end function LoadPropDict(model) -- load the model if it's not loaded and wait until it's loaded or timeout if not HasModelLoaded(joaat(model)) then RequestModel(joaat(model)) local timeout = 2000 while not HasModelLoaded(joaat(model)) and timeout > 0 do Wait(5) timeout = timeout - 5 end if timeout == 0 then DebugPrint("Loading model " .. model .. " timed out") return end end end function tableHasKey(table, key) return table[key] ~= nil end function RequestWalking(set) local timeout = GetGameTimer() + 5000 while not HasAnimSetLoaded(set) and GetGameTimer() < timeout do RequestAnimSet(set) Wait(5) end end function GetPedInFront() local player = PlayerId() local plyPed = GetPlayerPed(player) local plyPos = GetEntityCoords(plyPed, false) local plyOffset = GetOffsetFromEntityInWorldCoords(plyPed, 0.0, 1.3, 0.0) local rayHandle = StartShapeTestCapsule(plyPos.x, plyPos.y, plyPos.z, plyOffset.x, plyOffset.y, plyOffset.z, 10.0, 12 , plyPed, 7) local _, _, _, _, ped2 = GetShapeTestResult(rayHandle) return ped2 end function NearbysOnCommand(source, args, raw) local NearbysCommand = "" for a in pairsByKeys(RP.Shared) do NearbysCommand = NearbysCommand .. "" .. a .. ", " end EmoteChatMessage(NearbysCommand) EmoteChatMessage(Config.Languages[lang]['emotemenucmd']) end function SimpleNotify(message) if Config.NotificationsAsChatMessage then TriggerEvent("chat:addMessage", { color = { 255, 255, 255 }, args = { tostring(message) } }) else BeginTextCommandThefeedPost("STRING") AddTextComponentSubstringPlayerName(message) EndTextCommandThefeedPostTicker(0, 1) end end function GetClosestPlayer() local players = GetPlayers() local closestDistance = -1 local closestPlayer = -1 local ply = PlayerPedId() local plyCoords = GetEntityCoords(ply, 0) for index, value in ipairs(players) do local target = GetPlayerPed(value) if (target ~= ply) then local targetCoords = GetEntityCoords(GetPlayerPed(value), 0) local distance = GetDistanceBetweenCoords(targetCoords["x"], targetCoords["y"], targetCoords["z"], plyCoords["x"], plyCoords["y"], plyCoords["z"], true) if (closestDistance == -1 or closestDistance > distance) then closestPlayer = value closestDistance = distance end end end return closestPlayer, closestDistance end function GetPlayers() local players = {} for i = 0, 255 do if NetworkIsPlayerActive(i) then table.insert(players, i) end end return players end