[HELP] ESX + DriftV?

I have been developing a server using the DriftV base and everything has been going great except I cannot seem to figure out how to use the money system provided in driftv with ESX scripts.
For example: this black jack script using ESX. How would I change this to use the driftv database?

ESX = nil

TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)

function SetExports()
    exports["kgv-blackjack"]:SetGetChipsCallback(function(source)
        local cash = 0
        local xPlayer = ESX.GetPlayerFromId(source)

        if xPlayer ~= nil then
            cash = xPlayer.getMoney()
        end

        return cash or 0
    end)

    exports["kgv-blackjack"]:SetTakeChipsCallback(function(source, amount)
        local xPlayer = ESX.GetPlayerFromId(source)

        if xPlayer ~= nil then
            xPlayer.removeMoney(amount)
        end
    end)

    exports["kgv-blackjack"]:SetGiveChipsCallback(function(source, amount)
        local xPlayer = ESX.GetPlayerFromId(source)

        if xPlayer ~= nil then
            xPlayer.addMoney(amount)
        end
    end)
end

AddEventHandler("onResourceStart", function(resourceName)
	if ("kgv-blackjack" == resourceName) then
        Citizen.Wait(1000)
        SetExports()
    end
end)

SetExports()

Thanks and any help is appreciated!



There appears to be no server side call to directly add/remove player money, instead requiring a client to trigger a server event.
It appears these are the two calls you to need trigger from the blackjack resource, but you would have to trigger them from the client side, not the server.

Your DriftV files should contain an “Events” table somewhere which has the reference for the .pay and .addMoney event names you will call

If you are aware of a way server side to add/remove money that would be the better route to go but my quick search of the Github did not return anything of the sort.

1 Like

Okay so that would explain why adding those events into server side wouldn’t work for me. And kept returning p: was a nil global. If I add them to client side do you think it would work as expected? Just would have the opportunity for more clients to exploit/cheat right?
(Which I honestly am not concerned about)

I think you found the only reference to the event.pay and event.addmoney. As those screenshots are the only ones I was able to find after hours of searching the files.

Wondering if it would just be easier setup esx to use driftv’s data for money…

I would personally create my own server event to trigger, and mimic the code, but accept and pass a source value, also, the events don’t need to be networked so you can just use a handler, but seeing d-bubble’s response to another post and seeming to understand exports a bit more, creating exported functions you call would be better.

For the add money you would do like

exports('addPlayerMoney', function(source, money)
  player[source].money = math.floor(player[source].money + money)
  TriggerClientEvent('FeedM:showNotification', source, "+ ~g~"..tostring(math.floor(money)).."~s~$", 2000, "success")
end)

And the blackjack file would call

exports["kgv-blackjack"]:SetGiveChipsCallback(function(source, amount)
    exports['DriftV']:addPlayerMoney(source, amount) -- 'DriftV' will be 'whateverTheDriftVResourceNameis'
end)
1 Like

So i went ahead and tested this but there is still one problem im having of grabbing the players current money. I put:

exports('GetPlayerMoney', function(source, money)
  player[source].money = player[source].money
end)

And it returns that i dont have enough money. Sorry if im missing something simple haha ive been at this for far too long.

1.) You are not getting and returning any value.
2.) You are just setting the players money equal to their money
Having a main reference for the money value, you don’t need to “get” the value so you just need to return the player[source].money

1 Like

Thank you! I didnt realize I had to put the return in the server script for black jack! After that it worked flawlessly! ( I did have to add some save functions otherwise it would appear as if you has 0 money)!