Vorp Core Tutorial IconVorp Core Tutorial Icon

How do I add paying 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 elses scripts, then the steps may be different, but should be similar enough to follow along.

config.lua

Add the following code to config.lua, if config.lua does not exist, then add it.

--------------------------------------------------
Config = {}
Config.paymentamount = 5 -- interger 
Config.paymenttype = 0  -- 0 for cash, 1 for gold
Config.ScriptName = GetCurrentResourceName()

** Note: If “Config = {}” already exists in the file then ignore that line. you do not need it twice.

server.lua

Add the following code to the server.lua file. If server.lua does not exist add it.

TriggerEvent("getCore",function(core)
    VorpCore = core
end)

RegisterServerEvent(Config.ScriptName..'PayPlayer')
AddEventHandler(Config.ScriptName..':PayPlayer', function( --[[source]] )
    local _source = source
    print("payment, type",Config.paymentamount, Config.paymenttype) 
    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 _price = tonumber(Config.paymentamount)      
    local steamhex = GetPlayerIdentifier(_source)
    if Config.paymenttype == 0  then  -- 0 for cash, 1 for gold
        PaymentType = "cash" 
    else 
        PaymentType = "gold" 
    end  

    local server_text = playername.." was paid $".._price.." in ".. PaymentType .. " by " .. Config.ScriptName  

    local player_text = "You received $".._price.." in ".. PaymentType

    Character.addCurrency(Config.paymenttype, _price)  
    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 pays the player and sends the confirmation to the client.

client.lua

In client.lua add something like this example to where ever you want the payment to be triggered. If you do not have a client.lua, then add it to whatever client side script you do have.

 print(Config.ScriptName..':PayPlayer ', Config.paymentamount, Config.paymenttype)  
 TriggerServerEvent(Config.ScriptName..':PayPlayer')   

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

Tutorial Poll

0
Tutorial - Add paying a player to any vorp core based script

Was this tutorial helpful?

You will be redirected

Relevant Tutorials

By MK