Vice Underdogs

Scripting => Script Showroom => Topic started by: Shadow on November 14, 2012, 02:36:44 pm

Title: Player loop, new method
Post by: Shadow on November 14, 2012, 02:36:44 pm
Quote from:  Vice City Multiplayer Unofficial Forums
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:

Code: [Select]
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:

Quote
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.
Title: Re: Player loop, new method
Post by: WiLsOn on November 14, 2012, 03:43:09 pm
Looks nice  :thumbsup: