alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
973 stars 422 forks source link

CSRoundEndReason is 1 larger than expected when fetched from event #1419

Closed nickdnk closed 3 years ago

nickdnk commented 3 years ago

Help us help you

Environment

Description

When fetching the round_end event (https://wiki.alliedmods.net/Counter-Strike:_Global_Offensive_Events#round_end) and reading the reason property using event.GetInt("reason"), it returns an integer that's 1 larger than defined in https://sm.alliedmods.net/new-api/cstrike/__raw, i.e. when the bomb explodes, CSRoundEnd_TargetBombed becomes 1, not 0, CSRoundEnd_TargetSaved becomes 12 instead of 11 and so on.

Is this me being an idiot? Does GetInt() not work when the field is of type "byte" (there's no GetByte() method it seems). I'm pretty new to SourceMod/SourcePawn so this might be my fault.

Problematic Code (or Steps to Reproduce)

// Hook the event
int reason = event.GetInt("reason");
LogMessage("%d", reason);

Logs

n/a

psychonic commented 3 years ago

IIRC, this is due to the reasons being off by one between CS:S and CS:GO (and the include predating CS:GO). The SourceMod and CStrike extension natives and forwards that specifically deal with round end reason do account for this. For reading from the event, you do have to handle it manually.

nickdnk commented 3 years ago

Cool. Thanks for clearing it up. I'll just adjust my code to compensate for it. I just wanted to make sure I wasn't doing something wrong.