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!

SAMURAI16 01-29-2009 12:53

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

Originally Posted by pheadxdll (Post 752252)
Anybody willing to take some screenshots of what these look like?

Thanks!

what ? :|

antihacker 03-10-2009 16:32

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Where can i find usermessages for L4D ?

Fyren 03-11-2009 09:40

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Do "meta game" in your server console. Not all messages are actually used/work/do anything.

antihacker 03-11-2009 10:27

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
thanks
+karma

DaFox 03-12-2009 09:19

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

Originally Posted by pheadxdll (Post 752252)
Anybody willing to take some screenshots of what these look like?

Thanks!

http://img24.**************/img24/961/03122009071849.png

ErF 03-21-2009 11:56

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
You can give all the code?

Thanks.

CrimsonGT 03-22-2009 21:54

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Im a bit confused, I wrote a plugin that hooks all TF2 usermessages and creates a 0.1 second timer and then prints to chat when they are called. Some usermessages which I KNOW are being called are not printing out to chat. For example SayText2, I have another plugin that uses SayText2 but when I use it, nothing prints to chat.

I have...
Code:

HookUserMessage(GetUserMessageId("SayText2"), fn_SayText2, true);

public Action:fn_SayText2(UserMsg:msg_id, Handle:bf, const players[], playersNum, bool:reliable, bool:init)
{
    CreateTimer(0.1, Timer_SayText2);
}
public Action:Timer_SayText2(Handle:hndl)
{
    PrintToChatAll("UserMessage: SayText2 was Called");
}

My other question is how the hell do you find out what the args for a usermessage are? The first post says it will be covered later but never goes over it so im a bit clueless.

SAMURAI16 03-23-2009 08:46

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
by guessing
BfReadByte(bf) -> see if return a value
if no
BfReadChar(bf) and so on untill you get a value

Let's say if find a char. That means first argument is a char. Now you have to do
BfReadChar(bf)
BfReadByte(bf) -> if returns something is good, else again

BfReadChar(bf)
BfReadChar(bf) -> returns something ? if yes that means 2nd argument is char also

psychonic 03-23-2009 08:49

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

Originally Posted by CrimsonGT (Post 786904)
Im a bit confused, I wrote a plugin that hooks all TF2 usermessages and creates a 0.1 second timer and then prints to chat when they are called. Some usermessages which I KNOW are being called are not printing out to chat. For example SayText2, I have another plugin that uses SayText2 but when I use it, nothing prints to chat.

My other question is how the hell do you find out what the args for a usermessage are? The first post says it will be covered later but never goes over it so im a bit clueless.

Not sure why your hook isn't working. That's the only way I know of to get a good guess of the format, but this is what I use for SayText2 in TF2

PHP Code:

    BfWriteByte(hBfclientid); 
    
BfWriteByte(hBf0); 
    
BfWriteString(hBfmessage);
    
EndMessage(); 

Use \x03 in the message for the team color of the specified clientid.

SAMURAI16 03-23-2009 09:18

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
that's sending a message, not hooking

psychonic 03-23-2009 09:38

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

Originally Posted by SAMURAI16 (Post 787109)
that's sending a message, not hooking

I was getting the impression that he was hooking it to figure out how it works because his plugin that sends was not working
Quote:

Originally Posted by CrimsonGT
I have another plugin that uses SayText2 but when I use it, nothing prints to chat.


CrimsonGT 03-23-2009 09:38

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Thanks Samurai,

and yeah, im not actually trying to find the SayText2 stuff, I just tested to see if my hooks were actually working which apparently they arent. (I hooked all of the TF2 usermessages) and I just tried out saytext and saytext2 and neither one worked so im a bit confused as to why the hooks arent being called on them when they are obviously being used.

Dragonshadow 08-14-2009 09:54

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.

I know this is an old thread, but is there anything like this in tf2?

Wazz 08-14-2009 20:33

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Your only chance is the using the developers commentary. I have no further help I can give though, good luck :)

flud 04-29-2010 20:21

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
any chance to see some example for l4d2 ?

KawMAN 05-01-2010 11:22

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
This can be useful
PHP Code:

decl String:strRest[256]="";
decl String:strRestc[256]="";
new 
curbyte;
while(
BfGetNumBytesLeft(hBitBuffer))
{
    
curbyte BfReadByte(hBitBuffer);
    
Format(strRestsizeof(strRest), "%s%d"strRestcurbyte);
    
Format(strRestcsizeof(strRestc), "%s%c"strRestccurbyte);
}
PrintToServer("USERMSGHOOK: %s "strRest);
PrintToServer("USERMSGHOOK: %s "strRestc); 

also Name Change Message Block if
PHP Code:

public OnPluginStart()
{    
    
HookUserMessage(GetUserMessageId("SayText2"), UserMessageHooktrue);
}

public 
Action:UserMessageHook(UserMsg:MsgIdHandle:hBitBuffer, const iPlayers[], iNumPlayersbool:bReliablebool:bInit)
{
    
decl String:strMessage[256]="";

    
// Skip the first two bytes
    
BfReadByte(hBitBuffer);
    
BfReadByte(hBitBuffer);
    
    
// Read the message
    
BfReadString(hBitBufferstrMessagesizeof(strMessage), true);
    
//Next BfReadString is prev name, next is current name (changed to)
    
    //#Cstrike_Name_Change
    
if (StrEqual(strMessage"#Cstrike_Name_Change")) 
    {

        return 
Plugin_Handled;
    }
    return 
Plugin_Continue;



Soldier.Zi 05-23-2022 16:58

Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
 
Sorry for refreshing so old thread, but i want to ask where I can find list of all user messages for CS:GO?


All times are GMT -4. The time now is 23:42.

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