Credits to Gastricpenguin
Reposted because old thread was deleted
- Request for Sticky
C++ Script References
If you want to start scripting but don't know where to begin, take a look at the following scripts and work your way up. Just a heads up, these scripts are just the barebone functions and classes, you need to fill in the details and do whatever you wish. These scripts are written for Aspire using shared pointers, they are relatively easy to convert to an ArcEmu format.
Anything highlighted in yellow should be edited accordingly.
Gossip Scripts
Good for making teleporters, scripted events, scripted items, etc.
Code:
class ITEMSCRIPT : public GossipScript
{
public:
void GossipHello(ObjectPointer pObject, PlayerPointer Plr, bool AutoSend)
{
//STUFF
}
void GossipSelectOption(ObjectPointer pObject, PlayerPointer Plr, uint32 Id, uint32 IntId, const char * Code)
{
switch(IntId)
{
case 0:
GossipHello(pObject, Plr, true);
break;
}
}
void GossipEnd(ObjectPointer pObject, PlayerPointer Plr)
{
GossipScript::GossipEnd(pObject, Plr);
}
void Destroy()
{
delete this;
}
};
void Setup(ScriptMgr * mgr)
{
GossipScript * itr = (GossipScript*) new ITEMSCRIPT();
mgr->register_gossip_script(ENTRY_ID, itr); //NPC Gossip
mgr->register_go_gossip_script(ENTRY_ID, itr); //GameObject Gossip
mgr->register_item_gossip_script(ENTRY_ID, itr); //Item Gossip
}
GameObject Scripts
Script an object to spawn some monsters when activated.
Code:
class OBJECTSCRIPT : public GameObjectAIScript
{
public:
OBJECTSCRIPT(GameObjectPointer goinstance) : GameObjectAIScript( goinstance ) {}
GameObjectAIScript *Create(GameObjectPointer GO)
{
return new OBJECTSCRIPT(GO);
}
void OnActivate(PlayerPointer pPlayer)
{
//STUFF
}
void OnCreate()
{
//STUFF
}
void OnSpawn()
{
//STUFF
}
void OnDespawn()
{
//STUFF
}
void AIUpdate()
{
//STUFF
}
};
void Setup(ScriptMgr * mgr)
{
mgr->register_gameobject_script(ENTRYID, &OBJECTSCRIPT::Create);
}
Instance Scripts
This one I like very much. Completely customize an instance or map using this framework.
Code:
class INSTANCEAI : public InstanceScript
{
public:
ADD_INSTANCE_FACTORY_FUNCTION(INSTANCEAI);
INSTANCEAI(MapMgrPointer pMapMgr) : InstanceScript(pMapMgr) {}
void OnLoad()
{
//STUFF
}
void OnPlayerDeath(PlayerPointer pVictim, UnitPointer pKiller)
{
//STUFF
}
void OnPlayerEnter(PlayerPointer pPlayer)
{
//STUFF
}
void OnAreaTrigger(PlayerPointer pPlayer, uint32 pAreaId)
{
//STUFF
}
void OnZoneChange(PlayerPointer pPlayer, uint32 pNewZone, uint32 pOldZone)
{
//STUFF
}
void OnCreatureDeath(CreaturePointer pVictim, UnitPointer pKiller)
{
//STUFF
}
void OnGameObjectActivate(GameObjectPointer pGameObject, PlayerPointer pPlayer)
{
//STUFF
}
};
void Setup(ScriptMgr * mgr)
{
mgr->register_instance_script(MAP_ID, &INSTANCEAI::Create);
}
Quest Scripts
More fun quest scripts, better than using the hooks.
Code:
class QUESTAI : public QuestScript
{
public:
void OnQuestStart(PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
void OnQuestComplete(PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
void OnQuestCancel(PlayerPointer mTarget)
{
//STUFF
}
void OnGameObjectActivate(uint32 entry, PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
void OnCreatureKill(uint32 entry, PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
void OnExploreArea(uint32 areaId, PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
void OnPlayerItemPickup(uint32 itemId, uint32 totalCount, PlayerPointer mTarget, QuestLogEntry *qle)
{
//STUFF
}
};
void Setup(ScriptMgr * mgr)
{
QuestScript * qs = (QuestScript*) new QUESTAI();
mgr->register_quest_script(ENTRY_ID, qs);
}
Creature Scripts
Make a better and more entertaining bossfight via a script.
Code:
class CREATURESCRIPT : public CreatureAIScript
{
public:
ADD_CREATURE_FACTORY_FUNCTION(CREATURESCRIPT);
CREATURESCRIPT(CreaturePointer pCreature) : CreatureAIScript(pCreature) {}
void OnCombatStart(UnitPointer mTarget)
{
//STUFF
}
void OnCombatStop(UnitPointer mTarget)
{
//STUFF
}
void OnDamageTaken(UnitPointer mAttacker, float fAmount)
{
//STUFF
}
void OnCastSpell(uint32 iSpellId)
{
//STUFF
}
void OnTargetParried(UnitPointer mTarget)
{
//STUFF
}
void OnTargetDodged(UnitPointer mTarget)
{
//STUFF
}
void OnTargetBlocked(UnitPointer mTarget, int32 iAmount)
{
//STUFF
}
void OnTargetCritHit(UnitPointer mTarget, float fAmount)
{
//STUFF
}
void OnTargetDied(UnitPointer mTarget)
{
//STUFF
}
void OnParried(UnitPointer mTarget)
{
//STUFF
}
void OnDodged(UnitPointer mTarget)
{
//STUFF
}
void OnBlocked(UnitPointer mTarget, int32 iAmount)
{
//STUFF
}
void OnCritHit(UnitPointer mTarget, float fAmount)
{
//STUFF
}
void OnHit(UnitPointer mTarget, float fAmount)
{
//STUFF
}
void OnAssistTargetDied(UnitPointer mAssistTarget)
{
//STUFF
}
void OnFear(UnitPointer mFeared, uint32 iSpellId)
{
//STUFF
}
void OnFlee(UnitPointer mFlee)
{
//STUFF
}
void OnDied(UnitPointer mKiller)
{
//STUFF
}
void AIUpdate()
{
//STUFF
}
};
void Setup(ScriptMgr * mgr)
{
mgr->register_creature_script(ENTRY_ID, &CREATURESCRIPT::Create);
}
Setup.cpp
Needed for compiling your script.
Code:
#include "StdAfx.h"
#include "Setup.h"
#define SKIP_ALLOCATOR_SHARING 1
#include <ScriptSetup.h>
extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
{
return SCRIPT_TYPE_MISC;
}
extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
{
Setup(mgr);
}
#ifdef WIN32
BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved )
{
return TRUE;
}
#endif
Setup.h
Goes along with Setup.cpp
Code:
#ifndef CUSTOMSCRIPTS_H
#define CUSTOMSCRIPTS_H
void Setup(ScriptMgr * mgr);
#endif