Jump to content

Police Job auto Payment


Recommended Posts

Posted (edited)

Job payout timer 

-- Group payout timer 
function sendTurfPayout ( ) 
    local playerJobs = { }


    for i, Police Officer in pairs ( getElementsByType ( 'player' ) ) do 
        local exports.NGJobs:getPlayerJobs ( 'Police Officer' ) 
        if ( g and playerJobs [ g ] and playerJobs [ g ] > 0 ) then 
            local c = playerJobs [ g ] * tonumber ( get ( "*PAYOUT_CASH" ) )
            givePlayerMoney ( Police Officer, c )
            exports.NGMessages:sendClientMessage ( "Police: Here is $ "( playerJobs [ g ] ).."playout" v, 0, 255, 0 )
        end
    end
end 
setTimer ( sendTurfPayout, (60*tonumber(get("*PAYOUT_TIME")))*1000, 0 )

 

Edited by Citizen
code block
  • Moderators
Posted

Hello @BigBoss1234

Don't use the Tutorial section to ask scripting questions. Your topic has been moved to the Scripting section and approved so other members can now see it.

Using the right section for your post next time will reduce the waiting time for an actual answer.

PS: Also embed your lua code in a script block so it is easier to read. It's greatly appreciated in the community when OP does so (I edited your post for you)

Best regards,

Posted (edited)
function sendTurfPayout()
    local playerJobs = {}

    -- getting all police
    for i, player in ipairs(getElementsByType('player')) do
        local job = exports.NGJobs:getPlayerJob(player)
        if (job == 'Police Officer') then
            if (playerJobs[player] == nil) then
                playerJobs[player] = 0
            end
            playerJobs[player] = playerJobs[player] + 1
        end
    end

    -- pay the players
    for player, count in pairs(playerJobs) do
        local cash = count * tonumber(get("*PAYOUT_CASH"))
        givePlayerMoney(player, cash)
        exports.NGMessages:sendClientMessage("Police: Here is $" .. tostring(cash) .. " payout.", player, 0, 255, 0)
    end
end

-- set the timer
local payoutTime = tonumber(get("*PAYOUT_TIME"))
if payoutTime then
    setTimer(sendTurfPayout, 60 * payoutTime * 1000, 0)
end

 

Edited by FLUSHBICEPS
  • Thanks 1
Posted (edited)

Not Warking 

function sendJobPayout()
    local playerJobs = {}

    -- getting all police
    for i, player in ipairs(getElementsByType('player')) do
        local job = exports.NGJobs:getPlayerJob(player)
        if (job == 'Police Officer') then
            if (playerJobs[player] == nil) then
                playerJobs[player] = 0
            end
            playerJobs[player] = playerJobs[player] + 1
        end
    end

    -- pay the players
    for player, count in pairs(playerJobs) do
        local cash = count * tonumber(get("*PAYOUT_CASH"))
        givePlayerMoney(player, cash)
        exports.NGMessages:sendClientMessage("Police: Here is $" .. tostring(cash) .. " payout.", player, 0, 255, 0)
    end
end

-- set the timer
local payoutTime = tonumber(get("*PAYOUT_TIME"))
if payoutTime then
    setTimer(sendTurfPayout, 60 * payoutTime * 1000, 0)
end

 

 

<meta>
    <info author="BigBoss" name="Police Playout" type='script' version="1.0" />
    <script src="server.lua" type="server" />
    
    <settings>
        <setting name="*PAYOUT_TIME" value="30" desc="Payout timer in minutes" />
        <setting name="*PAYOUT_CASH" value="100000" desc="Money per group member per turf" />
    </settings>
    
</meta>

Edited by BigBoss1234
Posted
16 hours ago, BigBoss1234 said:

Not Warking 

