Shadow
« on: November 14, 2012, 02:36:44 pm »
This is a loop-through method using arrays tested by me, ( with myself... duh.. )! The good thing is that this method loops only through the valid player instances, and not some unfilled slot ( like for( local i = 0; i < GetMaxPlayers(); i++ ) ).
Also, morphine shown me a method using constructor and classes, but I thought this would be easier to teach, so here it is.
I will show it in an example:
playerson <- [];
function onPlayerJoin( player )
{
playerson.push( player.ID );
}
function onPlayerPart( player, reason )
{
playerson.remove( player.ID );
}
function HealAll()
{
foreach(playerid, val in playerson )
{
print( "CLIENT NAME: " + FindPlayer(playerid).Name );
}
}
function onPlayerCommand( player, cmd, params )
{
if( cmd == "printall" )
{
HealAll();
}
}
Output:
CLIENT NAME: yournamegoeshere
CLIENT NAME: yournamegoeshere
etc..
What happens if there is no player in the server ?
Nothing will happen, no message from the server.
Can be modified at your will, some credits won't hurt anyone.
« Last Edit: November 14, 2012, 02:40:40 pm by Shadow »
Logged
Cannot rate own posts