Custom Gamemode Salary

Hello, so i’ve tried adding salary with a timer, it doesn’t seem to be working, so i would like to ask if someone could make me an example timer that would give 2 different jobs 2 different salarys every 10 seconds.

The jobs are just called “1, 2” well thats their ID.
Hope u can help :slight_smile:
And also if it’s not too much to ask maybe an example on how to make it print in chat [SeriousRP] You have received $amount for being a citizen of paralake city! (Or something like that)

It’s a very simple system to make. When the player first spawns (PlayerInitialSpawn), create an infinite timer (reps=0) that can be uniquely identified by some player id, eg, ply:SteamID64() or just ply:SteamID() (it’s probably a bad idea to use UniqueID because it has performance issues apparently), such as
[lua]“Salary_” … ply:SteamID64()[/lua]
Inside the callback function, first of all add an IsValid( ply ) check to ensure the player is still valid when the callback is called and has not disconnected. If they have, remove the timer with timer.Remove.
Otherwise, find the job salary by indexing your jobs table for the salary and give it to the player.
I suggest you restart the timer when the player changes jobs.

[lua]local job = {
[1] = 3000,
[2] = 100
}

function SalaryInitialize()

timer.Create( "Salary", 120, 0, Salary )

end
hook.Add( “Initialize”, “SalaryTimerInit”, SalaryInitialize )

function Salary( )
for k,ply in pairs(player.GetAll())
ply:AddMoney(job[ply:GetJobID])
ply:PrintMessage(HUD_PRINTTALK, “[SeroiusRP] You have received” …job[ply:GetJobID]… “Pokédollars for being a citizen of Viridian City!”)
end
end
[/lua]
pseudocode, but you should get the idea.

I get the idea, but will that code actually work? If so thanks alot!

ewwwww timers per client, yuck.

Why? It makes sense when you’re giving money to players depending on their role. You’d want it to be independent for each player so that they actually have to spend time playing to get the reward. It’s only pointless when you’ve got such a mediocre delay (like 15-30 seconds) between payouts.

Anyone know the error?

[LUA]local job = {
[1] = 50,
[2] = 250
}

function SalaryInitialize()

timer.Create( "Salary", 10, 0, Salary )

end
hook.Add( “Initialize”, “SalaryTimerInit”, SalaryInitialize )

function Salary( ply )
for k,ply in pairs(player.GetAll())
ply:AddMoney(job[ply:GetJobID])
ply:PrintMessage(HUD_PRINTTALK, “[SeriousRP] You have received $” …job[ply:GetJobID]… " for being a citizen of Viridian City!")
end
end[/LUA]

error:


 
 [ERROR] gamemodes/seriousrp/gamemode/jobrelated.lua:16: 'do' expected near 'ply'

  1. unknown - gamemodes/seriousrp/gamemode/jobrelated.lua:0


[editline]5th October 2014[/editline]

My delay is gonna be 1 minute, but 10 seconds for testing purpose…


local job = { 
[1] = 50,
[2] = 250
}


function SalaryInitialize()

	timer.Create( "Salary", 10, 0, Salary )

end
hook.Add( "Initialize", "SalaryTimerInit", SalaryInitialize )

function Salary( ply )
	for k,ply in pairs(player.GetAll()) do
             ply:AddMoney(job[ply:GetJobID])
             ply:PrintMessage(HUD_PRINTTALK, "[SeriousRP] You have received $" ..job[ply:GetJobID].. " for being a citizen of Viridian City!")
end
end

Edit:

But it doesn’t matter that it gives a newly joined player 50$ same time as the other palyers, not that big of a deal.

You’ve forgotten parentheses after ply:GetJobID
And I doubt that method even exists, he’s probably not made it

Snip readt wrong

You can always save CurTime to the client when they join, then have a global timer run every one or few minutes, looping through players checking if their saved CurTime + jobtime >= CurTime, if true then update their saved CurTime to current CurTime, then give payout,
Obviously there will be some delays for certain people, but is that really a big deal, the delays would be too small to notice.
If you have a 50 person server, this solution works much better.

Wait SalaryInitialize? Is that a method? Or what will it not worK?

[editline]5th October 2014[/editline]

Why am i getting this error?




[ERROR] gamemodes/seriousrp/gamemode/jobrelated.lua:16: 'do' expected near 'ply'

  1. unknown - gamemodes/seriousrp/gamemode/jobrelated.lua:0



Code:

[LUA]
local job = {
[1] = 50,
[2] = 250
}

function SalaryInitialize()

timer.Create( "Salary", 10, 0, Salary )

end
hook.Add( “Initialize”, “SalaryTimerInit”, SalaryInitialize )

function Salary( ply )
for k,ply in pairs(player.GetAll())
ply:AddMoney(job[ply:GetJobID()])
ply:PrintMessage(HUD_PRINTTALK, “[SeriousRP] You have received $” …job[ply:GetJobID]… " for being a citizen of Viridian City!")
end
end
[/LUA]

[editline]5th October 2014[/editline]

