Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] [ESX Legacy] Receiving Money if Player is not Online #23

Open
Musiker15 opened this issue Feb 21, 2022 · 0 comments
Open

[FIX] [ESX Legacy] Receiving Money if Player is not Online #23

Musiker15 opened this issue Feb 21, 2022 · 0 comments

Comments

@Musiker15
Copy link

Musiker15 commented Feb 21, 2022

Replace this function in server.lua to Support ESX 1.2 ; ESX v1-final and ESX Legacy :)
Add Config.ForceMoney = true to your config.lua

function addMoney(identifier,money,business)
    if not identifier then return end
    local xPlayer = ESX.GetPlayerFromIdentifier(identifier)
    local money = math.floor(tonumber(money))
    if xPlayer then
        print("[^1"..GetCurrentResourceName().."^7] Adding money to "..GetPlayerName(xPlayer.source).." - "..identifier.." ("..tostring(money).."$)")
        TriggerClientEvent('esx:showNotification', xPlayer.source, _L("received_money"):format(tostring(money),business))
        xPlayer.addAccountMoney("bank", math.floor(money))
    else
        --print("[^1"..GetCurrentResourceName().."^7] An error occured while adding money to "..identifier.." ("..tostring(money).."$). The player is offline.")
        if Config.ForceMoney then
            print("[^1"..GetCurrentResourceName().."^7] Forcing adding money to " .. identifier .. " (" ..tostring(money).. "$). The player is offline.")
            --MySQL.Sync.execute('UPDATE `users` SET `bank` = `bank` + @bank WHERE `identifier` = @identifier',{['@bank'] = money, ['@identifier'] = identifier})
            MySQL.Async.fetchAll('SELECT accounts FROM users WHERE identifier = @identifier', { 
                ["@identifier"] = identifier 
            }, function(result)
                if result[1] then
                    local accs = json.decode(result[1].accounts)
                    
                    accs.bank = accs.bank + money
            
                    MySQL.Async.execute("UPDATE users SET accounts = @bank WHERE identifier = @identifier", {
                        ["@identifier"] = identifier,
                        ["@bank"] = json.encode(accs)
                    })
                end
            end)
        end
    end
end

Please do not close this, so that everybody can see this :)

Repository owner deleted a comment Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant