AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [Tutorial] Usermessages : list, ussage, bitbuffer structure (https://forums.alliedmods.net/showthread.php?t=80256)

SAMURAI16 11-08-2008 11:14

[Tutorial] Usermessages : list, ussage, bitbuffer structure
 
To make things more simple to understand, I can say usermessages are something like events
There are different user message for every game (I mean CS:S for example don't have the same user message like TF2)

○ Here is list of usermessages in CS:S
Code:

Geiger                           
Train                           
HudText                       
SayText                         
SayText2                           
TextMsg                           
HudMsg                         
ResetHUD                       
GameTitle                         
ItemPickup                       
ShowMenu                       
Shake                           
Fade                             
VGUIMenu                         
CloseCaption                     
SendAudio                     
RawAudio                       
VoiceMask                     
RequestState                     
BarTime                         
Damage                             
RadioText                         
HintText                         
ReloadEffect                     
PlayerAnimEvent                   
AmmoDenied                       
UpdateRadar                       
KillCam

○ Natives that may you need are found in usermessage.inc

○ How to create create (reproduce) an usermessage and send it to client

Before all you need the usermessage structure. There are bunch of bits wich may not so easy to find (We'll talk about that later)
Now i'll show how to send a message to all clients. If you want to set only to a client use StartMessageOne() native (at least check usermessages.inc)

PHP Code:

// start message
new Handle:hBf StartMessageAll("Message Name");

if(
hBf != INVALID_HANDLE)
{
    
structure...
    
EndMessage();
    


Let's say if this message have 4 arg's (I know it's not real args but whatever) and first 3 are byte time last last is char.
Code would be:

PHP Code:

// start message
new Handle:hBf StartMessageAll("Message Name");

if(
hBf != INVALID_HANDLE)
{
    
BfWriteByte(hBf,20);
    
BfWriteByte(hBf,10);
    
BfWriteByte(hBf,440);
    
BfWriteChar(hBf,'c');
    
EndMessage();
    


It's verry important to respect the order on sending bitbuffer bytes
You can find all bitbuffer natives in bitbuffer.inc file


○ How to hook user messages
Well that's not so hard, but again problem is with structure of usermessage
First I want to say you can't print anything in callback of hooked message (I mean you can't use PrintToChat, PrintToChatAll etc)

Now, example:

PHP Code:

public OnPluginStart()
{
    
HookUserMessage(GetUserMessageId("ResetHUD"),fn_HookResetHUD,true);
}

public 
Action:fn_HookResetHUD(UserMsg:msg_idHandle:bf, const players[], playersNumbool:reliablebool:init
{
    
// stuff whatever





I choosed "ResetHUD", of course you'll use what you need
Now the most difficult part is structure of message. You can read all bits with BfRead*() natives (bitbuffer.inc)
Let's say if structure is byte,byte,float,byte and you need to check if last is 40:

PHP Code:

public Action:fn_HookMyMessage(UserMsg:msg_idHandle:bf, const players[], playersNumbool:reliablebool:init
{
    
BfReadByte(bf);
    
BfReadByte(bf);
    
BfReadFloat(bf);
    new 
my_search BfReadByte(bf);
    if(
my_search == 40)
    {
        
// do stuff
    
}



I can say this message have some kind of 4 arg's. To reach the 4nd you have to read the previous ones

I can say that's all. You can ask here all you want to know about each usermessages (when they are called, structure ) ; I'll do a handjob to find what you need ;)








blade81 01-25-2009 15:35

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Would you post an example for BarTime please? I can't get it to work. Thanks

p3tsin 01-25-2009 16:20

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Quote:

Originally Posted by SAMURAI16 (Post 711615)
First I want to say you can't print anything in callback of hooked message (I mean you can't use PrintToChat, PrintToChatAll etc)

To be more specific, you can't use other usermessages in hooks (PrintToChat is a wrapper for TextMsg usermsg), but PrintToServer and possibly PrintToConsole should work just fine. Use the MsgSentNotify callback (4th param in HookUserMessage) if you need to send usermessages.

Also, you could've mentioned the use of the bool:intercept param in HookUserMessage. Nice tut otherwise. :up:

Quote:

Originally Posted by blade81 (Post 750060)
Would you post an example for BarTime please? I can't get it to work. Thanks

This should be it but donnu if it works.

Code:

new Handle:buf = StartMessageOne("BarTime",client,USERMSG_RELIABLE)
if(buf != INVALID_HANDLE) {
        BfWriteByte(buf,duration)
        BfWriteByte(buf,0)
        EndMessage()
}


blade81 01-25-2009 17:35

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
It doesn't work. Thx anyway

SAMURAI16 01-26-2009 07:39

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
BarTime Draws a HUD progress bar which is filled from 0% to 100% for the time.
try this
Code:
new Handle:buf = StartMessageOne("BarTime",client,USERMSG_RELIABLE) if(buf != INVALID_HANDLE) {     BfWriteShort(buf,duration) // duration is in seconds     EndMessage() }

CrimsonGT 01-26-2009 09:12

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Just to make note, BarTime doesn't work in TF2.

Should this work? I grabbed this usermessage from the tf2 list and tried to use it, but it never got called.

Code:

public OnPluginStart()
{
    HookUserMessage(GetUserMessageId("HudArenaNotify"),fn_HookArenaNotify,true);
}

public Action:fn_HookArenaNotify(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
{
    CreateTimer(0.5, Timer_Test);
}

public Action:Timer_Test(Handle:hndl)
{
    PrintToChatAll("IT WAS CALLED");
}


blade81 01-26-2009 14:24

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Quote:

Originally Posted by SAMURAI16 (Post 750370)
BarTime Draws a HUD progress bar which is filled from 0% to 100% for the time.
try this
Code:
new Handle:buf = StartMessageOne("BarTime",client,USERMSG_RELIABLE) if(buf != INVALID_HANDLE) {     BfWriteShort(buf,duration) // duration is in seconds     EndMessage() }


Still doesn't work. Also tried with WriteFloat.

p3tsin 01-26-2009 16:44

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Quote:

Originally Posted by blade81 (Post 750125)
It doesn't work. Thx anyway

It seems even CSS never fires that usermessage. You can do the progress bar with these 2 netprops though

Code:

CCSPlayer::m_iProgressBarDuration (byte)
CCSPlayer::m_flProgressBarStartTime (float)

Set starttime to GetGameTime() and duration to number of seconds you want it to last. Apparently you gotta reset the value of m_iProgressBarDuration to 0 manually when the time has ran out.

blade81 01-27-2009 18:16

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Quote:

Originally Posted by p3tsin (Post 750688)
It seems even CSS never fires that usermessage. You can do the progress bar with these 2 netprops though

Code:

CCSPlayer::m_iProgressBarDuration (byte)
CCSPlayer::m_flProgressBarStartTime (float)

Set starttime to GetGameTime() and duration to number of seconds you want it to last. Apparently you gotta reset the value of m_iProgressBarDuration to 0 manually when the time has ran out.

Thank you all! +karma :)

This works!
PHP Code:

  SetEntPropFloat(clientProp_Send"m_flProgressBarStartTime"GetGameTime());
  
SetEntProp(clientProp_Send"m_iProgressBarDuration"10); 


pheadxdll 01-29-2009 12:03

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Anybody willing to take some screenshots of what these look like?

Thanks!


All times are GMT -4. The time now is 19:55.

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