View Single Post
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