General > Developers Corner

Help with a reward system

(1/1)

Digital Spit:
I was messing around with ways to reward players for staying in game and helping us reach our goal of reaching our player cap.

How can I get this to run automatically? I originally had it in a timer to run every 4 minutes, but I was receiving lua errors (though it would run fine)

My question is how can I get this to run without locking it into a timer?


--- Code: ---local Players = player.GetAll()
for i = 1, table.Count(Players) do
local ply = Players[i]
if table.Count(Players) <= 5 then
ply:addMoney( 150 )
ply:ChatPrint( "[TPG] " .. i .. "/40 players connected - initializing cash give-away.")
elseif table.Count(Players) >= 20 then
ply:addMoney( 200 )
ply:ChatPrint( "[TPG] " .. i .. "/40 players connected - initializing cash give-away.")
elseif table.Count(Players) >=30 then
ply:addMoney( 250 )
ply:ChatPrint( "[TPG] " .. i .. "/40 players connected - initializing & upgrading cash give-away.")
elseif table.Count(Players) == 40 then
ply:addMoney(300)
ply:ChatPrint( "[TPG] " .. i .."/40 players connected - initializing & upgrading cash give-away.")
end
end
--- End code ---

JamminR:
Use hooks.
Playerjoin or connect or spawn.
I forget exactly which.
Timer would still be best for making sure players stayed long enough after joining though.
Really should figure out why you were getting the error.

Digital Spit:

--- Quote from: JamminR on June 14, 2014, 12:43:15 AM ---Use hooks.
Playerjoin or connect or spawn.
I forget exactly which.
Timer would still be best for making sure players stayed long enough after joining though.
Really should figure out why you were getting the error.

--- End quote ---

Will do JamminR, thanks for the help!

Navigation

[0] Message Index

Go to full version