### Database Updater System: Custom Tables and Migrations (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Register custom database tables and updates that automatically run on resource start using VORP Core's database updater system. This system supports version tracking and migration, ensuring your database schema evolves correctly. Updates are tracked in `server/services/dbupdater/status.json`. ```lua -- Add custom tables VORPcore.dbUpdateAddTables({ { name = "my_custom_table", sql = [[ CREATE TABLE IF NOT EXISTS `my_custom_table` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `identifier` VARCHAR(50) NOT NULL, `data` LONGTEXT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ]] } }) -- Add database updates/migrations VORPcore.dbUpdateAddUpdates({ { name = "add_nickname_column", check = "SHOW COLUMNS FROM `characters` LIKE 'nickname'", sql = [[ ALTER TABLE `characters` ADD COLUMN `nickname` VARCHAR(50) DEFAULT NULL; ]] }, { name = "add_inventory_slots", check = "SHOW COLUMNS FROM `characters` LIKE 'slots'", sql = [[ ALTER TABLE `characters` ADD COLUMN `slots` INT(11) DEFAULT 35; ]] } }) -- Updates run automatically on resource start -- Status tracked in server/services/dbupdater/status.json ``` -------------------------------- ### Get VORP Core API Object (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Access the main VORP Core API object to interact with framework functions. This includes retrieving user data by source or character ID, and listing all connected users. Server-side usage requires exporting the function, while client-side provides access to graphics and notification utilities. ```lua -- Server-side local VORPcore = exports.vorp_core:GetCore() -- Get a user by source local User = VORPcore.getUser(source) if User then local userData = User.getUsedCharacter print("Character: " .. userData.firstname .. " " .. userData.lastname) print("Money: $" .. userData.money) print("Gold: " .. userData.gold .. " bars") end -- Get all connected users local allUsers = VORPcore.getUsers() for identifier, user in pairs(allUsers) do print(identifier, user.source) end -- Get user by character ID local User = VORPcore.getUserByCharId(12345) if User then local character = User.getUsedCharacter print("Found character: " .. character.firstname) end ``` ```lua -- Client-side local VORPcore = exports.vorp_core:GetCore() -- Show notification to player VORPcore.NotifyTip("Welcome to the server!", 5000) -- Get screen resolution local resolution = VORPcore.Graphics.ScreenResolution() print("Screen: " .. resolution.width .. "x" .. resolution.height) ``` -------------------------------- ### Register and Trigger Callbacks with VORPcore Source: https://context7.com/vorpcore/vorp_core/llms.txt This section demonstrates how to register server-side callbacks and trigger them asynchronously or synchronously from both client and server. It covers request-response patterns and passing parameters. ```lua -- Server-side: Register a callback VORPcore.Callback.Register("myResource:checkInventory", function(source, cb, itemName) local User = VORPcore.getUser(source) local Character = User.getUsedCharacter -- Parse inventory (stored as JSON string) local inventory = json.decode(Character.inventory) or {} local hasItem = false local count = 0 for _, item in pairs(inventory) do if item.name == itemName then hasItem = true count = item.count break end end cb({ hasItem = hasItem, count = count }) end) -- Client-side: Call the callback asynchronously VORPcore.Callback.TriggerAsync("myResource:checkInventory", function(result) if result.hasItem then print("You have " .. result.count .. " of this item") else print("Item not found") end end, "weapon_revolver_cattleman") -- Client-side: Call the callback synchronously (blocking) local result = VORPcore.Callback.TriggerAwait("myResource:checkInventory", "weapon_revolver_cattleman") print("Has item: " .. tostring(result.hasItem)) -- Server-side: Trigger client callback VORPcore.Callback.TriggerAsync("myResource:getClientData", source, function(clientData) print("Received from client: " .. json.encode(clientData)) end, "param1", "param2") -- Server-side: Trigger client callback synchronously local clientResult = VORPcore.Callback.TriggerAwait("myResource:getClientData", source, "param1") ``` -------------------------------- ### Manage Player Whitelist with VORPcore Source: https://context7.com/vorpcore/vorp_core/llms.txt This snippet illustrates how to manage a player whitelist using VORPcore functions. It covers adding, removing, and retrieving whitelist entries, along with a configuration option to enable the system. ```lua -- Add player to whitelist local steamId = "steam:110000123456789" local success = VORPcore.Whitelist.whitelistUser(steamId) if success then print("Player whitelisted successfully") end -- Remove from whitelist VORPcore.Whitelist.unWhitelistUser(steamId) -- Get whitelist entry local entry = VORPcore.Whitelist.getEntry(steamId) if entry then print("User ID: " .. entry.id) print("Status: " .. tostring(entry.status)) print("Discord ID: " .. entry.discordid) end -- Whitelist configuration in config.lua Config.Whitelist = true -- Enable whitelist system -- Players without whitelist will see this kick message on connect -- Translation[Lang].MessageOfSystem.NoInWhitelist ``` -------------------------------- ### Implement Ban System with VORPcore Source: https://context7.com/vorpcore/vorp_core/llms.txt This section details the VORPcore ban system, showing how to perform permanent and temporary bans, unban players, and configure ban messages and time zones. ```lua -- Permanent ban local steamId = GetPlayerIdentifierByType(source, 'steam') TriggerEvent("vorpbans:addtodb", true, steamId, 0) -- 0 = permanent -- Temporary ban (ban for 24 hours) local currentTime = os.time() local banDuration = 24 * 60 * 60 -- 24 hours in seconds local banUntil = currentTime + banDuration TriggerEvent("vorpbans:addtodb", true, steamId, banUntil) -- Unban player TriggerEvent("vorpbans:addtodb", false, steamId, 0) -- Ban message configuration Config.DateTimeFormat = "%d/%m/%y %H:%M:%S" Config.TimeZone = " CET" Config.TimeZoneDifference = 1 -- Hours from UTC -- Player will see: "You are banned until: 15/03/25 14:30:00 CET" ``` -------------------------------- ### Manage Player Warnings with VORPcore Source: https://context7.com/vorpcore/vorp_core/llms.txt This code demonstrates the VORPcore warning system, including adding, removing, and checking player warnings. It also shows how to set warnings directly and implement an automatic ban system based on warning thresholds. ```lua -- Add warning to player local targetSource = 2 TriggerEvent("vorpwarns:addtodb", true, targetSource, source) -- Remove warning from player TriggerEvent("vorpwarns:addtodb", false, targetSource, source) -- Check player warnings local User = VORPcore.getUser(source) local warnings = User.getPlayerwarnings() print("Player has " .. warnings .. " warnings") -- Set warnings directly User.setPlayerWarnings(5) -- Custom warning threshold system AddEventHandler("vorpwarns:addtodb", function(status, target, source) local User = VORPcore.getUser(target) if User then local warnings = User.getPlayerwarnings() if warnings >= 3 then -- Auto-ban after 3 warnings local steamId = GetPlayerIdentifierByType(target, 'steam') TriggerEvent("vorpbans:addtodb", true, steamId, os.time() + (7 * 24 * 60 * 60)) -- 7-day ban end end end) ``` -------------------------------- ### Character Skill Management with VORPcore (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt This snippet demonstrates how to configure and manage character skill levels using VORPcore. It covers defining skill configurations, adding or deducting experience, checking current skill status, and listening for player level-up events. Experience rollover and progression events are handled automatically. ```lua -- config/skills.lua defines skill configuration Config.Skills = { Hunting = { Levels = { [1] = { Label = "Novice Hunter", NextLevel = 100 }, [2] = { Label = "Skilled Hunter", NextLevel = 250 }, [3] = { Label = "Expert Hunter", NextLevel = 500 }, [4] = { Label = "Master Hunter", NextLevel = 1000 }, [5] = { Label = "Legendary Hunter", NextLevel = 999999 } } } } -- Add skill experience local User = VORPcore.getUser(source) local Character = User.getUsedCharacter -- Add 50 hunting experience Character.setSkills("Hunting", 50) -- Deduct experience (negative value) Character.setSkills("Hunting", -25) -- Check current skills local skills = Character.skills for skillName, skillData in pairs(skills) do print(skillName .. ": Level " .. skillData.Level .. " - " .. skillData.Label) print(" Progress: " .. skillData.Exp .. "/" .. skillData.NextLevel) end -- Listen for level-up events AddEventHandler("vorp_core:Server:OnPlayerLevelUp", function(source, skillName, newLevel, oldLevel) print("Player " .. source .. " leveled up " .. skillName .. " from " .. oldLevel .. " to " .. newLevel) VORPcore.NotifySimpleTop(source, "Level Up!", "You reached " .. skillName .. " level " .. newLevel, 5000) end) ``` -------------------------------- ### VORPcore Notification System (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt This code demonstrates the various notification types available in VORPcore for both server-side and client-side use. It covers different styles like tips, centered messages, advanced notifications with icons, and mission updates. Customization options include text, icons, colors, and durations. ```lua -- Server-side notifications VORPcore.NotifyTip(source, "Pick up the item", 3000) VORPcore.NotifyLeft(source, "Sheriff Badge", "You received a badge", "generic_textures", "tick", 5000, "COLOR_PURE_WHITE") VORPcore.NotifyRightTip(source, "Quest updated", 4000) VORPcore.NotifyObjective(source, "Go to the saloon", 5000) VORPcore.NotifySimpleTop(source, "New Item", "Repeater Carbine", 3000) VORPcore.NotifyCenter(source, "Area Cleared", 3000, "COLOR_PURE_WHITE") VORPcore.NotifyFail(source, "Mission Failed", "Time ran out", 5000) VORPcore.NotifyWarning(source, "Warning", "Hostiles nearby", "CHECKPOINT_OBVIOUS", "checkpoint_bad", 5000) VORPcore.NotifyAvanced(source, "Legendary Item", "inventory_items", "consumable_herb_ginseng", "COLOR_PURE_WHITE", 5000, 1, true) -- Client-side notifications VORPcore.NotifyTip("You are hungry", 5000) VORPcore.NotifyLeftRank(source, "Level Up", "Rank 25 Unlocked", "toast_medal", "TOAST_MEDAL_BUCKLE", 5000, "COLOR_PURE_WHITE") VORPcore.NotifyOneSimpleTop("Server Restart", 5000) ``` -------------------------------- ### Manage Player Instances with VORP Core (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Create and manage isolated game instances for players using VORP Core's instance system. This allows for private areas like apartments or heists. Players can enter and leave instances, and client-side events notify them of instance changes. The system uses routing buckets to isolate players. ```lua -- Client-side: Enter an instance local VORPcore = exports.vorp_core:GetCore() VORPcore.instancePlayers("myhouse_instance_123") -- Server will assign a routing bucket (1-63) for this instance -- All players with the same instance name share the same bucket -- Leave instance (return to main world) VORPcore.instancePlayers(0) -- Listen for instance changes (client-side) AddEventHandler("vorp_core:instanceChanged", function(bucketId) print("Entered routing bucket: " .. bucketId) if bucketId == 0 then print("Returned to main world") end end) -- Example: Player-owned house system RegisterCommand("entermyhouse", function(source, args) local User = VORPcore.getUser(source) local Character = User.getUsedCharacter local houseId = Character.charIdentifier -- Use character ID as unique instance TriggerClientEvent("vorp_core:instancePlayers", source, "house_" .. houseId) VORPcore.NotifyTip(source, "Entering your house", 3000) end) ``` -------------------------------- ### Manage Characters in VORP Core (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Handles character creation, deletion, and retrieval for players. It interacts with VORPcore functions to add, remove, and select characters, and retrieves a player's existing characters and their associated data like money and job. ```lua -- Character creation AddEventHandler("vorp:SelectedCharacter", function(source, character) print("Player selected character: " .. character.firstname .. " " .. character.lastname) print("Character ID: " .. character.charIdentifier) print("Job: " .. character.job .. " (Grade " .. character.jobGrade .. ")") -- Initialize character-specific systems TriggerEvent("myResource:loadPlayerData", source, character) end) -- Get all characters for a player local User = VORPcore.getUser(source) local allCharacters = User.getUserCharacters for _, char in pairs(allCharacters) do print("Character: " .. char.firstname .. " " .. char.lastname) print(" Money: $" .. char.money) print(" Job: " .. char.job) end -- Add new character local characterData = { firstname = "John", lastname = "Marston", age = 32, gender = "male", charDescription = "Former outlaw", nickname = "Johnny", skin = json.encode(skinData), comps = json.encode(clothingData), compTints = json.encode(tintData) } User.addCharacter(characterData) -- Delete character User.removeCharacter(characterId) -- Set active character User.setUsedCharacter(characterId) -- Check max characters allowed local maxChars = VORPcore.maxCharacters(source) -- Returns Config.MaxCharacters or user-specific limit ``` -------------------------------- ### Manage Character Jobs (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Modify a player's job, job grade, and label, with options to trigger associated events. It also demonstrates how to listen for job and job grade change events to update player-specific logic. ```lua local User = VORPcore.getUser(source) local Character = User.getUsedCharacter -- Set job with event trigger (default behavior) Character.setJob("sheriff") Character.setJobGrade(3) Character.setJobLabel("Sheriff") -- Set job without triggering events (use false flag) Character.setJob("sheriff", false) Character.setJobGrade(3, false) -- Check current job print("Current job: " .. Character.job .. " (Grade: " .. Character.jobGrade .. ")") -- Listen for job change events AddEventHandler("vorp:playerJobChange", function(source, newJob, oldJob) print("Player " .. source .. " changed from " .. oldJob .. " to " .. newJob) -- Update permissions, spawn vehicles, etc. end) AddEventHandler("vorp:playerJobGradeChange", function(source, newGrade, oldGrade) print("Player " .. source .. " promoted from grade " .. oldGrade .. " to " .. newGrade) end) ``` -------------------------------- ### Send Discord Webhooks with VORP Core (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Send rich Discord webhook messages for logging player actions, admin commands, and server events using VORP Core's webhook system. This function allows for customizable messages with optional branding like logos, footers, and avatars. Default webhook settings can be configured in `config.lua`. ```lua -- Simple webhook VORPcore.AddWebhook( "Player Joined", "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL", "PlayerName (steam:123456) joined the server", "16711680", -- Red color "VORP Core" ) -- Advanced webhook with custom branding VORPcore.AddWebhook( "Transaction Log", "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL", "John Doe purchased a horse for $500", "65280", -- Green color "Economy System", "https://i.imgur.com/logo.png", -- Logo "https://i.imgur.com/footer.png", -- Footer logo "https://i.imgur.com/avatar.png" -- Avatar ) -- Configure default webhook settings in config.lua Config.webhookColor = 16711680 Config.name = "VORP" Config.logo = "https://via.placeholder.com/30x30" Config.footerLogo = "https://via.placeholder.com/30x30" Config.Avatar = "https://via.placeholder.com/30x30" -- Example: Log admin actions RegisterCommand("giveitem", function(source, args) local targetId = tonumber(args[1]) local itemName = args[2] local count = tonumber(args[3]) -- Give item logic here... local adminName = GetPlayerName(source) local targetName = GetPlayerName(targetId) local message = string.format("%s gave %s %dx %s", adminName, targetName, count, itemName) VORPcore.AddWebhook("Admin Action", Logs.AdminWebhookURL, message) end, true) -- Restricted command ``` -------------------------------- ### Manage Player State in VORP Core (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Allows modification of a character's personal information, group affiliation, inventory capacity, appearance, experience points, and status effects. It also provides access to player state bags for real-time data access. ```lua local User = VORPcore.getUser(source) local Character = User.getUsedCharacter -- Update character personal info Character.setFirstname("Arthur") Character.setLastname("Morgan") Character.setAge(36) Character.setGender("male") Character.setCharDescription("Rugged outlaw with a code") Character.setNickName("Art") -- Manage group/permissions Character.setGroup("admin") print("Group: " .. Character.group) -- Inventory capacity local currentCapacity = Character.invCapacity Character.updateInvCapacity(10) -- Add 10 slots print("New capacity: " .. Character.invCapacity) -- Update character appearance Character.updateSkin(json.encode(newSkinData)) Character.updateComps(json.encode(newClothingData)) Character.updateCompTints(json.encode(newTintData)) -- XP system Character.addXp(100) Character.removeXp(50) Character.setXp(1000) print("Current XP: " .. Character.xp) -- Status data (hunger, thirst, etc.) local status = json.decode(Character.status) status.hunger = 80 Character.setStatus(json.encode(status)) -- Access via Player State Bags local playerState = Player(source).state print("In Session: " .. tostring(playerState.IsInSession)) print("Character Name: " .. playerState.Character.FirstName .. " " .. playerState.Character.LastName) print("Money: $" .. playerState.Character.Money) ``` -------------------------------- ### Manage Character Currency (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt Add, remove, or set currency (money, gold, rol tokens) for a player's character. This function automatically updates the UI and persists changes to the database. It includes checks for sufficient funds before removing currency. ```lua -- Get player's character local User = VORPcore.getUser(source) local Character = User.getUsedCharacter -- Add currency (0=money, 1=gold, 2=rol) Character.addCurrency(0, 500) -- Add $500 dollars Character.addCurrency(1, 10) -- Add 10 gold bars Character.addCurrency(2, 25) -- Add 25 rol tokens -- Remove currency Character.removeCurrency(0, 100) -- Remove $100 dollars if Character.money >= 1000 then Character.removeCurrency(0, 1000) TriggerClientEvent("shop:purchaseSuccess", source) else VORPcore.NotifyTip(source, "Not enough money!", 5000) end -- Set currency directly Character.setMoney(5000) Character.setGold(100) Character.setRol(500) -- Check current amounts print("Player has: $" .. Character.money .. ", " .. Character.gold .. " gold, " .. Character.rol .. " rol") ``` -------------------------------- ### Player Management Functions in VORPcore (Lua) Source: https://context7.com/vorpcore/vorp_core/llms.txt This section details VORPcore functions for managing player health and respawn states. It includes methods to heal players, revive them at their current location or specified coordinates, and respawn them at the nearest or a specific hospital. Event triggers for these actions are also provided for script integration. ```lua -- Heal a player (restore health and cores) VORPcore.Player.Heal(source) -- Revive a player at current location VORPcore.Player.Revive(source) -- Revive with coordinates VORPcore.Player.Revive(source, {x = 100.0, y = 200.0, z = 300.0, heading = 180.0}) -- Respawn player at nearest hospital VORPcore.Player.Respawn(source) -- Respawn at specific hospital VORPcore.Player.Respawn(source, "Valentine") -- Listen for player state events AddEventHandler("vorp_core:Server:OnPlayerHeal", function(source) print("Player " .. source .. " was healed") end) AddEventHandler("vorp_core:Server:OnPlayerRevive", function(source, param) print("Player " .. source .. " was revived") -- Give items, set state, etc. end) AddEventHandler("vorp_core:Server:OnPlayerRespawn", function(source, param) print("Player " .. source .. " respawned") -- Reset death timer, clear drops, etc. end) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.