function sendJobPayout()
    local playerJobs = {}

    -- getting all police
    for i, player in ipairs(getElementsByType('player')) do
        local job = exports.NGJobs:getPlayerJob(player)
        if (job == 'Police Officer') then
            if (playerJobs[player] == nil) then
                playerJobs[player] = 0
            end
            playerJobs[player] = playerJobs[player] + 1
        end
    end

    -- pay the players
    for player, count in pairs(playerJobs) do
        local cash = count * tonumber(get("*PAYOUT_CASH"))
        givePlayerMoney(player, cash)
        exports.NGMessages:sendClientMessage("Police: Here is $" .. tostring(cash) .. " payout.", player, 0, 255, 0)
    end
end

-- set the timer
local payoutTime = tonumber(get("*PAYOUT_TIME"))
if payoutTime then
    setTimer(sendTurfPayout, 60 * payoutTime * 1000, 0)
end

 

 

<meta>
    <info author="BigBoss" name="Police Playout" type='script' version="1.0" />
    <script src="server.lua" type="server" />
    
    <settings>
        <setting name="*PAYOUT_TIME" value="30" desc="Payout timer in minutes" />
        <setting name="*PAYOUT_CASH" value="100000" desc="Money per group member per turf" />
    </settings>
    
</meta>

function sendTurfPayout()
    local playerJobs = {}

    -- getting all police
    for i, player in ipairs(getElementsByType('player')) do
        local job = exports.NGJobs:getPlayerJob(player)
        if (job == 'Police Officer') then
            if (playerJobs[player] == nil) then
                playerJobs[player] = 0
            end
            playerJobs[player] = playerJobs[player] + 1
        end
    end

    -- pay the players
    for player, count in pairs(playerJobs) do
        local cash = count * tonumber(get("*PAYOUT_CASH"))
        givePlayerMoney(player, cash)
        exports.NGMessages:sendClientMessage("Police: Here is $" .. tostring(cash) .. " payout.", player, 0, 255, 0)
    end 
end

-- set the timer  
local payoutTimeStr = get("*PAYOUT_TIME")
if payoutTimeStr ~= false and type(payoutTimeStr) == "string" then 
      local payoutTimeInt= tonumber(payoutTimeStr)
      if type(payoutTimeInt) == "number" and payoutTimeInt > 0 then 
           setTimer(sendTurfPayout,payoutInt*60*1000,0)
       else 
           outputDebugString("Warning! Invalid *PAYOUT_TIME set in meta file",2);
      end 

else 
     outputDebugString("warning No *PAYOUT_TIME parameter foundin meta file",2);
end

try this please

  • Thanks 1
Posted
18 hours ago, BigBoss1234 said:

Not Warking 

function sendJobPayout()
    local playerJobs = {}

    -- getting all police
    for i, player in ipairs(getElementsByType('player')) do
        local job = exports.NGJobs:getPlayerJob(player)
        if (job == 'Police Officer') then
            if (playerJobs[player] == nil) then
                playerJobs[player] = 0
            end
            playerJobs[player] = playerJobs[player] + 1
        end
    end

    -- pay the players
    for player, count in pairs(playerJobs) do
        local cash = count * tonumber(get("*PAYOUT_CASH"))
        givePlayerMoney(player, cash)
        exports.NGMessages:sendClientMessage("Police: Here is $" .. tostring(cash) .. " payout.", player, 0, 255, 0)
    end
end

-- set the timer
local payoutTime = tonumber(get("*PAYOUT_TIME"))
if payoutTime then
    setTimer(sendTurfPayout, 60 * payoutTime * 1000, 0)
end

 

 

<meta>
    <info author="BigBoss" name="Police Playout" type='script' version="1.0" />
    <script src="server.lua" type="server" />
    
    <settings>
        <setting name="*PAYOUT_TIME" value="30" desc="Payout timer in minutes" />
        <setting name="*PAYOUT_CASH" value="100000" desc="Money per group member per turf" />
    </settings>
    
</meta>

You are calling in setTimer “SendTurfPayout” function and the function is sendJobPayout

  • Thanks 1
Posted

Bro, a playout does not happen from Resource, please make one for me A big help?

On 11/04/2023 at 20:21, FLUSHBICEPS said:
    local job = exports.NGJobs:getPlayerJob(player)

getPlayerJob ro getPlayerJobs?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...