• Gamemode Scripting - Spotty Timer Behavior
    3 replies, posted
Hey all, I've run into an issue with a feature I'm trying to implement for a gamemode and haven't quite found a solution to it yet. While I feel I've got the right idea, my impression is that I might be simply implementing this into the incorrect location rather than having the wrong approach entirely. The gist of my problem is that I'm looking to implement a timer that awards players a passive amount of "money" given cVar numbers, similar to DarkRP. That's not the issue, rather, my timer exhibits odd behavior. Here's my code: if (MatchHasBegun) then -- Start the timer when the match begins timer.Create( "moneyTimer", (GetConVar("ctf_passivetimer"):GetFloat()), 0, function() ply:SetNWInt("playerMoney", ply:GetNWInt("playerMoney") + (GetConVar("ctf_passiveincome"):GetFloat())) end) -- Passive award timer net.Start("RestrictMenu") net.Send(ply) else net.Start("UnrestrictMenu") net.Send(ply) end Right now this is in the GM:PlayerSpawn(ply) function in the serverside init.lua. When testing with a friend, I found this gave just me (the host) money on the determined interval, but not the other player. So, my next test was as follows: if(MatchHasBegun) then for k,v in pairs(player.GetAll()) do -- Make a timer for each individual player timer.Create( "moneyTimer", (GetConVar("ctf_passivetimer"):GetFloat()), 0, function() v:SetNWInt("playerMoney", v:GetNWInt("playerMoney") + (GetConVar("ctf_passiveincome"):GetFloat())) end) -- Passive award timer end end Strangely, the converse occurred, where the other player got money, but not myself. Am I making a mistake putting this into the serverside init file? Should I do it on the clientside instead? If so, where? I did try putting this into the GM:Think() function in the serverside init file, but that didn't help, either - and I had suspected it wouldn't anyway, but I wanted to test everything. Also, I apologize for any strange formatting, the code feature for forum posts isn't very cooperative. Thanks for the input.
Would this work ( your right typing code in here is a pain ) timer.Create( "moneyTimer" .. ply:UserID ( ) 1, 10, (GetConVar("ctf_passivetimer"):GetFloat()), 0, function()
Hey RScott, I wasn't able to produce any different results. It gives all players except me, the host, money on the passive interval. Any other ideas?
The answer for someone else looking to make a timer for all players turned out to be to put it into a server side script and control it for the entire game... see if this would be any help... HERE For the meantime I will keep looking and see if I can find something a bit better...
Sorry, you need to Log In to post a reply to this thread.