Make methods to happen for every player

I have found this: http://wiki.garrysmod.com/page/player/GetAll but im new with lua

I want to make something to print for every players, for example player:PrintMessage to happen to every player online.

for k,v in pairs( player.GetAll() ) do

v:PrintMessage( HUD_PRINTTALK, “hello” )

end

Can you explain the for loop for me? I have never understood the k,v in pairs stuff

for key, value in pairs( player.GetAll() )

print( key, value:Nick() )

end

output: 1 Invule. Where the KEY is 1 and the VALUE is Invule

edit: You can also read about it here. http://wiki.garrysmod.com/page/Global/pairs

k it’s the player index number, the first player to join normally will be 1, and the last player will be like 4 or 5 (In the case there are 4 or 5 players) and v it’s the player itself

it’s for key, values, key it’s the index of the array:
[lua]
local tbl = {apple=“ok”,banana=“rock”}
local ntbl = {"ok,“rock”}

for k,v in pairs(tbl) do
MsgN(k…" “…v)
end
for k,v in pairs(ntbl) do
MsgN(k…” "…v)
end

//Will print:
//apple ok
//banana rock
//1 ok
//2 rock
[/lua]

Thanks, you explained it very good :slight_smile: