Raised This Month: $12 Target: $400
 3% 

get_user_msgid() fails to work on server startup?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 06-26-2018 , 15:10   get_user_msgid() fails to work on server startup?
Reply With Quote #1

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.

Am I missing something or is this a bug?
__________________

Last edited by OciXCrom; 06-26-2018 at 15:11.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 06-26-2018 , 15:14   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #2

Most likely get_user_msgid is assigned it's values after plugin_precache is triggered, that's why you're getting null values.
__________________
edon1337 is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-26-2018 , 18:47   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #3

Quote:
Originally Posted by edon1337 View Post
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
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-30-2018 , 13:22   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #4

plugin_precache is useful for hooking WeaponList via register_message which requires get_user_msgid call.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-30-2018 , 13:37   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #5

Quote:
Originally Posted by PRoSToTeM@ View Post
plugin_precache is useful for hooking WeaponList via register_message which requires get_user_msgid call.
Nope:

PHP Code:
#include <amxmodx>

public plugin_precache()
{
    
log_amx("%i"register_message(get_user_msgid("WeaponList"), "TestFunc"))
}

public 
TestFunc()
{
    static 
ii++
    
log_amx("test success %i"i)

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.
__________________

Last edited by OciXCrom; 07-30-2018 at 13:39.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-30-2018 , 14:10   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
Nope:
Yeah, I know, I only want to say that there is an application for that, but it doesn't work as expected.
Quote:
Originally Posted by OciXCrom View Post
I already submitted a pull request to add a warning for this function in the documentation - https://github.com/alliedmodders/amxmodx/pull/506
That's why I'm here.
Quote:
Originally Posted by OciXCrom View Post
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.
__________________

Last edited by PRoSToTeM@; 07-30-2018 at 14:26.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-30-2018 , 14:27   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #7

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.
__________________

Last edited by Arkshine; 07-30-2018 at 14:38.
Arkshine is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 07-30-2018 , 15:00   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #8

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.
__________________

Last edited by PRoSToTeM@; 07-30-2018 at 15:24.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-30-2018 , 15:27   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #9

This didn't work for me
PHP Code:
public plugin_init( )
{
    
register_forwardFM_RegUserMsg"@RegUserMsg" );
}

@
RegUserMsgszMsg[ ], iSize )
{
    
register_messageget_user_msgid"WeaponList" ), "OnMessageWeaponList" );
}

public 
OnMessageWeaponList( )
{
    new 
iAmmoIndex get_msg_arg_int);
    new 
iAmmoCount get_msg_arg_int);
    new 
iWeaponID get_msg_arg_int);
    
    
g_eAmmoIndexiWeaponID ][ AmmoIndex ] = iAmmoIndex;
    
g_eAmmoIndexiWeaponID ][ AmmoCount ] = iAmmoCount;
    
    
log_to_file"Weaponlist.txt""%d %d %d"iAmmoIndexiAmmoCountiWeaponID );

EDIT:
I forgot I had to hook FM_RegUserMsg in plugin_precache, works now.
__________________

Last edited by edon1337; 07-30-2018 at 15:31.
edon1337 is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 07-30-2018 , 15:30   Re: get_user_msgid() fails to work on server startup?
Reply With Quote #10

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
__________________

Last edited by Arkshine; 07-30-2018 at 15:30.
Arkshine is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode