garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

Add more robust error checking to weapons/scripted_ents.Register

Open Kefta opened this issue 1 year ago • 5 comments

Fixes https://github.com/Facepunch/garrysmod-issues/issues/5495 - unlike SWEPs, SENTs do not set a ClassName variable. While SWEPs really shouldn't either to prevent the same multi-registration issue, addons and even base code relies on this key to be set on the data table. While the entire initial SWEP table could be copied, I don't want to break addons that may rely on that ClassName being set on their passed table (yet).

Also added a bunch of type checks to provide more premature errors in case the SENT/SWEP sets something invalid before its creation.

A third optional bool argument (defaulting to false) "forcename" has been added to both Register functions which allows the caller to ignore ClassName overrides.

Additionally, the ai and nextbot SENT bases were added to the default base table.

Lastly, X.Register now returns true if the registration was successful and false if the PreRegisterX hook blocked it.

Kefta avatar Jun 27 '23 07:06 Kefta