Solved: See second post.
I hope someone can help me with this:
I have an enum which, for the purpose of this post, contains the variables below (for the curious, I use an underscore in the enum's name to solve
this compiler problem). Now, the problem is that my boolean variable
bAllowImmortality is seemingly being written without any such early assignment. It's value? The handle of the player's timer,
hIdleTimer! I am completely confused why this should happen. This is the code:
PHP Code:
enum _:PlayerData
{
Handle:hIdleTimer = INVALID_HANDLE,
bool:bAllowImmortality = false
};
new g_Players[MAXPLAYERS + 1][PlayerData];
new bool:g_bEnabled = true;
My hooked
player_spawn event contains the problem. I have commented out the PrintToChat debug lines just so you guys can see the real code easier.
PHP Code:
public Action:Event_PlayerSpawn(Handle:Event, const String:Name[], bool:dontBroadcast)
{
if (g_bEnabled) {
new client = GetClientOfUserId(GetEventInt(Event, "userid"));
//PrintToChat(client, "Spawn1 - AllowImmortality = %d", g_Players[client][bAllowImmortality]);
if (client > 0 && client < (MaxClients + 1)) {
if (!IsFakeClient(client)) {
//PrintToChat(client, "Spawn2 - AllowImmortality = %d", g_Players[client][bAllowImmortality]);
if ((g_Players[client][hIdleTimer] == INVALID_HANDLE) && (g_Players[client][hIdleTimer] = CreateTimer(g_fInterval, IdleTimer, client, TIMER_REPEAT))) {
//PrintToChat(client, "SpawnTimerHandle = %d", g_Players[client][hIdleTimer]);
// PrintToChat(client, "Spawn3 - AllowImmortality = %d", g_Players[client][bAllowImmortality]);
...
}
//PrintToChat(client, "Spawn4 - AllowImmortality = %d", g_Players[client][bAllowImmortality]);
g_Players[client][bAllowImmortality] = true;
//PrintToChat(client, "Spawn5 - AllowImmortality = %d", g_Players[client][bAllowImmortality]);
}
}
}
}
The output from the PrintToChat lines:
Code:
Spawn1 - AllowImmortality = 0
Spawn2 - AllowImmortality = 0
SpawnTimerHandle = 45547948
Spawn3 - AllowImmortality = 45547948
Spawn4 - AllowImmortality = 45547948
Spawn5 - AllowImmortality = 1
Thank you to any who can shed light on this thoroughly confusing bug.
Edit: I have confirmed that the problem happens exactly during:
Code:
g_Players[client][hIdleTimer] = CreateTimer(g_fInterval, IdleTimer, client, TIMER_REPEAT);