Garry's Mod Wiki


thread coroutine.create( function func )


Creates a coroutine of the given function.


1 function func
The function for the coroutine to use.


1 thread


Display the location of each player in an endless loop, but only one player per frame.

local function displayer() local players while true do -- endless loop: you must guarantee that coroutine.yield() is always called! players = player.GetAll() if not next( players ) then -- empty table coroutine.yield() -- guarantee a pause in coroutine even with an empty table else for _, ply in ipairs( players ) do coroutine.yield() -- We yield here so what you may do next will start immediatly when this for loop finishes. if IsValid( ply ) then -- The player ply may be disconnected now! print( ply:Nick(), "is located at", ply:GetPos() ) end end end end end local co hook.Add( "Think", "DisplayPlayersLocation", function() if not co or not coroutine.resume( co ) then co = coroutine.create( displayer ) coroutine.resume( co ) end end )
Custom Nickname is located at 10.102 59.04 -100.96 SuperBoss is located at 55.85 1209.11 -100.96 Custom Nickname is located at 11.126 51.92 -100.96 ...

Page Links

Special Pages



Render Time: 55ms

DB GetPage 25
Generate Html 6
SaveChanges (1) 9
Render Body 0
Render Sidebar 12