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

EventManager


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bos93
Veteran Member
Join Date: Jul 2010
Old 05-11-2013 , 17:34   EventManager
Reply With Quote #1

EventManager by quckly

Ready-made solution for messaging / event module to metamod.

Example of use:

PHP Code:
#include "q_events.h"
         
int Event_CurWeaponint msg_destint msg_type, const float *pOriginedict_t *ed );
         
void ClientCommand(edict_tpPlayer)
{
    if(!
strcmp(CMD_ARGV(1), "hook"))
    {
        
Events.RegisterEvent"CurWeapon", &Event_CurWeapon );
    }
         
    
RETURN_META(MRES_IGNORED);
}
         
int Event_CurWeaponint msg_destint msg_type, const float *pOriginedict_t *ed )
{
    
UTIL_ClientPrint(NULLHUD_PRINTTALK"Event: CurWeapon dest: %d type: %d ed: %p"msg_destmsg_typeed);
    
UTIL_ClientPrint(NULLHUD_PRINTTALK"Active: %d ID: %d ClippAmmo: %d"Events.GetArgInt(0), Events.GetArgInt(1), Events.GetArgInt(2));
         
    
UTIL_ClientPrint(NULLHUD_PRINTTALK"%d %p"Events.GetArgInt(3), Events.GetArgString(2));
         
    
Events.SetArg(277);
         
    return 
ER_IGNORED;

Type of event handler function: EventCallback
int Event_Handler (int msg_dest, int msg_type, const float * pOrigin, edict_t * ed);

It returns one of the following values:

PHP Code:
enum
{
    
ER_IGNORED 0,
    
ER_SUPERCEDE    // block event
}; 
Functions:

PHP Code:
/ / Hook event by name or id
                 void RegisterEvent 
(const int msg_idEventCallback func);
                 
void RegisterEvent (const char msg_idEventCallback func);
         
                 / / 
Gets the argument by number
                 int GetArgInt 
(int num);
                 
float GetArgFloat (int num);
                 const 
char GetArgString (int num);
         
                 / / 
Set the argument by number
                 void SetArg 
(int numint set);
                 
void SetArg (int numfloat set);
                 
void SetArg (int num, const char set);
         
                 / / 
Get the id event by name (not required)
                 
int ID (const char msg_name); 
Attached Files
File Type: zip q_events.zip (2.9 KB, 105 views)
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 05-11-2013 , 22:18   Re: EventManager
Reply With Quote #2

Very nice and helpful but think it's not really fast enough.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 05-12-2013 , 16:30   Re: EventManager
Reply With Quote #3

Too much loop iterations using cvector.

Better to store in a fixed array using 1 byte for type, 4 bytes for value (cast everything to int) then you can access directly using arg number as array offset (arg 0, 1, 2, 3, etc)

Also you may can add msg blocking function

Check this code

PHP Code:
// messages.h

#define BLOCK_NOT 0
#define BLOCK_ONCE 1
#define BLOCK_SET 2

void SetMsgBlock(int msgidint block); 
PHP Code:
// messages.cpp
#include "sdk/amxxmodule.h"
#include "messages.h"

int inblock;
int msgBlocks[256] = {BLOCK_NOT};
int msgType;

void SetMsgBlock(int msgidint block)
{
        if(
msgid && msgid 256)
                
msgBlocks[msgid] = block;
}

void MessageBegin(int msg_destint msg_type, const float *pOriginedict_t *ed)
{
        
msgType msg_type;
        if(
msgBlocks[msg_type])
        {
                
inblock 1;
                
RETURN_META(MRES_SUPERCEDE);
        }
        else
        {
                
inblock 0;
        }

        
RETURN_META(MRES_IGNORED);
}

void WriteByte(int iValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteChar(int iValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteShort(int iValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteLong(int iValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteAngle(float flValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteCoord(float flValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteString(const char *sz)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void WriteEntity(int iValue)
{
        
RETURN_META(inblock MRES_SUPERCEDE MRES_IGNORED);
}

void MessageEnd(void)
{
        if(
msgBlocks[msgType] == BLOCK_ONCE)
                
msgBlocks[msgType] = BLOCK_NOT;

        if(
inblock)
        {
                
inblock 0;
                
RETURN_META(MRES_SUPERCEDE);
        }
        
inblock 0;

        
RETURN_META(MRES_IGNORED);

__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
max13tum
Junior Member
Join Date: Mar 2009
Location: Russia,Tyumen
Old 05-20-2013 , 08:50   Re: EventManager
Reply With Quote #4

It is fast, easy to use. Direct access to the array can lead to the out of range, disruption types, etc.
joropito, this not only blocking.
max13tum is offline
Send a message via ICQ to max13tum Send a message via Skype™ to max13tum
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 05-20-2013 , 09:06   Re: EventManager
Reply With Quote #5

Quote:
Originally Posted by max13tum View Post
It is fast, easy to use. Direct access to the array can lead to the out of range, disruption types, etc.
joropito, this not only blocking.
Who said that?

I shared my blocking code that can be improved to add hooking.

I insist, cvector isn't the best for performance purposes. Better to use indexed arrays.
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
Reply



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:30.


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