Hello,
I got bored so I decided to write this short "tutorial" about "while" loop.
The while loop will be repeating as long as it's condition is false (eg. 1 > 0 = true, stop; 1 < 0 = false, continue executing).
The main syntax of the while loop is:while ( condition )
{
code to execute
}
And below are some samples of use:- Setting all players health to 100:local x = 0;
while ( x < GetPlayers() )
{
local plr = FindPlayer( x );
if ( plr )
{
plr.Health = 100;
}
x++;
}
- Teleporting all players somewhere:local x = 0;
while ( x < GetPlayers() )
{
local plr = FindPlayer( x );
if ( plr )
{
plr.Pos = Vector( 0, 0, 0 );
}
x++;
}
- Fixing every vehicle on the server:local x = 0;
while ( x < GetVehicleCount() )
{
local veh = FindVehicle( x );
if ( veh )
{
veh.Fix();
}
x++;
}
Good luck with looping
.
PS. Samples weren't tested, so if there's something wrong, please inform me.