Function only acts if players are connected.



function yepthing()
 if player connected >10 then --This isn't real code, I need to know what would go here.
     PrintMessage( HUD_PRINTTALK, "yep" )
else 
     PrintMessage( HUD_PRINTTALK, "nope" )

end
timer.Create("yepthingEmit", 1880, 0, yepthing) --yepthing every 30 minutes.


I need to know how to check if there are 10 or more players connected if so, it will say yep, if not it’ll say nope. Yes there is a cause for this.
I’m just giving an example. :smiley: Thanks!

[lua]#player.GetAll() > 10[/lua]



function entspawn()
	if #player.GetAll() > 1 then
          PrintMessage( HUD_PRINTTALK, "yep" )
       else
          PrintMessage( HUD_PRINTTALK, "nope" )
end
timer.Create("entspawnEmit", 5, 0, entspawn) 


This didn’t work, it just didn’t do anything, no errors. Im sorry about this. D:

Are you alone on the server?
Because you are putting “greater than 1”

Try this.



function entspawn()
	if #player.GetAll() >= 1 then
          PrintMessage( HUD_PRINTTALK, "yep" )
       else
          PrintMessage( HUD_PRINTTALK, "nope" )
       end
end
timer.Create("entspawnEmit", 5, 0, entspawn)


That won’t work either, I’m not sure what the problem is, there are no errors.

Updated the code in my last post. Try it.


function entspawn()
	if #player.GetAll() >= 1 then
          PrintMessage( HUD_PRINTTALK, "yep" )
       else
          PrintMessage( HUD_PRINTTALK, "nope" )
       end
end
hook.Add("PlayerSpawn", "spawnChecker", entspawn)

hmm?



MsgAll( "This code has loaded on the " .. SERVER and "server" or "client" )
hook.Add( "PlayerInitialSpawn", "facepunch", function( ply )

   if #player.GetAll() > 10 then
      PrintMessage( HUD_PRINTTALK, ply:Name() .. " has joined, and there are 11 or more players in the server currently." )
   else
      PrintMessage( HUD_PRINTTALK, ply:Name() .. " has joined, and there 10 players or less in the server currently." )
   end

end )


If you’re going to provide help, at least make it what he wants. In his original post, he wanted it on a timer not hooked to anything.

oh i didn’t see that

Clearly the issue he’s having is not with a timer, but instead with basic syntax and implementation. furthermore, unless you’re playing a server that never switches maps, your 30 minute timer will be wildly inaccurate due to the Lua environment being shut down at every map switch.

There are some obvious solutions to the issue, which I’m more than happy to help OP solve. However, I’d like to see him get a basic understanding of Lua syntax before we jump into more complex situations.

[editline]28th August 2014[/editline]

Also your code doesn’t even work. Do you realize that every function and every ‘if’ statement requires an ‘end’ statement in Lua? Doesn’t look like it. Also you’re crowding the global namespace with useless shit. Learn to use appropriate naming, proper use of variable scope, and atually have the most basic level of syntax mastery before you ‘attempt’ to help other people with their code.

Instead of acting like a know-it-all git you could provide the OP with the help he wanted, a function that does one thing if there are more than ten players and one thing if there isn’t. In his original post and his further replies he continues the use of a timer yet you provide him an example using the PlayerInitialSpawn hook? He has shown he lacks the knowledge required to do it and will obviously never be as good as somebody like yourself :v: but everybody starts somewhere.

What the fuck are you talking about? I clearly stated that I was more than happy to help OP, and I provided code that gave an example using hooks. Just because it wasn’t exactly what he wanted doesn’t mean he wouldn’t be able to change it himself to use a timer.



if SERVER then
    MsgAll( "This code has loaded on the server" )
else
    MsgN( "This code has loaded on the client" )
end

local check_time = 60
timer.Create("30minCheck", check_time, 0, function()
	
	if os.time() % 1800 <= check_time then
		
		if #player.GetAll() > 10 then
			PrintMessage( HUD_PRINTTALK, ply:Name() .. " has joined, and there are 11 or more players in the server currently." )
		else
			PrintMessage( HUD_PRINTTALK, ply:Name() .. " has joined, and there 10 players or less in the server currently." )
		end

	end

end )


check every minute if the number of minutes that have elapsed are within a minute of being a multiple of 30.
If you really want accuracy, just reduce the check time to even multiples of 60; eg. 30, 15, 10, 1.

Keep in mind that lower numbers will require more work for your server to do but as long as the check is this trivial it won’t make a noticeable difference.