login
March 28, 2024, 12:43:34 pm

Author Topic: Player loop, new method  (Read 1224 times)

0 Members and 1 Guest are viewing this topic.

Shadow

  • Guest
Player loop, new method
« 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.
« Last Edit: November 14, 2012, 02:40:40 pm by Shadow »
Cannot rate own posts


WiLsOn

  • Crazy Man
  • *****
  • *
  • *
  • *
  • Posts: 5488
  • Country: 00
  • First in battle last in retreat.
    • View Profile
Re: Player loop, new method
« Reply #1 on: November 14, 2012, 03:43:09 pm »
Looks nice  :thumbsup:
Agree Disagree Funny Winner Pwnt Informative Friendly Useful Optimistic Artistic Late Brain Donor