How do I add giving an item to a player to any vorp core based script?
If you are adding it to one of my scripts, these are the steps.
If you are adding it to someone else’s scripts, then the steps may be different, but should be similar enough to follow along.
This is the simple version, it can be far more complex if you want it to be.
config.lua
Add to the following lines to the config.lua. If there isn’t a config.lua please create one.
Config = {}
Config.ItemLabel = "Beloved Family Members Ashes" -- This is the label that is used to print messages to the player, can be whatever you want, as long as it's a string.
Config.dbItem = "dead_person_ashes" -- this is the name of the item in your database. It must match exactly, and is caps specific.
Config.amount = 1 -- interger
Config.ScriptName = GetCurrentResourceName()
** Note: if “Config = {}” already exists in the file you do not need to add that line again.
server.lua
Please add the following lines to the server.lua file. If the file does not exist please create it.
TriggerEvent("getCore",function(core)
VorpCore = core
end)
VorpInv = exports.vorp_inventory:vorp_inventoryApi()
------------- ------------- ------------- -------------
------------- Give player item
------------- ------------- ------------- -------------
RegisterServerEvent(Config.ScriptName..':addItem')
AddEventHandler(Config.ScriptName..':addItem', function(--[[source]] epoc)
local _source = source
print("addItem: ",Config.dbItem, Config.ItemLabel)
local Character = VorpCore.getUser(_source).getUsedCharacter
if Character.lastname == nil then
Character = VorpCore.getUser(_source).getUsedCharacter
end
if Character.firstname == nil then
Character = VorpCore.getUser(_source).getUsedCharacter
end
local playername = Character.firstname .. ' ' .. Character.lastname
local server_text = playername.." was given "..Config.dbItem.." a ".. Config.ItemLabel .. " by " .. Config.ScriptName
local player_text = "You received ".. Config.ItemLabel
VorpInv.addItem(source, Config.dbItem, Config.amount )
print server_text
TriggerClientEvent("vorp:TipBottom", _source, player_text, 3000)
end)
This connects to vorp core, creates the variables, and pulls out the players name, and gives the player the item and sends the confirmation to the client.
client.lua
In client.lua add something like this example to where ever you want the item to be given to be triggered. If the client.lua does not exist, look for the file that runs in the client and add it to that.
print(Config.ScriptName..':addItem ', Config.ItemLabel, Config.amount)
TriggerServerEvent(Config.ScriptName..':addItem')
If you create any files make sure to add them to the fxmanifest.lua file under client or server scripts.
— Want more help? we are here: dragon code https://discord.gg/WPtnPbXhWY