Jump to content

salary system help


rogerioexper

Recommended Posts

--salary system

local salario2 = 1000
local salario3 = 1000
local salario4 = 1000
local salario5 = 1000

function salario()
setTimer(salario2, 1000, 1)
setTimer(salario3, 1000, 1)
setTimer(salario4, 1000, 1)
setTimer(salario5, 1000, 1)
setTimer(reset, 1000, 1)
end


addCommandHandler("salario", aktu)

function aktu ()
local accName = getAccountName ( getPlayerAccount( thePlayer ) )
 if isObjectInACLGroup ("user."..accountName, aclGetGroup ( "PMSP2" ) ) then
givePlayerMoney(source, salario2)
setPlayerMoney(root, 2000)
outputChatBox("salario!")
end
end

--function salario2(p)
--if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)), aclGetGroup("PMSP2")) then -- 
--givePlayerMoney(source, salario2)
--givePlayerMoney ( source, 30000 )
--setPlayerMoney(source, 2000)
--end
--end

function salario3(p)
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)), aclGetGroup("BOPE2")) then -- 
givePlayerMoney(source, salario3)
end
end

function salario4(p)
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)), aclGetGroup("ROTA2")) then -- 
givePlayerMoney(source, salario4)
end
end

function salario5(p)
if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(p)), aclGetGroup("NARCOS2")) then -- 
givePlayerMoney(source, salario5)
end
end

function reset()
setTimer(salario, 5000, 1) -- return the new start
end

I wish someone help me if I am again making a salary system for acl and time

if puderen help me and I am grateful tanbem help many who need Fates basic script

Edited by rogerioexper
Link to comment

Use debugscript and it will tell you in detail what's wrong with the script. But from what I can spot, p is never defined and as such will return a null reference - resulting in errors.

Another issue is that you're trying to call the variable as opposed to the function in your timers. For example;

setTimer(salario3, 1000, 1) -- Variable
setTimer(salario3(), 1000, 1) -- Function

I would also recommend that you do not use the same name for variables and functions to keep things clean and not confuse yourself or others. :)

Edit:

I don't think any of your code is actually executed unless you left some code out. These functions, salario() and reset() are never triggered. You'll want to use an event such as onResourceStart for this.

Edited by Dealman
  • Like 1
Link to comment

A better implementation to this would be with tables:

-- Define ACLs' salary
local acl2salary = {
    -- ["ACL NAME"] = salary,
    
    ["PMSP2"] = 2000,
    ["BOPE2"] = 1000,
    ["ROTA2"] = 1000,
    ["NARCOS2"] = 1000
}

function giveSalaries ()
    -- Loop throught all the previously defined ACLs
    for aclName, salary in pairs ( acl2salary ) do
        -- Loop throught all the ACL's objects
        for index, objectName in pairs ( aclGroupListObjects ( aclGetGroup ( aclName ) ) ) do
            -- Check if the object is an account (and if it is, check if the account exists)
            if ( objectName:find ( "^user." ) and getAccount ( (objectName:gsub ( "^user.", "" )) ) ) then
                -- Try to get a player from his account name
                local player = getAccountPlayer ( getAccount ( (objectName:gsub ( "^user.", "" )) ) )
                
                -- Make sure we've found a player
                if ( player ) then
                    -- Give him the money
                    givePlayerMoney ( player, salary )
                    
                    outputChatBox ( "SALARY: You received $" .. salary .. "!", player )
                end
            end
        end
    end
end

-- Repeat every 5 seconds infinite times
setTimer ( giveSalaries, 5000, 0 )

Untested, but it should work.

Edited by znext
  • Like 1
Link to comment

Ah, znext beat me to it. I've written an example as well, I haven't tested it either but it should work. :)

local group1Salary = 1000
local group2Salary = 2000
local group3Salary = 3000
local group4Salary = 4000
local group5Salary = 5000

local salaryTimer = nil -- If we store the timer we can easily access it later

function Initialize()
	salaryTimer = setTimer(function()
		local allPlayers = getElementsByType("player") -- Get all the current player elements, and store them in a local variable
		for key, thePlayer in ipairs(allPlayers) do -- Loop through all the player elements, and store them in the temporary variable thePlayer
			if(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Group1"))) then
				givePlayerMoney(thePlayer, group1Salary)
				outputChatBox("You've received a salary of $"..tostring(group1Salary).."!", thePlayer, 255, 255, 255, true)
			elseif(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Group2"))) then
				givePlayerMoney(thePlayer, group2Salary)
				outputChatBox("You've received a salary of $"..tostring(group2Salary).."!", thePlayer, 255, 255, 255, true)
			elseif(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Group3"))) then
				givePlayerMoney(thePlayer, group3Salary)
				outputChatBox("You've received a salary of $"..tostring(group3Salary).."!", thePlayer, 255, 255, 255, true)
			elseif(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Group4"))) then
				givePlayerMoney(thePlayer, group4Salary)
				outputChatBox("You've received a salary of $"..tostring(group4Salary).."!", thePlayer, 255, 255, 255, true)
			elseif(isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Group5"))) then
				givePlayerMoney(thePlayer, group5Salary)
				outputChatBox("You've received a salary of $"..tostring(group5Salary).."!", thePlayer, 255, 255, 255, true)
			end
		end
	end, 10000, 0) -- This timer will trigger the included function every 10 seconds for an infinite amount of times
end
addEventHandler("onResourceStart", resourceRoot, Initialize) -- Run this function when this resource is started

 

  • Like 1
Link to comment

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...