### Registering qb-spawn Client Setup Event Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation This Lua code registers a network event 'qb-spawn:client:setupSpawns' on the client. It handles the setup of player spawns, fetches owned houses via a server callback, and sends NUI messages to update the game interface based on whether the player is new or has existing properties. ```lua RegisterNetEvent('qb-spawn:client:setupSpawns', function(cData, new, apps) if not new then QBCore.Functions.TriggerCallback('qb-spawn:server:getOwnedHouses', function(houses) local myHouses = {} if houses ~= nil then for i = 1, (#houses), 1 do local house = houses[i] myHouses[#myHouses+1] = { house = house, label = (house.apartment or house.street) .. " " .. house.property_id, } end end Wait(500) SendNUIMessage({ action = "setupLocations", locations = QB.Spawns, houses = myHouses, isNew = new }) end, cData.citizenid) elseif new then SendNUIMessage({ action = "setupAppartements", locations = apps, isNew = new }) end end) ``` -------------------------------- ### Configure qb-multicharacter Character Creation (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Modifies the `qb-multicharacter:server:createCharacter` event in `server/main.lua` to handle new character creation. It logs the player in with new data, waits for preloading, closes the NUI, triggers client events for housing setup, and provides starter items. ```lua RegisterNetEvent('qb-multicharacter:server:createCharacter', function(data) local src = source local newData = {} newData.cid = data.cid newData.charinfo = data if QBCore.Player.Login(src, false, newData) then repeat Wait(10) until hasDonePreloading[src] print('^2[qb-core]^7 '..GetPlayerName(src)..' has succesfully loaded!') QBCore.Commands.Refresh(src) TriggerClientEvent("qb-multicharacter:client:closeNUI", src) newData.citizenid = QBCore.Functions.GetPlayer(src).PlayerData.citizenid TriggerClientEvent('ps-housing:client:setupSpawnUI', src, newData) GiveStarterItems(src) end end) ``` -------------------------------- ### Configure qb-multicharacter User Data Loading (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Modifies the `qb-multicharacter:server:loadUserData` event in `server/main.lua` to handle user data loading. It checks player login status, waits for preloading, prints a success message, refreshes commands, and triggers client events for housing setup and logging. ```lua RegisterNetEvent('qb-multicharacter:server:loadUserData', function(cData) local src = source if QBCore.Player.Login(src, cData.citizenid) then repeat Wait(10) until hasDonePreloading[src] print('^2[qb-core]^7 '..GetPlayerName(src)..' (Citizen ID: '..cData.citizenid..') has succesfully loaded!') QBCore.Commands.Refresh(src) TriggerClientEvent('ps-housing:client:setupSpawnUI', src, cData) TriggerEvent("qb-log:server:CreateLog", "joinleave", "Loaded", "green", "**".. GetPlayerName(src) .. "** (<@"..(QBCore.Functions.GetIdentifier(src, 'discord'):gsub("discord:", "") or "unknown").."> | ||" ..(QBCore.Functions.GetIdentifier(src, 'ip') or 'undefined') .. "|| | " ..(QBCore.Functions.GetIdentifier(src, 'license') or 'undefined') .." | " ..cData.citizenid.." | "..src..") loaded..") end end) ``` -------------------------------- ### Modify qb-smallresources/client/ignore.lua Source: https://docs.projectsloth.org/ps/scripts/ps-fuel/installation-guide This snippet provides the Lua code to be pasted into `qb-smallresources/client/ignore.lua`. It's part of the ps-fuel installation process and may involve replacing existing lines to ensure compatibility. ```lua TriggerServerEvent("weapons:server:UpdateWeaponAmmo", CurrentWeaponData, tonumber(ammo)) ``` -------------------------------- ### Configure Discord Webhook for ps-housing Logs Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Adds a configuration line to `qb-smallresources/server/logs.lua` to enable logging for ps-housing events to a specified Discord webhook. Replace 'yourdiscordwebhookhere' with the actual webhook URL. This system currently only supports qb-core. ```lua ['pshousing'] = 'yourdiscordwebhookhere', ``` -------------------------------- ### Modify qb-garages Ownership Check to Use ps-housing Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Replaces the qb-houses ownership check with ps-housing's IsOwner function in the qb-garages server script. This change is necessary for compatibility between the two systems. Ensure ps-housing is installed and configured. ```lua local hasHouseKey = exports['ps-housing']:IsOwner(src, house) ``` -------------------------------- ### Set Item Limits in ps-housing Configuration Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Example of how to set item limits within the `Config.Furniture` section of `shared/config.lua` for ps-housing. By adding `["max"] = value`, you can restrict the number of specific furniture items a player can own. ```lua { ["object"] = "v_res_r_figcat", ["price"] = 300, ["max"] = 2, ["label"] = "Fig Cat" }, ``` -------------------------------- ### Modify qb-weapons/client/main.lua for Weapon Ammo Update Source: https://docs.projectsloth.org/ps/scripts/ps-fuel/installation-guide This Lua snippet is intended for `qb-weapons/client/main.lua` and handles the updating of weapon ammo and quality. It includes logic for specific weapons like the 'WEAPON_PETROLCAN' and triggers server events for data synchronization. ```lua CreateThread(function() while true do local ped = PlayerPedId() local idle = 1 if (IsPedArmed(ped, 7) == 1 and (IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24))) or IsPedShooting(PlayerPedId()) then local weapon = GetSelectedPedWeapon(ped) local ammo = GetAmmoInPedWeapon(ped, weapon) if weapon == GetHashKey("WEAPON_PETROLCAN") then idle = 1000 end TriggerServerEvent("weapons:server:UpdateWeaponAmmo", CurrentWeaponData, tonumber(ammo)) if MultiplierAmount > 0 then TriggerServerEvent("weapons:server:UpdateWeaponQuality", CurrentWeaponData, MultiplierAmount) MultiplierAmount = 0 end end Wait(idle) end end) ``` -------------------------------- ### Implementing Server Callback for Owned Houses Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation This Lua code defines a server-side callback function 'qb-spawn:server:getOwnedHouses'. It queries the MySQL database for properties owned by a given citizen ID and returns the results to the client. If no houses are found, it returns an empty table. ```lua QBCore.Functions.CreateCallback('qb-spawn:server:getOwnedHouses', function(_, cb, cid) if cid ~= nil then local houses = MySQL.query.await('SELECT * FROM properties WHERE owner_citizenid = ?', {cid}) if houses[1] ~= nil then cb(houses) else cb({}) end else cb({}) end end) ``` -------------------------------- ### Handling Apartment Choice via NUI Callback Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation This Lua code defines a NUI callback named 'chooseAppa'. When triggered by the UI, it handles the logic for choosing an apartment, including fading the screen, freezing player position, destroying cameras, and initiating the creation of a new apartment on the server. ```lua RegisterNUICallback('chooseAppa', function(data, cb) local ped = PlayerPedId() local appaYeet = data.appType SetDisplay(false) DoScreenFadeOut(500) Wait(100) FreezeEntityPosition(ped, false) RenderScriptCams(false, true, 0, true, true) SetCamActive(cam, false) DestroyCam(cam, true) SetCamActive(cam2, false) DestroyCam(cam2, true) SetEntityVisible(ped, true) Wait(500) TriggerServerEvent('QBCore:Server:OnPlayerLoaded') TriggerEvent('QBCore:Client:OnPlayerLoaded') Wait(100) TriggerServerEvent("ps-housing:server:createNewApartment", appaYeet) cb('ok') end) ``` -------------------------------- ### Processing Player Spawn Selection via NUI Callback Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation This Lua code implements the 'spawnplayer' NUI callback. It manages different spawn types ('current', 'house', 'normal'), updates player coordinates and heading, triggers server events for player loading and property entry, and calls helper functions 'PreSpawnPlayer' and 'PostSpawnPlayer'. ```lua RegisterNUICallback('spawnplayer', function(data, cb) local location = tostring(data.spawnloc) local type = tostring(data.typeLoc) local ped = PlayerPedId() local PlayerData = QBCore.Functions.GetPlayerData() local insideMeta = PlayerData.metadata["inside"] if type == "current" then PreSpawnPlayer() QBCore.Functions.GetPlayerData(function(pd) ped = PlayerPedId() SetEntityCoords(ped, pd.position.x, pd.position.y, pd.position.z) SetEntityHeading(ped, pd.position.a) FreezeEntityPosition(ped, false) end) TriggerServerEvent('QBCore:Server:OnPlayerLoaded') TriggerEvent('QBCore:Client:OnPlayerLoaded') if insideMeta.property_id ~= nil then local property_id = insideMeta.property_id TriggerServerEvent('ps-housing:server:enterProperty', tostring(property_id)) end PostSpawnPlayer() elseif type == "house" then PreSpawnPlayer() TriggerServerEvent('QBCore:Server:OnPlayerLoaded') TriggerEvent('QBCore:Client:OnPlayerLoaded') local property_id = data.spawnloc.property_id TriggerServerEvent('ps-housing:server:enterProperty', tostring(property_id)) PostSpawnPlayer() elseif type == "normal" then local pos = QB.Spawns[location].coords PreSpawnPlayer() SetEntityCoords(ped, pos.x, pos.y, pos.z) TriggerServerEvent('QBCore:Server:OnPlayerLoaded') TriggerEvent('QBCore:Client:OnPlayerLoaded') TriggerServerEvent('ps-housing:server:resetMetaData') SetEntityCoords(ped, pos.x, pos.y, pos.z) SetEntityHeading(ped, pos.w) PostSpawnPlayer() end cb('ok') end) ``` -------------------------------- ### Configure Roles and Card Settings in Lua Source: https://docs.projectsloth.org/ps/scripts/ps-discord/installation This snippet refers to the configuration of roles and card display within the Lua files 'queue/roles.lua' and 'queue/card.lua'. These files allow for customization of how roles and user cards are displayed and managed by the ps-discord resource. ```lua -- queue/roles.lua configuration example -- ... -- queue/card.lua configuration example -- ... ``` -------------------------------- ### Update qb-garages V2 House Ownership Check for ps-housing Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Modifies the ownership check within qb-garages V2 for house types to utilize the ps-housing system. This replaces the older qb-houses dependency with the new ps-housing integration, ensuring correct owner verification for house garages. ```lua if type == 'house' and not exports['ps-housing']:IsOwner(source, garage) then ``` -------------------------------- ### Add Garage Removal Event for qb-garages V2 Client Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Adds an event handler to the qb-garages V2 client script for removing garages. This ensures that client-side garage configurations are cleaned up properly when garages are removed, maintaining data integrity. This is associated with the ps-housing integration. ```lua RegisterNetEvent('qb-garages:client:removeHouseGarage', function(house) Config.Garages[house] = nil end ``` -------------------------------- ### Modify qb-inventory/client/main.lua for Fire Extinguisher Ammo Source: https://docs.projectsloth.org/ps/scripts/ps-fuel/installation-guide This code modifies the `qb-inventory/client/main.lua` file to set the ammo for the 'weapon_fireextinguisher' to 4000. This is a specific adjustment required for the ps-fuel installation. ```lua if weaponName == "weapon_fireextinguisher" then ammo = 4000 end ``` -------------------------------- ### Format properties.sql for Database Collation Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Corrects the character set and collation at the end of the `properties.sql` file to match the database's settings, specifically for `utf8mb4_general_ci`. This resolves 'Foreign key constraint is incorrectly formed' errors during SQL import. ```sql ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; ``` -------------------------------- ### Input Field Configuration Examples (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/menus/client/input This section provides examples of how to configure different types of input fields within the `ps.input` dialog. It covers basic text input, numeric input with range validation, dropdown selection, boolean checkboxes, and multi-line text areas, illustrating the structure and available properties for each. ```lua -- Basic text input field { title = 'Player Name', type = 'input', placeholder = 'Enter player name', required = true } ``` ```lua -- Numeric input with min/max validation { title = 'Amount', type = 'number', min = 1, max = 999999, placeholder = 'Enter amount', required = true } ``` ```lua -- Dropdown selection from predefined options { title = 'Vehicle Class', type = 'select', options = { {value = 'compact', label = 'Compact Cars'}, {value = 'sedan', label = 'Sedans'}, {value = 'suv', label = 'SUVs'}, {value = 'sports', label = 'Sports Cars'} }, required = true } ``` ```lua -- Boolean checkbox input { title = 'Send Notification', type = 'checkbox', description = 'Send notification to all players' } ``` ```lua -- Multi-line text input { title = 'Description', type = 'textarea', placeholder = 'Enter detailed description…', required = false } ``` -------------------------------- ### Lua: Basic User Registration Form Example Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/input Demonstrates how to create and display a user registration form using the `input` function. It defines various input fields and handles the form submission or cancellation. ```lua local function showRegistrationForm() local options = { { type = 'text', title = 'First Name', placeholder = 'Enter first name', required = true }, { type = 'text', title = 'Last Name', placeholder = 'Enter last name', required = true }, { type = 'number', title = 'Age', placeholder = 18, required = true, min = 16, max = 100 }, { type = 'select', title = 'Gender', options = { { label = 'Male', value = 'male' }, { label = 'Female', value = 'female' }, { label = 'Other', value = 'other' } }, required = true } } local result = exports['ps-lib']:input('Character Registration', options) if result then TriggerServerEvent('character:create', result) ps.notify('Character created successfully!', 'success') else ps.notify('Registration cancelled', 'error') end end ``` -------------------------------- ### Add House Garage Removal Event to qb-garages Client Source: https://docs.projectsloth.org/ps/scripts/ps-housing/installation Adds a new event handler to the qb-garages client script to manage the removal of house garages. This ensures that when a house garage is removed, its configuration is correctly updated in the client's memory. This is part of the integration with ps-housing. ```lua RegisterNetEvent('qb-garages:client:removeHouseGarage', function(house) Config.HouseGarages[house] = nil end) ``` -------------------------------- ### Configure Discord Bot Token in server.cfg Source: https://docs.projectsloth.org/ps/scripts/ps-discord/installation This snippet shows how to set your Discord bot token within the server.cfg file. Ensure you replace 'TOKENHERE' with your actual bot token obtained from the Discord Developer Portal. ```cfg set ps:discordBotToken "TOKENHERE" ``` -------------------------------- ### Get From Server API Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/framework/server Query general data across the server environment. ```APIDOC ## Get From Server API Functions ### Description Allows querying general server-wide data, including lists of players, jobs, gangs, and details about shared vehicles and weapons. ### Functions - `getAllPlayers`: Retrieves a list of all currently online players. - `getNearbyPlayers`: Retrieves players located near a specified point or player. - `getJobCount`: Retrieves the total number of players currently in a specific job. - `getJobTypeCount`: Retrieves the total number of players in a specific job type. - `getAllJobs`: Retrieves a list of all defined jobs on the server. - `getAllGangs`: Retrieves a list of all defined gangs on the server. - `vehicleOwner`: Retrieves the owner of a specified vehicle. - `getSharedVehicle`: Retrieves information about a shared vehicle definition. - `getSharedVehicleData`: Retrieves shared data for a specific vehicle. - `getSharedWeapons`: Retrieves a list of all shared weapon definitions. - `getSharedWeaponData`: Retrieves shared data for a specific weapon. ``` -------------------------------- ### Basic Usage Example - Lua Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/coord-grabber This Lua code snippet outlines the basic usage of the Coord Grabber module. It explains how to start the tool, move the crosshair, copy coordinates in different formats (Vec3, Vec4, Vec2), and how to stop the grabber. ```lua -- Start coordinate grabber -- Type in chat: /coordGrab -- Move crosshair to desired location -- Press F to copy Vec3 coordinates -- Press G to copy Vec4 coordinates (includes heading) -- Press H to copy Vec2 coordinates -- Right-click or run /coordGrab again to stop ``` -------------------------------- ### Execute OX Lib Skill Check Minigame Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/interactions/client/minigame Starts the 'ox' minigame, a skill check minigame utilizing OX Lib. Configuration involves 'difficulty' and optional 'input' arrays. Returns a boolean indicating success. ```lua local values = { difficulty = {'easy', 'easy', 'medium'}, -- Difficulty array input = {'1', '2', '3', '4'} -- Input keys (optional) } local success = ps.minigame('ox', values) ``` -------------------------------- ### Configure Discord Guild ID in server.cfg Source: https://docs.projectsloth.org/ps/scripts/ps-discord/installation This snippet demonstrates how to set your server's Discord guild ID in the server.cfg file. Replace 'IDHERE' with your server's ID, which can be found by enabling developer mode in Discord and copying the server ID. ```cfg set ps:discordGuildId "IDHERE" ``` -------------------------------- ### Execute PS-UI Scrambler Minigame Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/interactions/client/minigame Starts the 'ps-scrambler' minigame, a word scramble challenge from PS-UI. Configuration includes 'type' and 'timeLimit' in seconds. Returns a boolean indicating success. ```lua local values = { type = "alphabet", -- Type of scrambler timeLimit = 30 -- Time limit in seconds } local success = ps.minigame('ps-scrambler', values) ``` -------------------------------- ### VarHack Minigame - Lua Example (Callback) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/minigames/varhack Demonstrates using the VarHack minigame with a callback function to handle the game's completion. The callback receives a boolean indicating success or failure. This is the standard method for asynchronous handling. ```lua RegisterCommand('testVarHack', function() exports.ps_lib:VarHack(function(success) if success then TriggerServerEvent('ps_lib:varHackSuccess') end end, 8, 5000) end) ``` -------------------------------- ### Client-Side: Inventory Management Source: https://docs.projectsloth.org/ps/scripts/ps-lib Client-side functions for interacting with the player's inventory. This includes checking if an item exists, getting item labels, and retrieving item images. Crucial for displaying inventory UI and enabling item interactions. ```lua function getImage(item) -- Implementation to get the image for an inventory item end function getLabel(item) -- Implementation to get the display label for an inventory item end function hasItem(item, count) -- Implementation to check if the player has a specific item and quantity end ``` -------------------------------- ### Server-Side: Get Job Information Source: https://docs.projectsloth.org/ps/scripts/ps-lib Fetches various job-related information from the server. This includes counts of jobs, specific job types, and details about all available jobs. Essential for systems that manage or display job statistics. ```lua function getJobCount() -- Implementation to return the total number of jobs end function getJobTypeCount(jobType) -- Implementation to return the count of players for a specific job type end function getAllJobs() -- Implementation to return a list of all available jobs end ``` -------------------------------- ### Check Version - PS Library Module Source: https://docs.projectsloth.org/ps/scripts This snippet likely represents a PowerShell module for checking software versions. It might involve functions to compare installed versions against required or latest versions, potentially taking version strings as input and returning a boolean or status code. ```powershell # Placeholder for version-check.md content # This file likely contains PowerShell functions related to version checking. ``` -------------------------------- ### VarHack Minigame - Lua Example (Direct Result) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/minigames/varhack Illustrates using the VarHack minigame by passing `false` for the callback, allowing the function to return the result directly. This method is suitable for synchronous checks of the game's outcome. An early return is used if the game is not successful. ```lua RegisterCommand('testVarHack', function() local success = exports.ps_lib:VarHack(false, 8, 5000) if not success then return end TriggerServerEvent('ps_lib:varHackSuccess') end) ``` -------------------------------- ### Circle Minigame Usage Example with Callback (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/minigames/circle Demonstrates using the Circle minigame with a callback function. The callback is executed upon completion of the minigame, allowing for conditional actions based on success. Parameters include the callback function, number of circles, and duration. ```lua RegisterCommand('testCircle', function() exports.ps_lib:Circle(function(success) if success then TriggerServerEvent('ps_lib:circleSuccess') end end, 2, 8) end) ``` -------------------------------- ### Get Nearby Objects Lua Example Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/getnear/getnearbyobjects Demonstrates how to use the getNearbyObjects function to find entities within a given distance from the player's current location. It takes optional coordinates and distance, returning a table of found objects. ```lua local nearbyObjects = ps.getNearbyObjects(nil, 20.0) print("Found " .. #nearbyObjects .. " objects nearby") ``` -------------------------------- ### Modules and Callbacks Source: https://docs.projectsloth.org/ps/scripts Information regarding modules and their associated callbacks within the framework. ```APIDOC ## Modules and Callbacks ### Description Documentation for available modules and their respective callbacks within the `ps_lib` framework. ``` -------------------------------- ### Show Project Sloth Context Menu (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/context-menu Creates and displays a context menu using provided data. It accepts a table 'menuData' with menu title and an array of items, each configurable with text, icons, descriptions, and actions (functions or events). ```lua local function showPlayerMenu() local menuData = { name = 'Player Options', items = { { title = 'Check ID', icon = 'https://example.com/id-icon.png', description = 'View player identification', action = function() ps.notify('Checking player ID...', 'info') -- Your ID check logic here end, }, { title = 'Give Money', icon = ps.getImage('money'), description = 'Transfer money to player', action = function() -- Open money transfer interface TriggerEvent('banking:openTransfer') end, } } } exports['ps-lib']:showContext(menuData) end ``` ```lua local function showVehicleMenu(vehicleId) local menuData = { name = 'Vehicle Actions', items = { { title = 'Lock/Unlock', icon = 'https://example.com/lock-icon.png', description = 'Toggle vehicle lock', event = 'vehicle:toggleLock', type = 'server', args = { vehicleId = vehicleId } }, { title = 'Start Engine', icon = 'https://example.com/engine-icon.png', description = 'Start the vehicle engine', event = 'vehicle:startEngine', type = 'client', args = { vehicle = vehicleId } }, { title = 'Check Trunk', description = 'Open vehicle trunk', action = function() TriggerServerEvent('inventory:openTrunk', vehicleId) end, } } } exports['ps-lib']:showContext(menuData) end ``` -------------------------------- ### Register Command to Test Maze Minigame (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/minigames/maze Demonstrates how to register a command to initiate the Maze minigame. It shows two common usage patterns: one using a callback function and another where the function returns the result directly. This highlights the flexibility of the Maze export. ```lua RegisterCommand('testMaze', function() exports.ps_lib:Maze(function(success) if success then TriggerServerEvent('ps_lib:mazeSuccess') end end, 15) end) ``` ```lua RegisterCommand('testMaze', function() local success = exports.ps_lib:Maze(false, 15) if not success then return end TriggerServerEvent('ps_lib:mazeSuccess') end) ``` -------------------------------- ### Register Server-Side Command with Lua Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/registercommand This Lua code snippet demonstrates how to register a server-side command using the `ps.registerCommand` function. It defines the command's name, configuration options (like admin access and help text), and a callback function to handle command execution. The callback receives the source, arguments, and the raw command string. ```lua ps.registerCommand('ps-print',{ admin = true, help = 'Turn On Types Of Prints', description = { -- gives chat message for args required { name = 'script', help = 'Script Name' }, { name = 'type', help = 'Type of print to turn on' } } }, function(source, args, rawCommand) local resource = args[1] local type = args[2] TriggerClientEvent('ps_lib:client:print', source, key, resource, type) TriggerEvent('ps_lib:print', resource, type) end) ``` -------------------------------- ### Client-Side: Get Coords and Money Source: https://docs.projectsloth.org/ps/scripts/ps-lib Client-side functions for accessing player coordinates and money. This allows client scripts to display or utilize the player's current location and financial status. Includes functions to get specific money types or all available amounts. ```lua function getCoords() -- Implementation to get the player's coordinates end function getMoneyData() -- Implementation to get all money data for the player end function getMoney(type) -- Implementation to get a specific type of money for the player end function getAllMoney() -- Implementation to get all types of money for the player end ``` -------------------------------- ### Menus Client API Source: https://docs.projectsloth.org/ps/scripts Client-side functions for creating and managing in-game menus. ```APIDOC ## Menus Client API ### Description Client-side functions for creating, displaying, and interacting with in-game menus. ### Functions - **`menu(source, menuData)`**: Displays a menu to the player. - **`closeMenu(source)`**: Closes the currently open menu for the player. - **`input(source, inputConfig)`**: Prompts the player for text input. ``` -------------------------------- ### Create Temporary Shop (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/inventory/server/ps Creates and opens a temporary shop for a player using the ps.createShop function. It takes a source ID and shop configuration data including name, label, items, and slots. ```lua ps.createShop(source, { name = "tool_shop", label = "Hardware Store", items = { { name = "screwdriver", price = 10 }, { name = "hammer", price = 15 } } }) ``` -------------------------------- ### Server-Side: Get All Players Source: https://docs.projectsloth.org/ps/scripts/ps-lib Retrieves a list of all players currently connected to the server. This function is useful for server-side scripts that need to iterate over or interact with all active players. ```lua function getAllPlayers() -- Implementation to return a list of all connected player sources end ``` -------------------------------- ### Initialize ps_lib in Shared File (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/dependancies/how-to-inject-ps_lib-into-your-scripts Initializes the ps_lib by calling the 'init' export. This line should be placed in a shared file within your script. The returned 'ps' object will contain client-side utilities on the client and server-side utilities on the server. ```lua ps = exports.ps_lib:init() ``` -------------------------------- ### Get Player Queue Status - Lua Source: https://docs.projectsloth.org/ps/scripts/ps-discord/exports Retrieves the current queue number and priority for a specified player. Requires a player identifier as input. Returns an integer for queue number and an integer for queue priority. ```lua exports["ps-discord"]:GetQueueStatus(identifier) ``` -------------------------------- ### Targets API Source: https://docs.projectsloth.org/ps/scripts Functions for creating and managing in-game targets. ```APIDOC ## Targets API ### Description APIs for creating, managing, and destroying various types of targets in the game world. ### Functions - **`boxTarget(name, coords, size, options)`**: Creates a box-shaped target. - **`circleTarget(name, coords, radius, options)`**: Creates a circular target. - **`entityTarget(name, entity, options)`**: Creates a target associated with a specific entity. - **`targetModel(name, model, coords, size, options)`**: Creates a target based on a vehicle or ped model. - **`destroyAllTargets()`**: Removes all active targets. - **`destroyTarget(name)`**: Removes a specific target by its name. ``` -------------------------------- ### Server-Side: Get Player Data Source: https://docs.projectsloth.org/ps/scripts/ps-lib Retrieves various data points for players from the server. This includes player identifiers, metadata, character information, and job-related details. It is crucial for server-side logic that needs player-specific information. ```lua function getPlayerData(source, key) -- Implementation to get player data based on the provided key end function getIdentifier(source, type) -- Implementation to get a specific player identifier end function getMetadata(source, key) -- Implementation to get player metadata end function getCharInfo(source, key) -- Implementation to get character information end function getPlayerName(source) -- Implementation to get the player's name end function getPlayer(source) -- Implementation to get the player object end function getVehicleLabel(source) -- Implementation to get the player's current vehicle label end function isDead(source) -- Implementation to check if the player is dead end function getJob(source) -- Implementation to get the player's current job end function getJobName(source) -- Implementation to get the player's job name end function getJobType(source) -- Implementation to get the player's job type end function isBoss(source) -- Implementation to check if the player is a boss in their job end function getJobDuty(source) -- Implementation to get the player's job duty status end function getJobData(source, key) -- Implementation to get specific job data for the given key. end function getGang(source) -- Implementation to get the player's gang information end function getGangName(source) -- Implementation to get the name of the player's current gang. end function isLeader(source) -- Implementation to check if the player is a leader of their gang end function getGangData(source, key) -- Implementation to get specific gang data for the given key. end function getCoords(source) -- Implementation to get the player's coordinates end function getMoneyData(source) -- Implementation to get all money data for the player end function getMoney(source, type) -- Implementation to get a specific type of money for the player end function getAllMoney(source) -- Implementation to get all types of money for the player end ``` -------------------------------- ### Get Nearby Players (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/framework/server/players/getnearbyplayers Retrieves a list of players within a specified distance from a source player. It returns a table containing player IDs, names, source IDs, and distances. Note: Players closer than 5.0 units are always filtered out. ```lua local nearby = ps.getNearbyPlayers(source, 10.0) for _, player in ipairs(nearby) do print(player.name .. " is nearby (" .. player.distance .. "m away)") end ``` -------------------------------- ### Display Image/GIF using showImage (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/show-image Demonstrates how to use the showImage function to display a static image or an animated GIF in a full-screen overlay. This function takes a URL string as input and does not return any value. It is exported via 'ps-lib' and 'ps-ui' for standard and legacy support respectively. ```lua -- Show a static image exports['ps-lib']:showImage('https://example.com/image.jpg') -- Show an animated GIF exports['ps-lib']:showImage('https://example.com/animation.gif') ``` -------------------------------- ### Apply Item Requirements for Crafting (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/crafting/server-side Specifies item requirements needed to access a crafting station. This can be a single item string or an array of required item names. Ensures players have necessary items before crafting. ```lua checks = { items = {'crafting_license', 'workshop_key'} } ``` ```lua checks = { items = 'crafting_license' } ``` -------------------------------- ### Configure Minigame for Crafting (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/crafting/server-side Defines minigame integration for a crafting recipe. This allows for interactive gameplay elements during the crafting process. The `type` specifies the minigame, and `data` contains its specific parameters. ```lua minigame = { type = 'ps-circle', -- Minigame type data = { circles = 4, time = 8 } } ``` -------------------------------- ### Server-Side: Get Shared Weapon Data Source: https://docs.projectsloth.org/ps/scripts/ps-lib Enables server-side retrieval of shared weapon data. This function is used to access information about weapons that are shared across the server. It's important for managing weapon inventories and permissions. ```lua function getSharedWeapons() -- Implementation to get a list of all shared weapons end function getSharedWeaponData(weaponName, key) -- Implementation to get specific data for a shared weapon end ``` -------------------------------- ### Trigger Server Callback with Data (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/callbacks/callback This Lua code demonstrates how to use the `ps.callback` function to trigger a server-side function. It accepts a function name and any number of arguments to be passed to the server. The return value from the server is then printed. ```lua -- for client sided callback triggers local timeWorked = ps.callback('getTimeWorked', "data1", 'data2') print(timeWorked) -- for server sided callback triggers local timeWorked = ps.callback('getTimeWorked', source, "data1", 'data2') print(timeWorked) ``` -------------------------------- ### Define and Display Context Menu in Lua Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/menus/client/menu The `ps.menu` function creates and displays a context menu. It requires a unique name, an optional label, and an array of menu options. Each option can have text, a description, an icon, a disabled state, and can trigger a function or a client/server event with arguments. ```lua ps.menu('main_menu', 'Main Menu', { { title = 'Police Actions', description = 'Access police menu', icon = 'fas fa-shield-alt', event = 'police:client:openMenu' }, { title = 'Check ID', description = 'Check nearby player ID', icon = 'fas fa-id-card', isServer = true, event = 'police:server:checkId', args = {playerId = GetPlayerServerId(PlayerId())} }, { title = 'Close Menu', description = 'Close this menu', icon = 'fas fa-times', action = function() ps.closeMenu() end } }) ``` -------------------------------- ### Server-Side: Get Shared Vehicle Data Source: https://docs.projectsloth.org/ps/scripts/ps-lib Allows server-side scripts to access shared vehicle information. This includes checking vehicle ownership and retrieving data for shared vehicles. Useful for managing vehicle access and synchronization. ```lua function vehicleOwner(vehicleNetId) -- Implementation to check if a vehicle is owned end function getSharedVehicle(vehicleNetId) -- Implementation to get shared vehicle data end function getSharedVehicleData(vehicleNetId, key) -- Implementation to get specific shared vehicle data end ``` -------------------------------- ### Initialize Scrambler Minigame (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/minigames/scrambler Demonstrates how to initialize the Scrambler minigame using the ps_lib export. It shows two methods for handling the completion callback: using a function or checking the boolean return value. This function requires the ps_lib resource to be available. ```lua RegisterCommand('testScrambler', function() exports.ps_lib:Scrambler(function(success) if success then TriggerServerEvent('ps_lib:scramblerSuccess') end end, "numeric", 20, 0) end) RegisterCommand('testScrambler', function() local success = exports.ps_lib:Scrambler(false, "numeric", 20, 0) if not success then return end TriggerServerEvent('ps_lib:scramblerSuccess') end) ``` -------------------------------- ### Server-Side: Get Gang Information Source: https://docs.projectsloth.org/ps/scripts/ps-lib Provides access to gang-related data on the server. Functions allow retrieval of all gangs, specific gang details, gang grades, and leader status. This is vital for managing gang systems and permissions. ```lua function getAllGangs() -- Implementation to return a list of all gangs end function getGang(gangId) -- Implementation to retrieve details for a specific gang end function getGangName(gangId) -- Implementation to retrieve the name of a specific gang end function getGangData(gangId, key) -- Implementation to retrieve specific data for a gang end function getGangGrade(gangId, gradeLevel) -- Implementation to retrieve information about a specific gang grade end function getGangGradeLevel(gangId, gradeName) -- Implementation to retrieve the level of a specific gang grade end function getGangGradeName(gangId, gradeLevel) -- Implementation to retrieve the name of a specific gang grade level end function isLeader(source, gangId) -- Implementation to check if a player is a leader of a specific gang end ``` -------------------------------- ### Create and Display Input Dialog (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/menus/client/input This snippet demonstrates how to create and display a customizable input dialog using the `ps.input` function. It defines the dialog title and an array of input fields, each with specific properties like title, type, validation rules, and placeholder text. The function returns the collected input values or nil if cancelled. ```lua local result = ps.input('Player Information', { { title = 'First Name', type = 'input', placeholder = 'Enter first name', required = true }, { title = 'Age', type = 'number', min = 18, max = 100, required = true }, { title = 'Department', type = 'select', options = { {value = 'police', label = 'Police Department'}, {value = 'ems', label = 'Emergency Medical'}, {value = 'fire', label = 'Fire Department'} }, required = true }, { title = 'On Duty', type = 'checkbox', description = 'Are you currently on duty?' } }) if result then local firstName = result[1] local age = result[2] local department = result[3] local onDuty = result[4] print("Name:", firstName, "Age:", age, "Dept:", department, "Duty:", onDuty) else print("Input cancelled") end ``` -------------------------------- ### Client-Side: Get Gang Information Source: https://docs.projectsloth.org/ps/scripts/ps-lib Provides client-side functions to retrieve information about the player's gang. This includes the gang's name, data, and leader status. Essential for displaying gang affiliations and managing permissions on the client. ```lua function getGang() -- Implementation to get the player's gang information end function getGangName() -- Implementation to get the name of the player's current gang. end function isLeader() -- Implementation to check if the player is a leader of their gang end function getGangData(key) -- Implementation to get specific gang data for the given key. end ``` -------------------------------- ### Execute PS-UI Maze Minigame Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/interactions/client/minigame Launches the 'ps-maze' minigame, a maze navigation challenge from PS-UI. Requires a 'timeLimit' in seconds. Returns a boolean indicating success. ```lua local values = { timeLimit = 20 -- Time limit in seconds } local success = ps.minigame('ps-maze', values) ``` -------------------------------- ### Players API Source: https://docs.projectsloth.org/ps/scripts/ps-lib/bridge/framework/server Functions for managing player data, identity, state, and economy. ```APIDOC ## Players API Functions ### Description Provides functions to interact with player data, including identity, status, and economic information. ### Functions - `getPlayer`: Retrieves player information. - `getPlayerByIdentifier`: Retrieves player information using an identifier. - `getOfflinePlayer`: Retrieves information for an offline player. - `getLicense`: Retrieves a player's license. - `getIdentifier`: Retrieves a player's identifier. - `getSource`: Retrieves the player's source identifier. - `getPlayerName`: Retrieves the player's name. - `getPlayerNameByIdentifier`: Retrieves a player's name using their identifier. - `getPlayerData`: Retrieves all player data. - `getMetadata`: Retrieves player metadata. - `getCharInfo`: Retrieves character information for a player. - `getNearbyPlayers`: Retrieves players in proximity to a given player or location. - `setJob`: Sets the job for a player. - `setJobDuty`: Sets the job duty status for a player. - `addMoney`: Adds money to a player's account. - `removeMoney`: Removes money from a player's account. - `getMoney`: Retrieves the amount of money a player has. - `isOnline`: Checks if a player is currently online. ``` -------------------------------- ### Client-Side: Get Job Information Source: https://docs.projectsloth.org/ps/scripts/ps-lib Client-side functions to fetch current job details for the player. This includes the job itself, its name, type, duty status, and whether the player is a boss. Useful for displaying job-related information on the client UI. ```lua function getJob() -- Implementation to get the player's current job end function getJobName() -- Implementation to get the player's job name end function getJobType() -- Implementation to get the player's job type end function isBoss() -- Implementation to check if the player is a boss in their job end function getJobDuty() -- Implementation to get the player's job duty status end function getJobData(key) -- Implementation to get specific job data for the given key. end ``` -------------------------------- ### Client-Side: Get Player Information Source: https://docs.projectsloth.org/ps/scripts/ps-lib Client-side functions for retrieving detailed player information. This includes identifiers, metadata, character details, names, and status like whether the player is dead. Essential for UI elements and client-side logic. ```lua function getPlayerData(key) -- Implementation to get player data based on the provided key end function getIdentifier(type) -- Implementation to get a specific player identifier end function getMetadata(key) -- Implementation to get player metadata end function getCharInfo(key) -- Implementation to get character information end function getPlayerName() -- Implementation to get the player's name end function getPlayer() -- Implementation to get the player object end function getVehicleLabel() -- Implementation to get the player's current vehicle label end function isDead() -- Implementation to check if the player is dead end ``` -------------------------------- ### Combine Multiple Restrictions for Crafting (Lua) Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/ps-ui/ui/crafting/server-side Demonstrates how to combine multiple restriction types (job, items, gang) for a single crafting station. This provides a flexible way to manage access based on various player attributes. ```lua checks = { job = {'mechanic'}, items = {'advanced_tools'}, gang = {'mechanics_union'} } ``` -------------------------------- ### Execute PS-UI Circle Minigame Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/interactions/client/minigame Initiates the 'ps-circle' minigame, a circle progress challenge from PS-UI. Requires 'amount' and 'speed' for configuration. Returns a boolean indicating success. ```lua local values = { amount = 3, -- Number of circles to complete speed = 15 -- Speed of the circle } local success = ps.minigame('ps-circle', values) ``` -------------------------------- ### Get Nearby Peds in Lua Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/getnear/getnearbyped Retrieves an array of nearby peds within a specified distance from the player's current position or provided coordinates. Each element in the returned table contains the ped entity and its distance. Defaults are applied if no coordinates or distance are specified. ```lua local nearbyPeds = ps.getNearbyPed(nil, 30.0) for i, pedData in ipairs(nearbyPeds) do print("Ped " .. i .. " at distance: " .. pedData.distance) end ``` -------------------------------- ### Execute PS-UI Varhack Minigame Source: https://docs.projectsloth.org/ps/scripts/ps-lib/modules/interactions/client/minigame Initiates the 'ps-varhack' minigame, a variable hacking challenge from PS-UI. Requires 'blocks' and 'timeLimit' in seconds for configuration. Returns a boolean indicating success. ```lua local values = { blocks = 5, -- Number of blocks timeLimit = 30 -- Time limit in seconds } local success = ps.minigame('ps-varhack', values) ```