Is there any way to apply a function on all. I mean for example I create /kickall command for Kicking all players ( :P ) now in function KickPlayer( player ) so it applies to 1 player, and I want to use it on all, like announceall applies to all...
For example: Creating a /attackoffall will use Player.CanAttack =false; and now I want it to apply to all players...
Waiting for replies...
You can make this using a loop.
else if ( cmd == "attackoffall" )
{
for( local i = 0, i_plr; i < GetMaxPlayers(); i++ )
{
i_plr = FindPlayer( i );
if( i_plr && i_plr.IsSpawned )
{
i_plr.CanAttack = false;
}
}
Message( "** Admin " + player.Name + " have disabled the attack for all the players." );
}
Which can be improved in this way
else if ( cmd == "attackoffall" )
{
local maxplayer = GetMaxPlayers();
for( local i = 0, i_plr; i <= maxplayer; ++i )
{
i_plr = FindPlayer( i );
if( i_plr && i_plr.IsSpawned )
{
i_plr.CanAttack = false;
}
}
Message( "** Admin " + player.Name + " have disabled the attack for all the players." );
}
Notice the changes to the l00p
This is a bit off topic but I would like to know how can I create a loop for pickups and vehicles?
For pickups
for(local i = 0; i < GetPickupCount(); i++)
For vehicles:-
for(local i = 0; i < GetVehicleCount(); i++)
Thanks!
Quote from: KAKAN on Oct 16, 2015, 08:33 AMFor pickups
for(local i = 0; i < GetPickupCount(); i++)
For vehicles:-
for(local i = 0; i < GetVehicleCount(); i++)
Please don't use a function like that. Let's say that you have 2000 pickups or 1000 vehicles. That means calling GetPickupCount() 2000 times and GetVehicleCount() 1000 times. For the love of god. Don't use functions in loop condition.
for(local i = 0, count = GetPickupCount(); i < count; ++i)
{
// ...
}
for(local i = 0, count = GetVehicleCount(); i < count; ++i)
{
// ...
}