get_user_msgid() fails to work on server startup?
I just noticed something weird. I made a simple code to demonstrate.
PHP Code:
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. Am I missing something or is this a bug? |
Re: get_user_msgid() fails to work on server startup?
Most likely get_user_msgid is assigned it's values after plugin_precache is triggered, that's why you're getting null values.
|
Re: get_user_msgid() fails to work on server startup?
Quote:
Also it only return msgId, and do not have an valid reason to work with this on plugin_precache |
Re: get_user_msgid() fails to work on server startup?
plugin_precache is useful for hooking WeaponList via register_message which requires get_user_msgid call.
|
Re: get_user_msgid() fails to work on server startup?
Quote:
PHP Code:
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. |
Re: get_user_msgid() fails to work on server startup?
Quote:
Quote:
Quote:
UPD: register_message works, so only get_user_msgid is bugged. |
Re: get_user_msgid() fails to work on server startup?
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. |
Re: get_user_msgid() fails to work on server startup?
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. |
Re: get_user_msgid() fails to work on server startup?
This didn't work for me
PHP Code:
I forgot I had to hook FM_RegUserMsg in plugin_precache, works now. |
Re: get_user_msgid() fails to work on server startup?
You have to check when WeaponList is being registered, then getting the return value.
RegUserMsg is going to be called for all the messages at once. The game does that essentially:
Spoiler
|
All times are GMT -4. The time now is 20:49. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.