This thread is getting very big lol, if possibly could anyone just provide me with a working example that looks clean and will make it easy to add new jobs to the salary list? LIke the code i had but working Thanks.

This is something I just came up with, it’s 1AM though.



local jobUpdateTime = 180
local jobSalary = {}

function AddJobSalary( team, time, amount )
    jobSalary[team] = { time, amount }
end

timer.Create( "GiveYaMoney", jobUpdateTime, 0, function()
    for k,v in pairs(player.GetAll()) do
        if ply.earlyPayout then
            local time = jobSalary[ply:Team()][1]
            if time < jobUpdateTime then
                ply:setDarkRPVar( "money", ply:getDarkRPVar("money") + (jobSalary[ply:Team()][2] * (time / jobUpdateTime)) )
            else
                ply:setDarkRPVar( "money", ply:getDarkRPVar("money") + (jobSalary[ply:Team()][2] * (jobUpdateTime / time)) )
            end
            ply.earlyPayout = false
            ply.savedTime = CurTime()
            continue
        end
        if ply.savedTime + jobSalary[ply:Team()][1] <= CurTime() then
            ply:setDarkRPVar( "money", ply:getDarkRPVar("money") + (jobSalary[ply:Team()][2] * ((ply.savedTime + jobSalary[ply:Team()][1]) / CurTime()))) // Make sure they get their moneys worth.
        end
    end
end )

hook.Add("PlayerAuthed", "aaaa", function( ply )
    ply.savedTime = CurTime()
    ply.earlyPayout = true
end)

AddJobSalary( TEAM_CITIZEN, 60, 100 ) // How to add jobs, first arg is team, second arg is time to wait for payout, third arg is amount of cash after payout.


Probably mess with the earlyPayout part a little bit and you could get yourself a nice set up.

The TEAM_CITIZEN looks like darkrp, its a gamemode from scratch will it work using TEAM_ whateve.r

[editline]5th October 2014[/editline]

Yeah, thats for darkrp, which im not using.

it’s pseudocode i wrote in 2 minutes without checking everything.
I assumed you did some meta work before. You need an Function for AddMoney and GetMoney etc, since i used some Dummy Functions, to get the idea.

FindMetaTable with Player to make an Function to Add Money and an Check for the Job of the Player.
add an do for the for-loop and it should work.

Can anyone give me a fully working version? My functions are:

ply:GetMoney()
ply:SetMoney()
ply:AddMoney()
ply:TakeMoney()

You have been given multiple examples. Understand what they are doing, then adapt it for your own uses. This isn’t how you learn how to code.

Holy fucking shit you are dense.

That was an example, change it to what you want, change TEAM_CITIZEN to whatever fucking team id you want.
And change the darkrp money parts to your functions. It isn’t hard, I was using that as an example.

I can’t believe this right now.



local jobUpdateTime = 180
local jobSalary = {}

function AddJobSalary( team, time, amount )
    jobSalary[team] = { time, amount }
end

timer.Create( "GiveYaMoney", jobUpdateTime, 0, function()
    for k,v in pairs(player.GetAll()) do
        if ply.earlyPayout then
            local time = jobSalary[ply:Team()][1]
            if time < jobUpdateTime then
                ply:AddMoney(jobSalary[ply:Team()][2] * (time / jobUpdateTime))
            else
                ply:AddMoney(jobSalary[ply:Team()][2] * (jobUpdateTime / time))
            end
            ply.earlyPayout = false
            ply.savedTime = CurTime()
            continue
        end
        if ply.savedTime + jobSalary[ply:Team()][1] <= CurTime() then
             ply:AddMoney(jobSalary[ply:Team()][2] * ((ply.savedTime + jobSalary[ply:Team()][1]) / CurTime())) // Make sure they get their moneys worth.
        end
    end
end )

hook.Add("PlayerAuthed", "DenseShit", function( ply )
    ply.savedTime = CurTime()
    ply.earlyPayout = true
end)

AddJobSalary( YOUR_FUCKING_STUPID_TEAM_ID, 60, 100 ) // How to add jobs, first arg is team, second arg is time to wait for payout, third arg is amount of cash after payout.


Holy crap am I like a Lua god, how did I do that? That was so hard! It was like 3 lines I changed, omg, holy shit. I need to go outside for a little bit too cool down, my brain is in overdrive. How did I do that.

I know I’m a bit late and might come across as a bit of an asshole, but please please please can coders use this as an example of why not to spoon-feed users, and people see this as why it’s very important to read through code written for you?

Like, in this thread, someone wrote code in which ‘do’ was missed from a k, v pairs loop. It would take two seconds to spot this error if you actually tried to understand it, and if somehow it didn’t, you aren’t at a level where you should be trying full gamemodes and maybe want to spend some time going over wiki pages

This isn’t the first time it’s happened and it won’t be the last but it’s beyond frustrating to see it occur over and over. 99% of the time when you write a large block of code for someone, they will not read it or try to understand it or do their own learning. They will, sadly, just copy and paste it