Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Zihad-VCMP on Oct 16, 2015, 04:51 AM

Title: Apply to All Question...
Post by: Zihad-VCMP on Oct 16, 2015, 04:51 AM
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...
Title: Re: Apply to All Question...
Post by: Mashreq on Oct 16, 2015, 05:10 AM
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." );
 }
Title: Re: Apply to All Question...
Post by: EK.IceFlake on Oct 16, 2015, 05:17 AM
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
Title: Re: Apply to All Question...
Post by: Xmair on Oct 16, 2015, 06:09 AM
This is a bit off topic but I would like to know how can I create a loop for pickups and vehicles?
Title: Re: Apply to All Question...
Post by: KAKAN on Oct 16, 2015, 08:33 AM
For pickups
for(local i = 0; i < GetPickupCount(); i++)For vehicles:-
for(local i = 0; i < GetVehicleCount(); i++)
Title: Re: Apply to All Question...
Post by: Xmair on Oct 16, 2015, 09:07 AM
Thanks!
Title: Re: Apply to All Question...
Post by: . on Oct 17, 2015, 01:49 PM
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)
{
// ...
}