Anyone has an idea why this is not working?
[LUA]
local jobUpdateTime = 180
local jobSalary = {}
function AddJobSalary( team, time, amount )
jobSalary[team] = { time, amount }
end
timer.Create( "SalaryTimer", 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", "SalaryGiveHook", function( ply )
ply.savedTime = CurTime()
ply.earlyPayout = true
end)
// How to add jobs, first arg is team, second arg is time to wait for payout, third arg is amount of cash after payout.
AddJobSalary( 1, 10, 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.
AddJobSalary( 2, 10, 110 )
AddJobSalary( 3, 10, 120 )
AddJobSalary( 4, 10, 130 )
AddJobSalary( 5, 10, 140 )
AddJobSalary( 6, 10, 150 )
AddJobSalary( 7, 10, 160 )
AddJobSalary( 8, 10, 170 )
AddJobSalary( 9, 10, 180 )
AddJobSalary( 10, 10, 190 )
[/LUA]
No we have fucking no idea.
Tell us the errors and try debugging yourself with prints.
[QUOTE=AnonTakesOver;46175923]No we have fucking no idea.
Tell us the errors and try debugging yourself with prints.[/QUOTE]
Holy shit chill down....
It says it doesn't know what ply is, i tried adding ( ply ) ot the function with the timer but it wouildnt work.
Change this:
[LUA]for k,v in pairs(player.GetAll()) do[/LUA]
To:
[LUA]for _, ply in pairs(player.GetAll()) do[/LUA]
[QUOTE=LocoJoker;46180236]Change this:
[LUA]for k,v in pairs(player.GetAll()) do[/LUA]
To:
[LUA]for _, ply in pairs(player.GetAll()) do[/LUA][/QUOTE]
Ill try when i get home thank you!
[editline]8th October 2014[/editline]
[QUOTE=xAl3xTh3K1nG;46180375]Ill try when i get home thank you![/QUOTE]
Wai, so i put for k, v ply in pairs(player.GetAll()) do
or for _, ply in pairs(player.GetAll()) do
[QUOTE=xAl3xTh3K1nG;46180375]kek[/QUOTE]
[lua]for _, ply in pairs(player.GetAll()) do
//do shit
end[/lua]
in an for loop you are passing 2 args. Key and Value of the Table.
since we are using Playerdata, it is commenly shorted with "ply", but you could also name it "sandrabullock". It is just an variable name.
so "for k,v in pairs(player.GetAll()) do" would refenrence all players that are currently online. with v:Function() you refenrence the User.
Please try to understand the code, not just copy paste, or you will never learn anything from it.
The Wiki is a good Place to look up functions.
[QUOTE=Tomelyr;46182842]in an for loop you are passing 2 args. Key and Value of the Table.
since we are using Playerdata, it is commenly shorted with "ply", but you could also name it "sandrabullock". It is just an variable name.
so "for k,v in pairs(player.GetAll()) do" would refenrence all players that are currently online. with v:Function() you refenrence the User.
Please try to understand the code, not just copy paste, or you will never learn anything from it.
The Wiki is a good Place to look up functions.[/QUOTE]
I do understand some code if not thats why i ask for help :) Thanks btw, i lookup sometimes but cant always find, i lookup on mauritz.tv, glua.me <--- good pages :)
The mauritz.tv wiki is outdated and GLua Docs are useful but it's just a mirror of the official wiki.
But still, if you're gonna have variables in k,v loop, make sure the k,v variables are the same as the code below or the ply variables match the k,v variables.
(Honestly the code you have looks like it was copy-pasted)
[QUOTE=LUModder;46193929]The mauritz.tv wiki is outdated and GLua Docs are useful but it's just a mirror of the official wiki.
But still, if you're gonna have variables in k,v loop, make sure the k,v variables are the same as the code below or the ply variables match the k,v variables.
(Honestly the code you have looks like it was copy-pasted)[/QUOTE]
It was code I gave him, I must of accidentally not changed the for loop, my bad.
[QUOTE=LUModder;46193929]The mauritz.tv wiki is outdated and GLua Docs are useful but it's just a mirror of the official wiki.
But still, if you're gonna have variables in k,v loop, make sure the k,v variables are the same as the code below or the ply variables match the k,v variables.
(Honestly the code you have looks like it was copy-pasted)[/QUOTE]
Yep it is, i need something to start off with.
Sorry, you need to Log In to post a reply to this thread.