Timer for setting teams wont work


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)


Nothing happens, no errors, it just doesn’t do anything. :confused:

[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:


hook.Add('*HookIWant*', 'SetTeamz', SetTeamz)

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?

Random gamemode im making, and yes, I set them up.

Are you calling it Clientside or Serverside?

Server side.

SetTeamz is never ran.

No really?



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?!?


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.



function GM:PlayerInitialSpawn(ply)


    local randomteam = math.random(1, 3)
    
    ply:SetTeam(randomteam)
    ply:Kill()
    ply:Spawn()


end


I’m not sure what you’re trying to achieve by moving the teams around a lot like that.

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.

Before you go any further, if I were you I’d invest in learning Lua basics.

:expressionless: Really? >.>

I already know Lua basics…



function wait(waitTime)
	local timers = os.time()
	repeat until os.time() > timers + waitTime
end


Basic function for wait().

Happy now?

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.