• IS THIS SITE UGLY? Click "RG3" at the very bottom-left of this page to change it. To dismiss this notice, click the X --->
Resource icon

Utility MQ2TributeManager 1.0

Download now: Join us with Level 2 access
or earn your way in with RedCents.
Other Authors
alt228, Sym, wired420
Included in Very Vanilla
Very Vanilla Included! No need to download.
MQ2TributeManager - This plugin Adds a /tribute command in game for automatic tribute management.

Commands
Rich (BB code):
/tribute on - Toggle tribute on.
/tribute off - Toggle tribute off.
/tribute auto* - Toggle tribute on or off based on combat state automatically.
/tribute forceoff - Toggle tribute off immediately ignoring any remaining time left.
/tribute show - Shows the current mode the plugin is running in (i.e. on/off/auto).
*Recommended
Rich (BB code):
// MQ2TributeManager.cpp : Defines the entry point for the DLL application.
//

// MQ2TributeManager
// Manages tribute for you based on combat status
// Author: alt228, [email protected]
//
// Now Saves/Loads previous settings. Still defaults to manual - wired420

#include "../MQ2Plugin.h"

enum TributeMode
{
    TributeMode_Manual,
    TributeMode_Auto,
    TributeMode_OffWhenExpired,
    TributeMode_Unused
};

enum CombatState
{
    CombatState_COMBAT,
    CombatState_DEBUFFED,
    CombatState_COOLDOWN,
    CombatState_ACTIVE,
    CombatState_RESTING
};

PreSetup("MQ2TributeManager");

// Save & Load
char szTemp[MAX_STRING], ourMode[MAX_STRING];
bool initDone = false;

//defaults
TributeMode mode = TributeMode_Manual;
unsigned int tributeFudge = 2000;
#define SKIP_PULSES 80
long SkipPulse = 0;

void updateINIFn() {
    sprintf_s(INIFileName, "%s\\%s_%s.ini", gszINIPath, EQADDR_SERVERNAME, GetCharInfo()->Name);
}

VOID SaveINI(VOID) {
    updateINIFn();
    sprintf_s(szTemp, "MQ2TributeManager");
    WritePrivateProfileSection(szTemp, "", INIFileName);
    if (mode == TributeMode_Auto) {
        WritePrivateProfileString(szTemp, "Mode", "2", INIFileName);
    }
    else if (mode == TributeMode_OffWhenExpired) {
        WritePrivateProfileString(szTemp, "Mode", "1", INIFileName);
    }
    else {
        WritePrivateProfileString(szTemp, "Mode", "0", INIFileName);
    }
}

VOID LoadINI(VOID) {
    updateINIFn();
    sprintf_s(szTemp, "MQ2TributeManager");
    DWORD loadMode = GetPrivateProfileString(szTemp, "Mode", "", ourMode, MAX_STRING, INIFileName);
    int setTheMode = atoi(ourMode);
    if (setTheMode == 0) {
        mode = TributeMode_Manual;
    }
    else if (setTheMode == 1) {
        mode = TributeMode_OffWhenExpired;
    }
    else if (setTheMode == 2) {
        mode = TributeMode_Auto;
    }
    initDone = true;
}

VOID SetTributeStatus(bool tributeOn)
{
    if (tributeOn)
    {
        if (!(bool)((*pTributeActive) ? true : false))
        {
            DebugSpewAlways("MQ2TributeManager::Turning on tribute");
            DoCommand((PSPAWNINFO)pCharSpawn, "/notify TributeBenefitWnd TBWP_ActivateButton leftmouseup");
            DoCommand((PSPAWNINFO)pCharSpawn, "/notify TributeBenefitWnd TBWT_ActivateButton leftmouseup");
        }
    }
    else
    {
        if ((bool)((*pTributeActive) ? true : false))
        {
            DebugSpewAlways("MQ2TributeManager::Turning off tribute");
            DoCommand((PSPAWNINFO)pCharSpawn, "/notify TributeBenefitWnd TBWP_ActivateButton leftmouseup");
            DoCommand((PSPAWNINFO)pCharSpawn, "/notify TributeBenefitWnd TBWT_ActivateButton leftmouseup");
        }
    }
}

