void sandbox_ObjectFunction_Think()
{SELFPARAM();
- entity e;
-
// decide if and how this object can be grabbed
if(autocvar_g_sandbox_readonly)
self.grab = 0; // no grabbing
// Object owner is stored via player UID, but we also need the owner as an entity (if the player is available on the server).
// Therefore, scan for all players, and update the owner as long as the player is present. We must always do this,
// since if the owning player disconnects, the object's owner should also be reset.
- FOR_EACH_REALPLAYER(e) // bots can't have objects
- {
- if(self.crypto_idfp == e.crypto_idfp)
+
+ // bots can't have objects
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+ if(self.crypto_idfp == it.crypto_idfp)
{
- self.realowner = e;
+ self.realowner = it;
break;
}
self.realowner = world;
- }
+ ));
self.nextthink = time;
sandbox_ObjectAttach_Remove(e); // detach child objects
// if the object being removed has been selected for attachment by a player, unset it
- entity head;
- FOR_EACH_REALPLAYER(head) // bots can't have objects
- {
- if(head.object_attach == e)
- head.object_attach = world;
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.object_attach == e, LAMBDA(it.object_attach = world));
if(e.material) { strunzone(e.material); e.material = string_null; }
if(e.crypto_idfp) { strunzone(e.crypto_idfp); e.crypto_idfp = string_null; }
void play2team(float t, string filename)
{
if (autocvar_bot_sound_monopoly) return;
- entity head;
- FOR_EACH_REALPLAYER(head)
- {
- if (head.team == t) play2(head, filename);
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.team == t, LAMBDA(play2(it, filename)));
}
void play2all(string samp)
activator.chlevel_targ = self;
- entity head;
int plnum = 0;
int realplnum = 0;
// let's not count bots
- FOR_EACH_REALPLAYER(head)
- {
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
++realplnum;
- if(head.chlevel_targ == self)
+ if(it.chlevel_targ == self)
++plnum;
- }
+ ));
if(plnum < ceil(realplnum * min(1, self.count))) // 70% of players
return;
}
// NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(yourcode));
// NOTE: FOR_EACH_SPEC deprecated! Use the following instead: FOREACH_CLIENT(IS_SPEC(it), LAMBDA(yourcode));
// NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), LAMBDA(yourcode));
-#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if (IS_PLAYER(v))
+// NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(yourcode));
#define FOREACH_CLIENT(cond, body) \
MACRO_BEGIN { \
void botframe_autowaypoints()
{
- entity p;
- FOR_EACH_REALPLAYER(p)
- {
- if(p.deadflag)
- continue;
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.deadflag == DEAD_NO, LAMBDA(
// going back is broken, so only fix waypoints to walk TO the player
//botframe_autowaypoints_fix(p, false, botframe_autowaypoints_lastwp0);
- botframe_autowaypoints_fix(p, true, botframe_autowaypoints_lastwp1);
+ botframe_autowaypoints_fix(it, true, botframe_autowaypoints_lastwp1);
//te_explosion(p.botframe_autowaypoints_lastwp0.origin);
- }
+ ));
if (autocvar_g_waypointeditor_auto >= 2) {
botframe_deleteuselesswaypoints();
string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix;
float flood;
var .float flood_field;
- entity head;
float ret;
string privatemsgprefix = string_null; float privatemsgprefixlen = 0;
{
sprint(source, sourcemsgstr);
dedicated_print(msgstr); // send to server console too
- FOR_EACH_REALCLIENT(head)
- if(head != source)
- if(head.active_minigame == source.active_minigame)
- sprint(head, msgstr);
+ FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame, LAMBDA(sprint(it, msgstr)));
}
else if(teamsay > 0) // team message, only sent to team mates
{
dedicated_print(msgstr); // send to server console too
if(sourcecmsgstr != "")
centerprint(source, sourcecmsgstr);
- FOR_EACH_REALPLAYER(head) if(head.team == source.team)
- if(head != source)
- {
- sprint(head, msgstr);
- if(cmsgstr != "")
- centerprint(head, cmsgstr);
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team, LAMBDA(
+ sprint(it, msgstr);
+ if(cmsgstr != "")
+ centerprint(it, cmsgstr);
+ ));
}
else if(teamsay < 0) // spectator message, only sent to spectators
{
sprint(source, sourcemsgstr);
dedicated_print(msgstr); // send to server console too
- FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head))
- if(head != source)
- sprint(head, msgstr);
+ FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
}
else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players
{
sprint(source, sourcemsgstr);
dedicated_print(msgstr); // send to server console too
- FOR_EACH_REALCLIENT(head)
- if(head != source)
- sprint(head, msgstr);
+ FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr)));
}
else
bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too.
{
case CMD_REQUEST_COMMAND:
{
- entity client;
string reason = argv(1);
float i = 0;
- FOR_EACH_REALPLAYER(client)
- {
- if (client.caplayer) client.caplayer = 0;
- WITH(entity, self, client, PutObserverInServer());
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+ if (it.caplayer) it.caplayer = 0;
+ WITH(entity, self, it, PutObserverInServer());
++i;
- }
+ ));
if (i) bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
else LOG_INFO("No players found to spectate.\n");
return;
{
case CMD_REQUEST_COMMAND:
{
- entity client;
float i = 0;
float argc;
- FOR_EACH_CLIENT(client)
- {
- argc = tokenize_console(strcat("defer_clear ", ftos(etof(client))));
+ FOREACH_CLIENT(true, LAMBDA(
+ argc = tokenize_console(strcat("defer_clear ", ftos(etof(it))));
GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
++i;
- }
+ ));
if (i) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); // should a message be added if no players were found?
return;
}
case CMD_REQUEST_COMMAND:
{
blockSpectators = 1;
- entity plr;
- FOR_EACH_REALCLIENT(plr) // give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
- {
- if (IS_SPEC(plr) || IS_OBSERVER(plr))
+ // give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
+ FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, LAMBDA(
+ if(!it.caplayer)
{
- if (!plr.caplayer)
- {
- plr.spectatortime = time;
- Send_Notification(NOTIF_ONE_ONLY, plr, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
- }
+ it.spectatortime = time;
+ Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
}
- }
+ ));
bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
return;
}
{
if (teamplay)
{
- entity tmp_player;
int i;
float x, t_teams, t_players, team_color;
// count the total amount of players and total amount of teams
t_players = 0;
t_teams = 0;
- FOR_EACH_CLIENT(tmp_player)
- if (IS_PLAYER(tmp_player) || tmp_player.caplayer)
- {
- CheckAllowedTeams(tmp_player);
+ FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
+ CheckAllowedTeams(it);
if (c1 >= 0) t_teams = max(1, t_teams);
if (c2 >= 0) t_teams = max(2, t_teams);
if (c4 >= 0) t_teams = max(4, t_teams);
++t_players;
- }
+ ));
// build a list of the players in a random order
- FOR_EACH_CLIENT(tmp_player)
- if (IS_PLAYER(tmp_player) || tmp_player.caplayer)
- {
+ FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA(
for ( ; ; )
{
i = bound(1, floor(random() * maxclients) + 1, maxclients);
}
else
{
- shuffleteams_players[i] = etof(tmp_player);
+ shuffleteams_players[i] = etof(it);
break;
}
}
- }
+ ));
// finally, from the list made earlier, re-join the players in different order.
for (int i = 1; i <= t_teams; ++i)
void race_SendTime(entity e, float cp, float t, float tvalid)
{
float snew, l;
- entity p;
if(g_race_qualifying)
t += e.race_penalty_accumulator;
race_checkpoint_recordholders[cp] = strzone(e.netname);
if(g_race_qualifying)
{
- FOR_EACH_REALPLAYER(p)
- if(p.race_checkpoint == cp)
- race_SendNextCheckpoint(p, 0);
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.race_checkpoint == cp, LAMBDA(race_SendNextCheckpoint(it, 0)));
}
}
}