[FREE] LAZY TAX

A simple tax system with setting options:
How much % should be deducted
When it should always happen
Notify message

Download: GitHub - ViziionMike/lazy_tax: Tax System


Screenshot_31

Code is accessible Yes
Subscription-based No
Lines (approximately) 150+
Requirements esx
Support Yes
6 Likes

Okay just some honest Feedback:

Client Lua

Why not simply trigger the esx notification as TriggerClientEvent on server side for the source?
And why do you have Config.taxNotification if you hardcode the notification msg?

RegisterNetEvent('showTaxNotification')
AddEventHandler('showTaxNotification', function(taxAmount)
    ESX.ShowNotification('Es wurden ' .. taxAmount .. '$ Steuern von Ihrem Konto abgezogen.')
end)

I dont understand what this Code is used for

RegisterNetEvent('receiveConfigFromServer')
AddEventHandler('receiveConfigFromServer', function(receivedConfig)
    config = receivedConfig
end)

For this one: The Event doesnt exist anymore on any esx version past 1.8.5, therefore it wont work. ESX = nil is useless and there is no reason to write that, if you dont define ESX, its always nil.

ESX = nil

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

So the Client.lua is basically useless

Server.lua

Same thing i mentioned for it on client side goes for this one.

ESX = nil

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

I dont know what this is,

local config = {}

Citizen.CreateThread(function()
    while ESX == nil do
        Citizen.Wait(10)
    end
    TriggerEvent('esx:getConfig', function(cfg) config = cfg end)
end)

Just do:

ESX = exports["es_extended"]:getSharedObject()

And add the config as server sided lua file in fxmanifest then you can access all the Config stuff too

And last but not least for this one:

local function applyTax()
    for _, player in ipairs(GetPlayers()) do
        local xPlayer = ESX.GetPlayerFromId(player)
        local accountBalance = xPlayer.getAccount('bank').money
        local taxPercentage = config.taxPercentage or 1 -- Standardmäßig 1%
        local taxAmount = accountBalance * (taxPercentage / 100)
        xPlayer.removeAccountMoney('bank', taxAmount)
        local notificationType = config.notificationType or 'esx'
        if notificationType == 'esx' then
            TriggerClientEvent('showTaxNotification', player, taxAmount) -- Auslösen der ESX-Benachrichtigung
        elseif notificationType == 'chat' then
            TriggerClientEvent('chatMessage', player, '', {255, 0, 0}, string.format(config.taxNotification, taxAmount)) -- Auslösen der Chat-Benachrichtigung
        end
    end
end

-- Timer fĂĽr die Steueranwendung
Citizen.CreateThread(function()
    while true do
        Citizen.Wait((config.taxInterval or 10) * 3600000) -- Millisekunden
        applyTax()
    end
end)

Just do

CreateThread(function()
    while true do
        Wait(Config.taxInterval)
        for _, player in ipairs(GetPlayers()) do 
            local xPlayer = ESX.GetPlayerFromId(player)
            local bankMoney = xPlayer.getAccount('bank').money
            local taxAmount = bankMoney * (Config.taxPercentage / 100)

            xPlayer.removeAccountMoney('bank', taxAmount)

            if notificationType == 'esx' then 
                TriggerClientEvent("ESX:Notify", xPlayer.source, "info", 3000, Config.taxNotification)
            else
                TriggerClientEvent('chatMessage', xPlayer.source, '', {255, 0, 0}, string.format(Config.taxNotification, taxAmount)) 
            end
        end
    end
end)

Thats basically all it needs

Suport for QBox / QBCORE ?