I just noticed something weird. I made a simple code to demonstrate.
PHP Code:
#include <amxmodx>
public plugin_precache() log_amx("%i %i %i", get_user_msgid("TeamInfo"), get_user_msgid("Damage"), get_user_msgid("ScreenFade"))
The output of this code is "0 0 0" on server start.
After I restart the server with the "restart" command or change the map, the output is "86 71 98" as it should be.
I tested both on 1.8.3 latest dev build and 1.8.2. The results are the same. It happens with any message.
However, if I change the event to plugin_init() instead of plugin_precache(), it works normally.
Most likely get_user_msgid is assigned it's values after plugin_precache is triggered, that's why you're getting null values.
It is during plugin_precache, but you can't get it at plugin_precache.
Also it only return msgId, and do not have an valid reason to work with this on plugin_precache
Prints 0 on server start.
Prints 1 and "test success" 29 times after server restart or mapchange.
I already submitted a pull request to add a warning for this function in the documentation - https://github.com/alliedmodders/amxmodx/pull/506
Correct me if there's indeed a bug that needs to be fixed.
Correct me if there's indeed a bug that needs to be fixed.
If register_message will work on startup (with substituted WeaponList msgid constant), then get_user_msgid is bugged. If not, then register_message & get_user_msgid are both bugged.
UPD: register_message works, so only get_user_msgid is bugged.
Not really a bug I believe. It's just that the game registers such messages in pfnServerActivate.
plugin_precache() is called before, at the first word pfnSpawn. So you can't use get_user_msgid() at this point at the first server start because not cached yet. plugin_init() is called after in pfnServerActivate as post. It's too late to hook for WeaponList.
One possible solution is to hook FM_RegUserMsg, and hooking WeaponList once the message is registered (In CS, the WeaponList messages are fired right after the message is registered).
Probably not fixable unless we implement a dedicated forward which would be fired once all the messages are registered.
Ye, plugin_precache is called from first spawn (from SV_LoadEntities). And usermsg registering is called from SV_ActivateServer (pfnServerActivate callback). SV_ActivateServer is called after SV_LoadEntities. As @Arkshine said the only and best way is to hook FM_RegUserMsg.
Possibly we can add register_message_lazy which would get usermsg name instead of id and retrieve msgid when the first message is sent.