.:: Bots United ::.  
filebase forums discord server github wiki web
cubebot epodbot fritzbot gravebot grogbot hpbbot ivpbot jkbotti joebot
meanmod podbotmm racc rcbot realbot sandbot shrikebot soulfathermaps yapb

Go Back   .:: Bots United ::. > Enhancement Workshop > Metamod and metamod plugins
Metamod and metamod plugins Plugins and improvements for the metamod server-side mod

Reply
 
Thread Tools
communication between two plugins
Old
  (#1)
commonbullet
Member
 
commonbullet's Avatar
 
Status: Offline
Posts: 49
Join Date: Nov 2004
Default communication between two plugins - 13-10-2008

I was wondering how could I establish communication between an amxx plugin and a metamod plugin - more precisely, an amxmodx plugin sets the game rule and a metamod bot should be aware about what's going on in the match.

It's been suggested that I could use engine messages, but I lack of understanding the mechanism.

I guess those messages have fixed sequences of parameters for each type of "event". I couldn't find where/how they are set in hlsdk, all I found was about SVC_TEMPENTITY.

Can I use a custom sequence of parameters and just return supercede?
Otherwise, if I would only be able to use existent messages patterns, wouldn't that be confused with 'real' engine messages.

I'd appreciate any information you could provide.
  
Reply With Quote
Re: communication between two plugins
Old
  (#2)
KWo
Developer of PODBot mm
 
KWo's Avatar
 
Status: Offline
Posts: 3,425
Join Date: Apr 2004
Default Re: communication between two plugins - 16-10-2008

If You are using "standard" AMX X / AMX natives, they are using HL messages only AMX X / AMX with its plugin can hook, because metamod blocks them to intercept by other mm plugins.
Example:
Code:
static cell AMX_NATIVE_CALL cs_set_user_team(AMX *amx, cell *params) // cs_set_user_team(index, team, model = 0); = 3 params
{
    // Set user team
    // params[1] = user index
    // params[2] = team
    // params[3] = model = 0

    // Valid entity should be within range
    CHECK_PLAYER(params[1]);

    // Make into edict pointer
    edict_t *pPlayer = MF_GetPlayerEdict(params[1]);

    int model = params[3];

    // Just set team. Removed check of 1-2-3, because maybe scripters want to create new teams, 4, 5 etc?
    *((int *)pPlayer->pvPrivateData + OFFSET_TEAM) = params[2];
    if (model != 0)
        *((int *)pPlayer->pvPrivateData + OFFSET_INTERNALMODEL) = model;
    
    // This makes the model get updated right away.
    MDLL_ClientUserInfoChanged(pPlayer, GETINFOKEYBUFFER(pPlayer)); //  If this causes any problems for WON, do this line only in STEAM builds.

    // And update scoreboard by sending TeamInfo msg.
    char teaminfo[32];
    switch (params[2]) {
        case TEAM_UNASSIGNED:
            strcpy(teaminfo, "UNASSIGNED");
            break;
        case TEAM_T:
            strcpy(teaminfo, "TERRORIST");
            break;
        case TEAM_CT:
            strcpy(teaminfo, "CT");
            break;
        case TEAM_SPECTATOR:
            strcpy(teaminfo, "SPECTATOR");
            break;
        default:
            int team_nr = (int)params[2];
            sprintf(teaminfo, "TEAM_%i", team_nr);
    }
    MESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamInfo", NULL));
    WRITE_BYTE(params[1]);
    WRITE_STRING(teaminfo);
    MESSAGE_END();
    
    if (params[2] == 1)
        MF_SetPlayerTeamInfo(params[1], params[2], "TERRORIST");
    else if (params[2] == 2)
        MF_SetPlayerTeamInfo(params[1], params[2], "CT");
    else
        MF_SetPlayerTeamInfo(params[1], params[2], NULL);

    return 1;
}
As You can see cstrike.cpp uses MESSAGE_BEGIN...MESSAGE_END scheme. Using this function casues metamod bots wouldn't get the teaminfo message, because metamod doesn't allow it to send to other mm plugins. But if You would write Your own function in sma script
Code:
cs_set_user_team2(id, team, modelname[]); 
{
    // Set user team
    // params[1] = user index
    // params[2] = team
    // params[3] = modelname

    // Valid entity should be within range

    if (!is_user_connected(id))
        return PLUGIN_HANDLED
    
    set_pdata_int(id, OFFSET_CSTEAMS, team, OFFSET_LINUX)

    // And update scoreboard by sending TeamInfo msg.
    new teaminfo[32];
    switch (team) {
        case TEAM_UNASSIGNED:
            strcpy(teaminfo, "UNASSIGNED");
            break;
        case TEAM_T:
            strcpy(teaminfo, "TERRORIST");
            break;
        case TEAM_CT:
            strcpy(teaminfo, "CT");
            break;
        case TEAM_SPECTATOR:
            strcpy(teaminfo, "SPECTATOR");
            break;
        default:
            int team_nr = (int)params[2];
            sprintf(teaminfo, "TEAM_%i", team_nr);
    }
    EMESSAGE_BEGIN(MSG_ALL, GET_USER_MSG_ID(PLID, "TeamInfo", NULL));
    EWRITE_BYTE(params[1]);
    EWRITE_STRING(teaminfo);
    EMESSAGE_END();

    // This makes the model get updated right away.
    set_user_info( id, "model", modelname )
    
    return PLUGIN_CONTINUE;
}
I hope that example describes clearly what You need to do in AMX X to inform bots about the info You are sending to other AMX X plugins.
  
Reply With Quote
Re: communication between two plugins
Old
  (#3)
commonbullet
Member
 
commonbullet's Avatar
 
Status: Offline
Posts: 49
Join Date: Nov 2004
Default Re: communication between two plugins - 18-10-2008

Thanks KWo, I understand now why engine messages should be sent instead.

But wouldn't these messages be confused with "real" game messages anyway?
I mean, suppose csflags plugin (an amxx plugin that adds "capture the flag" gameplay to cs) would send a message every time a flag is captured so bots (metamod) would be aware of the event. If it used an existent message like teaminfo or whatever, wouldn't that cause some mess in game?
  
Reply With Quote
Re: communication between two plugins
Old
  (#4)
KWo
Developer of PODBot mm
 
KWo's Avatar
 
Status: Offline
Posts: 3,425
Join Date: Apr 2004
Default Re: communication between two plugins - 18-10-2008

Everytime You want to send a HL message You need to know what it is for the game. If it's only some visual effect meesage, it cannot destroy the gameplaying. If it's changing something for players (because HL messages sent by AMX X can hit players; they only cannot hit other mm plugins - including mm bots) - and You know what is happening for them - just the same will happen for bots.
Hint
Test first the plugin normal way (with HL messages sent normal way by AMX X) on CZERO bots. Metamod doesn't block (it just cannot) sending the messages to them. If everything is OK - You can try to convert the plugin to use emessages.

More than likely the bots will not react on Your flags at all, since they don't know what such flags are for (there is no code in bots to react on such things, I guess)...
  
Reply With Quote
Re: communication between two plugins
Old
  (#5)
commonbullet
Member
 
commonbullet's Avatar
 
Status: Offline
Posts: 49
Join Date: Nov 2004
Default Re: communication between two plugins - 18-10-2008

Quote:
Originally Posted by KWo View Post
More than likely the bots will not react on Your flags at all, since they don't know what such flags are for (there is no code in bots to react on such things, I guess)...
I'm planning to code something in bot part to hook those messages and see if I manage to make them "skilled" to play csflags. (that's why I can't use csbots).

So, if it used a visual message just like you said (mostly tempentity messages), bots should still be able to distinguish those messages from "real" engine messages. I suppose these messages should contain a special value in a parameter so bots would know they're coming from csflags plugin (?).
  
Reply With Quote
Re: communication between two plugins
Old
  (#6)
KWo
Developer of PODBot mm
 
KWo's Avatar
 
Status: Offline
Posts: 3,425
Join Date: Apr 2004
Default Re: communication between two plugins - 18-10-2008

They will not know where this message is coming from, so You don't need that extra info include there (even no way to tell that). I wish You good luck with this, but I don't think You will be finally happy. The bots are really stupid and You need to put also the "AI" to the code so they can react on the messages You are going to send them. They don't have eyes, they are using tracelines and tracehulls to "see" obstacles or objectivities.
  
Reply With Quote
Re: communication between two plugins
Old
  (#7)
commonbullet
Member
 
commonbullet's Avatar
 
Status: Offline
Posts: 49
Join Date: Nov 2004
Default Re: communication between two plugins - 20-10-2008

About the amxx->metamod plugin communication, I've done some tests and it works fine so far.

Quote:
Originally Posted by KWo
I don't think You will be finally happy. The bots are really stupid and You need to put also the "AI" to the code so they can react on the messages You are going to send them. They don't have eyes, they are using tracelines and tracehulls to "see" obstacles or objectivities.
To make things worse, I've no experience with bot coding. But it's not so hard, at least at the level you're assuming, I hope.

Luckily csflags plugin stores lots of information in the flags entities (I was trying to avoid abusing from global variables in amxx).

So basically I would add some "objectives waypoints" (thoses flags are fixed just like in dod), and try add some "extra behavior" to an existent bot; I wouldn't have to code the hardest parts ...
  
Reply With Quote
Re: communication between two plugins
Old
  (#8)
commonbullet
Member
 
commonbullet's Avatar
 
Status: Offline
Posts: 49
Join Date: Nov 2004
Default Re: communication between two plugins - 05-01-2009

Just in case someone faces the same problem in counter-strike - CZCareer messages are very useful for this purpose since they have no effect in multiplayer matches. The first argument must be a string, then you may format the message as you like.
  
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles.com