Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for iterators not being cleared after a GMX #448

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 101 additions & 86 deletions YSI_Data/y_foreach/y_foreach_iterators.inc
Original file line number Diff line number Diff line change
Expand Up @@ -361,110 +361,125 @@ stock Iter_All_Internal(const array[], size, value)
#if _FOREACH_CHARACTERS || _FOREACH_VEHICLES || _FOREACH_ACTORS
HOOK__ OnScriptInit()
{
#if _FOREACH_VEHICLES
Iter_Clear(Vehicle);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedVehicle);
#endif
for (new i = 1; i <= MAX_VEHICLES; ++i)
// The code that ran here to clear and setup the data inside
// Player/Vehicle etc. iterators now runs in the
// 'foreach_ClearIteratorsOnInit' timer function with a 0ms delay.
// This is because, it would appear, running the code here does not
// work after a GMX. Exact cause unknown.
// It works absolutely fine just after, though.

SetTimer("Iter_ClearIteratorsOnInit", 0, false);

return 1;
}
#endif

forward Iter_ClearIteratorsOnInit();
public Iter_ClearIteratorsOnInit()
{
#if _FOREACH_VEHICLES
Iter_Clear(Vehicle);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedVehicle);
#endif
for (new i = 1; i <= MAX_VEHICLES; ++i)
{
if (GetVehicleModel(i))
{
if (GetVehicleModel(i))
{
Iter_Add(Vehicle, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
Iter_Add(Vehicle, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
{
if (IsVehicleStreamedIn(i, j))
{
if (IsVehicleStreamedIn(i, j))
{
Iter_Add(StreamedVehicle[j], i);
}
Iter_Add(StreamedVehicle[j], i);
}
#endif
}
}
#endif
}
#endif
#if _FOREACH_ACTORS
Iter_Clear(Actor);
for (new i = 0; i != MAX_ACTORS; ++i)
}
#endif
#if _FOREACH_ACTORS
Iter_Clear(Actor);
for (new i = 0; i != MAX_ACTORS; ++i)
{
if (IsValidActor(i))
{
if (IsValidActor(i))
{
Iter_Add(Actor, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
Iter_Add(Actor, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
{
if (IsActorStreamedIn(i, j))
{
if (IsActorStreamedIn(i, j))
{
Iter_Add(StreamedActor[j], i);
}
Iter_Add(StreamedActor[j], i);
}
#endif
}
}
#endif
}
}
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedActor);
#endif
#endif
#if _FOREACH_CHARACTERS
#if _FOREACH_BOTS
Iter_Clear(Bot);
Iter_Clear(Character);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedActor);
Iter_InitAndClear(StreamedBot);
Iter_InitAndClear(StreamedCharacter);
#endif
#endif
#if _FOREACH_CHARACTERS
#if _FOREACH_BOTS
Iter_Clear(Bot);
Iter_Clear(Character);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedBot);
Iter_InitAndClear(StreamedCharacter);
#endif
#endif
#if _FOREACH_PLAYERS
Iter_Clear(Player);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedPlayer);
#endif
#if _FOREACH_PLAYERS
Iter_Clear(Player);
#if _FOREACH_STREAMED
Iter_InitAndClear(StreamedPlayer);
#endif
for (new i = 0; i != MAX_PLAYERS; ++i)
#endif
for (new i = 0; i != MAX_PLAYERS; ++i)
{
if (IsPlayerConnected(i))
{
if (IsPlayerConnected(i))
{
#if _FOREACH_BOTS
Iter_Add(Character, i);
if (IsPlayerNPC(i))
{
Iter_Add(Bot, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
#if _FOREACH_BOTS
Iter_Add(Character, i);
if (IsPlayerNPC(i))
{
Iter_Add(Bot, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
{
if (IsPlayerStreamedIn(i, j))
{
if (IsPlayerStreamedIn(i, j))
{
Iter_Add(StreamedCharacter[j], i);
Iter_Add(StreamedBot[j], i);
}
Iter_Add(StreamedCharacter[j], i);
Iter_Add(StreamedBot[j], i);
}
#endif
}
else
#endif
{
#if _FOREACH_PLAYERS
Iter_Add(Player, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
}
#endif
}
else
#endif
{
#if _FOREACH_PLAYERS
Iter_Add(Player, i);
#if _FOREACH_STREAMED
for (new j = 0; j != MAX_PLAYERS; ++j)
{
if (IsPlayerStreamedIn(i, j))
{
if (IsPlayerStreamedIn(i, j))
{
#if _FOREACH_BOTS
Iter_Add(StreamedCharacter[j], i);
#endif
Iter_Add(StreamedPlayer[j], i);
}
#if _FOREACH_BOTS
Iter_Add(StreamedCharacter[j], i);
#endif
Iter_Add(StreamedPlayer[j], i);
}
#endif
#endif
}
}
}
#endif
#endif
}
}
#endif
return 1;
}
#endif
}
#endif
return 1;
}

/*

Expand Down