Apply to All Question...

Started by Zihad-VCMP, Oct 16, 2015, 04:51 AM

Previous topic - Next topic

Zihad-VCMP

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...

Mashreq

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." );
 }

EK.IceFlake

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

Xmair

This is a bit off topic but I would like to know how can I create a loop for pickups and vehicles?

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

KAKAN

For pickups
for(local i = 0; i < GetPickupCount(); i++)For vehicles:-
for(local i = 0; i < GetVehicleCount(); i++)
oh no

Xmair


Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

.

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)
{
// ...
}
.