|
Author
|
Message
|
|
BANNED
|

11-08-2008
, 11:14
[Tutorial] Usermessages : list, ussage, bitbuffer structure
|
#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_id, Handle:bf, const players[], playersNum, bool:reliable, bool: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_id, Handle:bf, const players[], playersNum, bool:reliable, bool: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.
|
|
|
|