This original MQ2 plugin adds a /tribute command in game with automatic tribute status management capabilities.
Usage: /tribute < auto | manual | on | off | forceoff | enabledetrimental | disabledetrimental | show | savesettings >
Options:
Compiled DLL attached.
alt228
alt228@nerdshack.com
Usage: /tribute < auto | manual | on | off | forceoff | enabledetrimental | disabledetrimental | show | savesettings >
Options:
Code:
auto: Automatically turn tribute on/off as you go in and out of combat. If you enter combat and tribute is not on, it is activated immediately. If you are not in combat when the tribute timer is going to expire, tribute is deactivated.
manual: Do not automatically turn on/off tribute. (default)
on: Turn on tribute but do not change auto/manual state.
off: Turn off tribute when current time left is going to expire. This option should not be combined with other options that change the operation mode.
forceoff: Turn off tribute immediately, ignoring any remainder of current time left.
enabledetrimental: Enable turning on tribute when casting a detrimental spell and in automatic mode.
enabledetrimental: Disables turning on tribute when casting a detrimental spell and in automatic mode. (default)
savesettings: Saves current settings to INI file (which will be loaded the next time the character logs in)
show: Show the current mode.
Multiple options can be passed as one command.
Example:
/tribute on auto
would turn the tribute on immediately and would automatically manage the state from then on. (ie, good before engaging a big named)
Code:
// MQ2TributeManager.cpp : Defines the entry point for the DLL application.
//
// MQ2TributeManager
// Manages tribute for you based on combat status
// Author: alt228, alt228@nerdshack.com
#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");
PLUGIN_VERSION(1.1);
//defaults
TributeMode mode = TributeMode_Manual;
bool tributeInitialized = false;
bool useDetrimentalSpell = false;
int tributeFudge = 2000;
VOID SetTributeStatus(bool tributeOn)
{
if( tributeOn )
{
if( !(bool)*pTributeActive )
{
DebugSpewAlways("MQ2TributeManager :: Turning on tribute");
SendWndClick("TributeBenefitWnd", "DowngradeButton", "leftmouseup");
}
}
else
{
if( (bool)*pTributeActive )
{
DebugSpewAlways("MQ2TributeManager :: Turning off tribute");
SendWndClick("TributeBenefitWnd", "DowngradeButton", "leftmouseup");
}
}
}
VOID LoadPreferences()
{
WriteChatColor("MQ2TributeManager :: Reading settings from INI file.");
CHAR iniSection[MAX_STRING];
sprintf(iniSection,"%s_%s",EQADDR_SERVERNAME, GetCharInfo()->Name);
CHAR iniMode[MAX_STRING];
CHAR iniDetrimentalSpell[MAX_STRING];
DebugSpewAlways("MQ2TributeManager :: Reading INI");
GetPrivateProfileString(iniSection, "Mode", "Manual", iniMode, 30, INIFileName);
GetPrivateProfileString(iniSection, "UseDetrimentalSpell", "0", iniDetrimentalSpell, 30, INIFileName);
if( (stricmp(iniMode, "Manual") == 0) && (mode != TributeMode_Manual) )
{
mode = TributeMode_OffWhenExpired;
}
else if( stricmp(iniMode, "Auto") == 0 )
{
mode = TributeMode_Auto;
}
useDetrimentalSpell = (stricmp(iniDetrimentalSpell,"1") == 0);
}
VOID SavePreferences()
{
CHAR iniSection[MAX_STRING];
CHAR valueTemp[MAX_STRING];
sprintf(iniSection,"%s_%s",EQADDR_SERVERNAME, GetCharInfo()->Name);
if( mode == TributeMode_Auto )
{
WritePrivateProfileString(iniSection, "Mode", "Auto", INIFileName);
}
else if( (mode == TributeMode_Manual) || (mode == TributeMode_OffWhenExpired) )
{
WritePrivateProfileString(iniSection, "Mode", "Manual", INIFileName);
}
sprintf(valueTemp,"%d",useDetrimentalSpell);
WritePrivateProfileString(iniSection, "UseDetrimentalSpell", valueTemp, INIFileName);
WriteChatColor("MQ2TributeManager :: Preferences Saved");
}
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;
bool saveSettings = 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;
}
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;
}
else if(stricmp(thisArg,"manual") == 0)
{
setMode = true;
newMode = TributeMode_Manual;
}
else if(stricmp(thisArg,"show") == 0)
{
showStatus = true;
}
else if(stricmp(thisArg,"savesettings") == 0)
{
saveSettings = true;
}
else if(stricmp(thisArg,"enabledetrimental") == 0)
{
useDetrimentalSpell = true;
}
else if(stricmp(thisArg,"disabledetrimental") == 0)
{
useDetrimentalSpell = false;
}
else
{
syntaxError = true;
}
}
if( syntaxError )
{
SyntaxError("Usage: /tribute < auto | manual | on | off | forceoff | enabledetrimental | disabledetrimental | show | savesettings >");
return;
}
if( setStatus )
{
SetTributeStatus(newStatus);
}
if( setMode )
{
mode = newMode;
}
if( showStatus )
{
CHAR buffer[MAX_STRING];
WriteChatColor("--------------------------------");
if( mode == TributeMode_Manual )
{
WriteChatColor("MQ2TributeManager :: Tribute mode: manual");
}
else if( mode == TributeMode_Auto )
{
WriteChatColor("MQ2TributeManager :: Tribute mode: automatic");
}
else if( mode == TributeMode_OffWhenExpired )
{
WriteChatColor("MQ2TributeManager :: Tribute mode: off when expired");
}
sprintf(buffer,"MQ2TributeManager :: Detrimental Spell Activation: %i", useDetrimentalSpell);
WriteChatColor(buffer);
if( gGameState == GAMESTATE_INGAME )
{
sprintf(buffer,"MQ2TributeManager :: Active Favor Cost: %i", pEQMisc->GetActiveFavorCost());
WriteChatColor(buffer);
sprintf(buffer,"MQ2TributeManager :: Combat State: %i", (CombatState)((PCPLAYERWND)pPlayerWnd)->CombatState);
WriteChatColor(buffer);
sprintf(buffer,"MQ2TributeManager :: Tribute Active: %i", *pTributeActive);
WriteChatColor(buffer);
sprintf(buffer,"MQ2TributeManager :: Current Favor: %i", GetCharInfo()->CurrFavor);
WriteChatColor(buffer);
sprintf(buffer,"MQ2TributeManager :: Tribute Timer: %i ms", GetCharInfo()->TributeTimer);
WriteChatColor(buffer);
}
WriteChatColor("--------------------------------");
}
if( saveSettings )
{
SavePreferences();
}
}
// Called once, when the plugin is to initialize
PLUGIN_API VOID InitializePlugin(VOID)
{
DebugSpewAlways("MQ2TributeManager :: Initializing");
AddCommand("/tribute",TributeManagerCmd);
}
// Called once, when the plugin is to shutdown
PLUGIN_API VOID ShutdownPlugin(VOID)
{
DebugSpewAlways("MQ2TributeManager :: Shutting down");
RemoveCommand("/tribute");
}
// This is called every time MQ pulses
PLUGIN_API VOID OnPulse(VOID)
{
if( gGameState != GAMESTATE_INGAME )
{
return;
}
if( mode == TributeMode_Auto )
{
PCHARINFO myCharInfo = GetCharInfo();
DWORD castingID = myCharInfo->pSpawn->CastingSpellID;
CombatState combatState = (CombatState)((PCPLAYERWND)pPlayerWnd)->CombatState;
int activeFavorCost = pEQMisc->GetActiveFavorCost();
bool inCombat = false;
if( combatState == CombatState_COMBAT )
{
inCombat = true;
}
if( (!inCombat) && (castingID != -1) && (useDetrimentalSpell) )
{
PSPELL casting = GetSpellByID(castingID);
if( casting->SpellType == 0 )
{
//detrimental spell
inCombat = true;
}
}
if( (inCombat) && (!*pTributeActive) && (activeFavorCost <= myCharInfo->CurrFavor) && (pEQMisc->GetActiveFavorCost() > 0) )
{
//activate tribute
SetTributeStatus(true);
}
else if( (!inCombat) && (*pTributeActive) && (myCharInfo->TributeTimer < tributeFudge) )
{
//deactivate tribute
SetTributeStatus(false);
}
}
else if( mode == TributeMode_OffWhenExpired )
{
if( (bool)*pTributeActive == false )
{
mode = TributeMode_Manual;
return;
}
if( GetCharInfo()->TributeTimer < tributeFudge )
{
mode = TributeMode_Manual;
SetTributeStatus(false);
}
}
}
PLUGIN_API VOID SetGameState(DWORD GameState)
{
if( GameState == GAMESTATE_INGAME )
{
if( !tributeInitialized )
{
DebugSpewAlways("MQ2TributeManager :: Making sure that TributeBenefitWnd has been opened at least once.");
DoCommand( (PSPAWNINFO)pCharSpawn, "/keypress TOGGLE_TRIBUTEBENEFITWIN" );
DoCommand( (PSPAWNINFO)pCharSpawn, "/keypress TOGGLE_TRIBUTEBENEFITWIN" );
LoadPreferences();
tributeInitialized = true;
}
}
else if( GameState == GAMESTATE_CHARSELECT )
{
tributeInitialized = false;
}
}
Compiled DLL attached.
alt228
alt228@nerdshack.com
Attachments
Last edited: