• Timer for setting teams wont work
    13 replies, posted
[code]function SetTeamz(ply) timer.Simple(25, function() if ply:Team()== 2 then ply:SetTeam(3) ply:Freeze(false) ply:Kill() elseif ply:Team()== 3 then ply:SetTeam(2) ply:Freeze(false) ply:Kill() elseif ply:Team()== 1 then ranteam = math.Rand(2, 3) ply:SetTeam(ranteam) ply:Kill() wait(1) ply:Spawn() end end) end hook.Add('Shit...', 'SetTeamz', function(ply) ply:print('kill me please...') end) [/code] Nothing happens, no errors, it just doesn't do anything. :/ [editline]24th August 2014[/editline] I've tried almost everything, I changed timer.Simple to timer.Create, and set it up for it. Like timer.Create('Fuck..', 20, 0, function() Myshit code here end)
Okay, first of all 'Ewwwwwwwwwwwwww'. Now, onto your issue: Your function 'SetTeamz' isn't being called, so your timer is never going to run. I see your trying to do something in that 'Shit...' hook; however I suggest you read up on how that works. hook.add('*What you want to hook your function to*', '*The ID of your hook*', *The function you want to run when the hook is called*) So, first of all you want to figure out what you want to hook to. And then you want to change your hook to the following: [code]hook.Add('*HookIWant*', 'SetTeamz', SetTeamz)[/code] That should work (Assuming your timer's code is correct).
When should it happen? You can do it on PlayerSpawn, or in a menu, or where-ever... Do those team even exist? What game-mode is this for?
[QUOTE=Acecool;45785006]When should it happen? You can do it on PlayerSpawn, or in a menu, or where-ever... Do those team even exist? What game-mode is this for?[/QUOTE] Random gamemode im making, and yes, I set them up.
Are you calling it Clientside or Serverside?
[QUOTE=Acecool;45785193]Are you calling it Clientside or Serverside?[/QUOTE] Server side.
SetTeamz is never ran.
[QUOTE=HumbleTH;45785965]SetTeamz is never ran.[/QUOTE] No really?
[code] function SetTeamz(ply) if ply:Team()== 2 then ply:SetTeam(3) ply:Freeze(false) ply:Kill() elseif ply:Team()== 3 then ply:SetTeam(2) ply:Freeze(false) ply:Kill() elseif ply:Team()== 1 then ranteam = math.Rand(2, 3) ply:SetTeam(ranteam) ply:Kill() ply:Spawn() end end timer.Create('SetTheFckingTeam', 25, 0, SetTeamz) // Fuck you timers. hook.Add('Think', 'SetTeamzHook', SetTeamz) // Maybe it's think?!? [/code] Does this look OK?
Just make the teams get set in a GM:PlayerInitialSpawn() function or something, if you're making a gamemode. I don't know why you would be changing the teams for any other reason. You really should never have to use think, you can just make a pseudo think timer, which is less expensive. [code] function GM:PlayerInitialSpawn(ply) local randomteam = math.random(1, 3) ply:SetTeam(randomteam) ply:Kill() ply:Spawn() end [/code] I'm not sure what you're trying to achieve by moving the teams around a lot like that.
[QUOTE=Lolcats;45792018]Just make the teams get set in a GM:PlayerInitialSpawn() function or something, if you're making a gamemode. I don't know why you would be changing the teams for any other reason. You really should never have to use think, you can just make a pseudo think timer, which is less expensive. [code] function GM:PlayerInitialSpawn(ply) local randomteam = math.random(1, 3) ply:SetTeam(randomteam) ply:Kill() ply:Spawn() end [/code] I'm not sure what you're trying to achieve by moving the teams around a lot like that.[/QUOTE] I'm trying to make rounds, so at the end of every round (5 mins, I set the timer to 20 seconds so I didn't have to wait for it.) the players team gets changed.
[QUOTE=thekiller123;45792348]I'm trying to make rounds, so at the end of every round (5 mins, I set the timer to 20 seconds so I didn't have to wait for it.) the players team gets changed.[/QUOTE] Before you go any further, if I were you I'd invest in learning Lua basics.
[QUOTE=kila58;45792596]Before you go any further, if I were you I'd invest in learning Lua basics.[/QUOTE] :| Really? >.> I already know Lua basics... [code] function wait(waitTime) local timers = os.time() repeat until os.time() > timers + waitTime end [/code] Basic function for wait(). Happy now?
[QUOTE=thekiller123;45792611]:| Really? >.> I already know Lua basics... [code] function wait(waitTime) local timers = os.time() repeat until os.time() > timers + waitTime end [/code] Basic function for wait(). Happy now?[/QUOTE] Not really, you have no proper indentation and then you add a think hook that calls a function with a timer in it for setting teams? If you don't know how to call your code you are sort of at a loss here. But enough derailing, I'm out.
Sorry, you need to Log In to post a reply to this thread.