I'm trying to make a really half-assed port of pheadxdll's old Roll the Dice plugin.
There is a condition called "scary bullets" that is meant to scare players you damage. This uses Native_TF2_StunPlayer.
However, when a player is attacked, the plugin throws this stacktrace:
L 07/11/2020 - 18:20:25: [SM] Exception reported: Client index 0 is invalid
L 07/11/2020 - 18:08:00: [SM] Blaming: custom/tf2c.smx
L 07/11/2020 - 18:08:00: [SM] Call stack trace:
L 07/11/2020 - 18:08:00: [SM] [0] GetClientUserId
L 07/11/2020 - 18:08:00: [SM] [1] Line 474, C:\Users\johnm\OneDrive\Documents\GitHub\TF2Classic-Tools\sourcemod\scripting\tf2c.sp::Native_TF2_StunPlayer
L 07/11/2020 - 18:08:00: [SM] [3] TF2_StunPlayer
L 07/11/2020 - 18:08:00: [SM] [4] Line 2499, C:\Users\Sap\Downloads\rtd_tf2c.sp::Event_PlayerHurt
Looking at the code in tf2c.sp, I noticed this block:
if (attacker)
{
if (!(-1 <= attacker <= MaxClients))
return ThrowNativeError(SP_ERROR_NATIVE, "Attacker index %d is invalid.", attacker);
if (attacker > 0 && !IsClientInGame(attacker))
return ThrowNativeError(SP_ERROR_NATIVE, "Attacker %d is not in-game", attacker);
if (attacker == 0)
attacker = -1;
// if (GetClientTeam(attacker) == GetClientTeam(victim))
// return;
}
This code explicitly tries to set the attacker ID to -1 if their ID is 0, but since attacker is 0 and evaluates to false, this code is never reached. Therefore, the code tries to continue with a client index of 0 and ends up throwing the traceback.
I found that removing the if (attacker) clause entirely fixed the issue, but I'm not sure if that approach is safe or not.
I'm trying to make a really half-assed port of pheadxdll's old Roll the Dice plugin.
There is a condition called "scary bullets" that is meant to scare players you damage. This uses Native_TF2_StunPlayer. However, when a player is attacked, the plugin throws this stacktrace:
Looking at the code in tf2c.sp, I noticed this block:
This code explicitly tries to set the attacker ID to -1 if their ID is 0, but since
attacker
is 0 and evaluates tofalse
, this code is never reached. Therefore, the code tries to continue with a client index of 0 and ends up throwing the traceback.I found that removing the
if (attacker)
clause entirely fixed the issue, but I'm not sure if that approach is safe or not.