Raised This Month: $32 Target: $400
 8% 

[Tutorial] Usermessages : list, ussage, bitbuffer structure


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SAMURAI16
BANNED
Join Date: Sep 2006
Old 11-08-2008 , 11:14   [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #1

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 ;)








Last edited by SAMURAI16; 11-08-2008 at 16:41.
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
blade81
Senior Member
Join Date: Apr 2005
Old 01-25-2009 , 15:35   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #2

Would you post an example for BarTime please? I can't get it to work. Thanks
__________________
blade81 is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 01-25-2009 , 16:20   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #3

Quote:
Originally Posted by SAMURAI16 View Post
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.

Quote:
Originally Posted by blade81 View Post
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()
}
__________________
plop

Last edited by p3tsin; 01-25-2009 at 16:26.
p3tsin is offline
blade81
Senior Member
Join Date: Apr 2005
Old 01-25-2009 , 17:35   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #4

It doesn't work. Thx anyway
__________________
blade81 is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 01-26-2009 , 07:39   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #5

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() }
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 01-26-2009 , 09:12   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #6

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");
}
__________________

Last edited by CrimsonGT; 01-26-2009 at 09:30.
CrimsonGT is offline
blade81
Senior Member
Join Date: Apr 2005
Old 01-26-2009 , 14:24   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #7

Quote:
Originally Posted by SAMURAI16 View Post
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.
__________________
blade81 is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 01-26-2009 , 16:44   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #8

Quote:
Originally Posted by blade81 View Post
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.
__________________
plop
p3tsin is offline
blade81
Senior Member
Join Date: Apr 2005
Old 01-27-2009 , 18:16   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #9

Quote:
Originally Posted by p3tsin View Post
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); 
__________________
blade81 is offline
pheadxdll
AlliedModders Donor
Join Date: Jun 2008
Old 01-29-2009 , 12:03   Re: [Tutorial] Usermessages : list, ussage, bitbuffer structure
Reply With Quote #10

Anybody willing to take some screenshots of what these look like?

Thanks!
__________________
pheadxdll 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 13:23.


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