VOID TributeManagerCmd(PSPAWNINFO characterSpawn, PCHAR line)
{
    bool syntaxError = false;
    if (line[0] == 0)
    {
        syntaxError = true;
    }

    bool setMode = false;
    TributeMode newMode = TributeMode_Unused;

    bool setStatus = false;
    bool newStatus = true;

    bool showStatus = false;

    CHAR thisArg[MAX_STRING] = { 0 };
    int argNumber = 1;
    bool moreArgs = true;

    while (moreArgs && argNumber < 10)
    {
        DebugSpewAlways("MQ2TributeManager:: GetArg(%i)", argNumber);
        GetArg(thisArg, line, argNumber);
        argNumber++;

        if (!thisArg || (strlen(thisArg) == 0))
        {
            moreArgs = false;
        }
        else if (_stricmp(thisArg, "on") == 0)
        {
            setStatus = true;
            newStatus = true;
        }
        else if (_stricmp(thisArg, "off") == 0)
        {
            setMode = true;
            newMode = TributeMode_OffWhenExpired;
            WriteChatColor("Tribute mode: off when expired");
        }
        else if (_stricmp(thisArg, "forceoff") == 0)
        {
            setStatus = true;
            newStatus = false;
            setMode = true;
            newMode = TributeMode_Manual;
        }
        else if (_stricmp(thisArg, "auto") == 0)
        {
            setMode = true;
            newMode = TributeMode_Auto;
            WriteChatColor("Tribute mode: automatic");
        }
        else if (_stricmp(thisArg, "manual") == 0)
        {
            setMode = true;
            newMode = TributeMode_Manual;
            WriteChatColor("Tribute mode: manual");
        }
        else if (_stricmp(thisArg, "show") == 0)
        {
            showStatus = true;
        }
        else
        {
            syntaxError = true;
        }
    }

    if (syntaxError)
    {
        SyntaxError("Usage: /tribute <auto|manual|on|off|forceoff|show>");
        return;
    }

    if (setStatus)
    {
        SetTributeStatus(newStatus);
    }

    if (setMode)
    {
        mode = newMode;
        SaveINI();
    }

    if (showStatus)
    {
        if (mode == TributeMode_Manual)
        {
            WriteChatColor("Tribute mode: manual");
        }
        else if (mode == TributeMode_Auto)
        {
            WriteChatColor("Tribute mode: automatic");
        }
        else if (mode == TributeMode_OffWhenExpired)
        {
            WriteChatColor("Tribute mode: off when expired");
        }

        if (gGameState == GAMESTATE_INGAME)
        {
            DebugSpewAlways("MQ2TributeManager:: Active Favor Cost: %i", pEQMisc->GetActiveFavorCost());
            DebugSpewAlways("MQ2TributeManager:: Combat State: %i", (CombatState)((PCPLAYERWND)pPlayerWnd)->CombatState);
            DebugSpewAlways("MQ2TributeManager:: Tribute Active: %i", *pTributeActive);
            DebugSpewAlways("MQ2TributeManager:: Current Favor: %i", GetCharInfo()->CurrFavor);
            DebugSpewAlways("MQ2TributeManager:: Tribute Timer: %i ms", GetCharInfo()->TributeTimer);
        }
    }
}

// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
    DebugSpewAlways("Initializing MQ2TributeManager");
    AddCommand("/tribute", TributeManagerCmd);
}

// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
    DebugSpewAlways("Shutting down MQ2TributeManager");
    RemoveCommand("/tribute");
}

PLUGIN_API VOID SetGameState(DWORD GameState)
{
    DebugSpewAlways("MQ2TributeManager::SetGameState()");
    if (GameState == GAMESTATE_INGAME)
    {
        if (!initDone) {
            LoadINI();
        }
        // have to do a little hack here or else other /notify commands will not work
        DebugSpewAlways("MQ2TributeManager::SetGameState::initializing tribute window");
        DoCommand((PSPAWNINFO)pCharSpawn, "/keypress TOGGLE_TRIBUTEBENEFITWIN");
        DoCommand((PSPAWNINFO)pCharSpawn, "/keypress TOGGLE_TRIBUTEBENEFITWIN");
    }
    if (GameState != GAMESTATE_INGAME && GameState != GAMESTATE_LOGGINGIN) {
        if (initDone) {
            initDone = false;
        }
    }
}

// This is called every time MQ pulses
PLUGIN_API VOID OnPulse(VOID)
{
    if (gGameState != GAMESTATE_INGAME)
        return;
    if (!initDone)
        return;

    if (SkipPulse == SKIP_PULSES) {
        SkipPulse = 0;

        if (mode == TributeMode_Auto)
        {
            CombatState combatState = (CombatState)((PCPLAYERWND)pPlayerWnd)->CombatState;
            bool inCombat = false;
            if (combatState == CombatState_COMBAT)
            {
                inCombat = true;
            }

            unsigned int activeFavorCost = pEQMisc->GetActiveFavorCost();
            PCHARINFO myCharInfo = GetCharInfo();

            if ((inCombat) && (!*pTributeActive) && (activeFavorCost <= myCharInfo->CurrFavor) && (pEQMisc->GetActiveFavorCost() > 0))
            {
                //activate tribute
                SetTributeStatus(true);
            }
            else if ((!inCombat) && (*pTributeActive) && (myCharInfo->TributeTimer < tributeFudge))
            {
                SetTributeStatus(false);
            }
        }
        else if (mode == TributeMode_OffWhenExpired)
        {
            if (((*pTributeActive) ? true : false) == false)
            {
                mode = TributeMode_Manual;
                return;
            }

            if (GetCharInfo()->TributeTimer < tributeFudge)
            {
                mode = TributeMode_Manual;
                SetTributeStatus(false);
            }
        }
    }
    SkipPulse++;
}
Server Type
Live, Emu, TLP, Test Server
Author
wired420
Downloads
2
First release
Last update
Rating
0.00 star(s) 0 ratings

More resources from wired420

Latest updates

  1. Fixed error in Logic Tree.

    Now works correctly even after reload. - wired420
  2. Updated to Save/Load previously selected settings.

    Saves info to ServerName_CharacterName.ini in main MQ\Release directory under heading...
Top