// MQ2ChuckNorris.cpp : Informs people about how cool Chuck Norris really is.
// - Brought to you by MMOBugs.com
//
//
// Commands:
// /chuckpower - Makes your targeted PC (or self) swell with the power of
// Chuck Norris, making them 10x their normal size!
//
// /chuckant - Makes your target cower in fear, and shrink at the threat
// of being smacked down by Chuck Norris
//
// /chuckreset - Returns your target to normal size
//
// /chuck /<channel> - Picks a random fact from INI file and splits it out
//
// Example: /chuck /gu - Would spout out a random chuck fact to Guild Chat
// /chuck /1 - Would spout out a random chuck fact to channel 1
// /chuck /ooc 30 - Would spout out chuck fact 30 (as listed in the INI)
#include "../MQ2Plugin.h"
PreSetup("MQ2ChuckNorris");
// Comment this out to update the offsets/opcodes/structs manually
#define UseMMOBugs True
#ifdef UseMMOBugs
#include "../MQ2MMOBugs.h"
#else
// Offset: 3-15-06
#define SizeFuncOffset 0x4F3210
#endif
class SizeClass
{
public:
void SizeFunc(float);
};
FUNCTION_AT_ADDRESS(void SizeClass::SizeFunc(float), SizeFuncOffset);
char ChuckFact[MAX_STRING][MAX_STRING];
char ChuckEcho[MAX_STRING][MAX_STRING];
int MaxFacts=0;
int MaxEcho=0;
int ChuckFactLast=0;
VOID LoadArray(VOID)
{
char szTemp[MAX_STRING];
for (unsigned long i = 1; i < MAX_STRING; i++)
{
sprintf(szTemp, "chuck%i", i);
GetPrivateProfileString("Chuck",szTemp,NULL,ChuckFact[i],MAX_STRING,INIFileName);
if (strlen(ChuckFact[i]) == 0)
{
MaxFacts = i-1;
sprintf(szTemp, "MQ2ChuckNorris: Found %i Chuck Norris Facts in INI file",MaxFacts);
WriteChatColor(szTemp, CONCOLOR_GREEN);
if (MaxFacts <= 0)
{
WriteChatColor("No INI file or INI file empty! Shutting down and unloading plugin", CONCOLOR_RED);
DoCommand((PSPAWNINFO)pCharSpawn,"/plugin MQ2ChuckNorris unload");
}
return;
}
}
}
VOID LoadEchoArray(VOID)
{
char szTemp[MAX_STRING];
for (unsigned long i = 1; i < MAX_STRING; i++)
{
sprintf(szTemp, "echo%i", i);
GetPrivateProfileString("Echo",szTemp,NULL,ChuckEcho[i],MAX_STRING,INIFileName);
if (strlen(ChuckEcho[i]) == 0)
{
MaxEcho = i-1;
if (MaxEcho <= 0)
{
sprintf(ChuckEcho[1], "Chuck Norris round-house kicks you in the face while saying fact");
MaxEcho = 1;
}
return;
}
}
}
VOID ChuckStuff(PSPAWNINFO pChar, PCHAR szLine)
{
char szTemp[MAX_STRING];
char szChat[MAX_STRING];
int ChuckFactNum=0;
int ChuckEchoNum=0;
GetArg(szChat,szLine,1);
GetArg(szTemp,szLine,2);
if ((strlen(szChat)==0) || ((szChat[0] != '/') && (szChat[0] != ';')))
{
WriteChatColor("MQ2ChuckNorris: You must enter a chat channel (i.e. /gu, /shout, etc)",CONCOLOR_RED);
return;
}
ChuckFactNum = atoi(szTemp);
if ((!ChuckFactNum) || (ChuckFactNum > MaxFacts))
{
ChuckFactNum = (rand()%MaxFacts)+1;
if (ChuckFactNum == ChuckFactLast)
ChuckFactNum++;
if (ChuckFactNum >= (MaxFacts+1))
ChuckFactNum = (ChuckFactNum-(rand()%MaxFacts));
}
ChuckFactLast = ChuckFactNum;
sprintf(szTemp, "%s %s", szChat, ChuckFact[ChuckFactNum]);
DoCommand(pChar, szTemp);
ChuckEchoNum = (rand()%MaxEcho)+1;
sprintf(szTemp, "%s %i", ChuckEcho[ChuckEchoNum],ChuckFactNum);
WriteChatColor(szTemp, CONCOLOR_LIGHTBLUE);
}
VOID ChuckPower(PSPAWNINFO pChar, PCHAR szLine)
{
char szTemp[MAX_STRING];
char szArg[MAX_STRING]={0};
GetArg(szArg,szLine,1);
if (ppTarget && pTarget)
{
PSPAWNINFO Target = (PSPAWNINFO)pTarget;
{
sprintf(szTemp,"%s has been given the power of Chuck Norris!", Target->DisplayedName);
WriteChatColor(szTemp, CONCOLOR_YELLOW);
((SizeClass*)Target)->SizeFunc((float)40);
}
}
}
VOID ChuckAnt(PSPAWNINFO pChar, PCHAR szLine)
{
char szTemp[MAX_STRING];
char szArg[MAX_STRING]={0};
GetArg(szArg,szLine,1);
if (ppTarget && pTarget)
{
PSPAWNINFO Target = (PSPAWNINFO)pTarget;
{
sprintf(szTemp,"%s has been smacked down to size by Chuck Norris!", Target->DisplayedName);
WriteChatColor(szTemp, CONCOLOR_YELLOW);
((SizeClass*)Target)->SizeFunc((float)1);
}
}
}
VOID ChuckReset(PSPAWNINFO pChar, PCHAR szLine)
{
char szTemp[MAX_STRING];
char szArg[MAX_STRING]={0};
GetArg(szArg,szLine,1);
if (ppTarget && pTarget)
{
PSPAWNINFO Target = (PSPAWNINFO)pTarget;
{
sprintf(szTemp,"Chuck Norris has restored %s to normal", Target->DisplayedName);
WriteChatColor(szTemp, CONCOLOR_YELLOW);
((SizeClass*)Target)->SizeFunc((float)0);
}
}
}
PLUGIN_API VOID InitializePlugin(VOID)
{
WriteChatColor("MQ2ChuckNorris - Brought to you by MMOBugs.com",CONCOLOR_YELLOW);
AddCommand("/chuck", ChuckStuff);
AddCommand("/chuckpower", ChuckPower);
AddCommand("/chuckant", ChuckAnt);
AddCommand("/chuckreset", ChuckReset);
LoadArray();
LoadEchoArray();
srand(time(0));
}
PLUGIN_API VOID ShutdownPlugin(VOID)
{
RemoveCommand("/chuck");
RemoveCommand("/chuckpower");
RemoveCommand("/chuckant");
RemoveCommand("/chuckreset");
}