diff options
author | maximius <none@none> | 2009-09-13 00:01:35 -0700 |
---|---|---|
committer | maximius <none@none> | 2009-09-13 00:01:35 -0700 |
commit | eef5abe6e1931eeae91d3a1ed68a3bf44237dea2 (patch) | |
tree | b4d2edf33613bfefe67bd534b0e3fe9622617ff7 | |
parent | c61bb37a0e80aae1dc24618782647c43d2feb174 (diff) |
*Event Hooks (OnLogin, OnLogout, OnPVPKill) by Hawthorne
*Boss Emote Command for DB Scripts by XTElite1
--HG--
branch : trunk
-rw-r--r-- | src/bindings/scripts/ScriptMgr.cpp | 24 | ||||
-rw-r--r-- | src/bindings/scripts/ScriptMgr.h | 3 | ||||
-rw-r--r-- | src/bindings/scripts/VC80/80ScriptDev2.vcproj | 4 | ||||
-rw-r--r-- | src/bindings/scripts/VC90/90ScriptDev2.vcproj | 4 | ||||
-rw-r--r-- | src/bindings/scripts/scripts/custom/on_events.cpp | 31 | ||||
-rw-r--r-- | src/bindings/scripts/system/ScriptLoader.cpp | 2 | ||||
-rw-r--r-- | src/game/CharacterHandler.cpp | 5 | ||||
-rw-r--r-- | src/game/Map.cpp | 2 | ||||
-rw-r--r-- | src/game/ObjectMgr.cpp | 7 | ||||
-rw-r--r-- | src/game/ScriptCalls.cpp | 3 | ||||
-rw-r--r-- | src/game/ScriptCalls.h | 9 | ||||
-rw-r--r-- | src/game/Unit.cpp | 9 | ||||
-rw-r--r-- | src/game/World.h | 2 | ||||
-rw-r--r-- | src/game/WorldSession.cpp | 4 |
14 files changed, 105 insertions, 4 deletions
diff --git a/src/bindings/scripts/ScriptMgr.cpp b/src/bindings/scripts/ScriptMgr.cpp index ba26d02acbe..7d1f27b2f96 100644 --- a/src/bindings/scripts/ScriptMgr.cpp +++ b/src/bindings/scripts/ScriptMgr.cpp @@ -221,6 +221,30 @@ void Script::RegisterSelf() //*** Functions to be Exported *** TRINITY_DLL_EXPORT +void OnLogin(Player *pPlayer) +{ + Script *tmpscript = m_scripts[GetScriptId("scripted_on_events")]; + if (!tmpscript || !tmpscript->pOnLogin) return; + tmpscript->pOnLogin(pPlayer); +} + +TRINITY_DLL_EXPORT +void OnLogout(Player *pPlayer) +{ + Script *tmpscript = m_scripts[GetScriptId("scripted_on_events")]; + if (!tmpscript || !tmpscript->pOnLogout) return; + tmpscript->pOnLogout(pPlayer); +} + +TRINITY_DLL_EXPORT +void OnPVPKill(Player *killer, Player *killed) +{ + Script *tmpscript = m_scripts[GetScriptId("scripted_on_events")]; + if (!tmpscript || !tmpscript->pOnPVPKill) return; + tmpscript->pOnPVPKill(killer, killed); +} + +TRINITY_DLL_EXPORT char const* ScriptsVersion() { return "Default Trinity scripting library"; diff --git a/src/bindings/scripts/ScriptMgr.h b/src/bindings/scripts/ScriptMgr.h index ad341a98098..5b5ce118236 100644 --- a/src/bindings/scripts/ScriptMgr.h +++ b/src/bindings/scripts/ScriptMgr.h @@ -43,6 +43,9 @@ struct Script std::string Name; //Methods to be scripted + void (*pOnLogin )(Player*); + void (*pOnLogout )(Player*); + void (*pOnPVPKill )(Player*, Player*); bool (*pGossipHello )(Player*, Creature*); bool (*pQuestAccept )(Player*, Creature*, Quest const* ); bool (*pGossipSelect )(Player*, Creature*, uint32 , uint32 ); diff --git a/src/bindings/scripts/VC80/80ScriptDev2.vcproj b/src/bindings/scripts/VC80/80ScriptDev2.vcproj index 8443677330b..1335502ace7 100644 --- a/src/bindings/scripts/VC80/80ScriptDev2.vcproj +++ b/src/bindings/scripts/VC80/80ScriptDev2.vcproj @@ -2646,6 +2646,10 @@ Name="custom" > <File + RelativePath="..\scripts\custom\on_events.cpp" + > + </File> + <File RelativePath="..\scripts\custom\npc_acherus_taxi.cpp" > </File> diff --git a/src/bindings/scripts/VC90/90ScriptDev2.vcproj b/src/bindings/scripts/VC90/90ScriptDev2.vcproj index 825e28964cf..be11b1110e7 100644 --- a/src/bindings/scripts/VC90/90ScriptDev2.vcproj +++ b/src/bindings/scripts/VC90/90ScriptDev2.vcproj @@ -2644,6 +2644,10 @@ Name="custom" > <File + RelativePath="..\scripts\custom\on_events.cpp" + > + </File> + <File RelativePath="..\scripts\custom\npc_acherus_taxi.cpp" > </File> diff --git a/src/bindings/scripts/scripts/custom/on_events.cpp b/src/bindings/scripts/scripts/custom/on_events.cpp new file mode 100644 index 00000000000..0f6a23698c5 --- /dev/null +++ b/src/bindings/scripts/scripts/custom/on_events.cpp @@ -0,0 +1,31 @@ +#include "precompiled.h" +#include <cstring> + +//This function is called when the player logs in (every login) +void OnLogin(Player *pPlayer) +{ + +} + +//This function is called when the player logs out +void OnLogout(Player *pPlayer) +{ + +} + +//This function is called when the player kills another player +void OnPVPKill(Player *killer, Player *killed) +{ + +} + + void AddSC_onevents() +{ + Script *newscript; + newscript = new Script; + newscript->Name = "scripted_on_events"; + newscript->pOnLogin = &OnLogin; + newscript->pOnLogout = &OnLogout; + newscript->pOnPVPKill = &OnPVPKill; + newscript->RegisterSelf(); +} diff --git a/src/bindings/scripts/system/ScriptLoader.cpp b/src/bindings/scripts/system/ScriptLoader.cpp index 5e9307902be..f21c5e1fb0d 100644 --- a/src/bindings/scripts/system/ScriptLoader.cpp +++ b/src/bindings/scripts/system/ScriptLoader.cpp @@ -397,6 +397,7 @@ extern void AddSC_shadowmoon_valley(); extern void AddSC_shattrath_city(); extern void AddSC_terokkar_forest(); extern void AddSC_zangarmarsh(); +extern void AddSC_onevents(); void AddScripts() { @@ -793,4 +794,5 @@ void AddScripts() AddSC_shattrath_city(); AddSC_terokkar_forest(); AddSC_zangarmarsh(); + AddSC_onevents(); } diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp index becf81d9c04..c65c923a31e 100644 --- a/src/game/CharacterHandler.cpp +++ b/src/game/CharacterHandler.cpp @@ -42,6 +42,7 @@ #include "SocialMgr.h" #include "UpdateMask.h" #include "Util.h" +#include "ScriptCalls.h" class LoginQueryHolder : public SqlQueryHolder { @@ -812,6 +813,10 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder * holder) pCurrChar->SetStandState(UNIT_STAND_STATE_STAND); m_playerLoading = false; + + //Hook for OnLogin Event + Script->OnLogin(pCurrChar); + delete holder; } diff --git a/src/game/Map.cpp b/src/game/Map.cpp index ee6ca6f8291..2953236bcbd 100644 --- a/src/game/Map.cpp +++ b/src/game/Map.cpp @@ -2866,7 +2866,7 @@ void Map::ScriptsProcess() sLog.outError("SCRIPT_COMMAND_TALK call for non-creature (TypeId: %u, Entry: %u, GUID: %u), skipping.",source->GetTypeId(),source->GetEntry(),source->GetGUIDLow()); break; } - if(step.script->datalong > 3) + if(step.script->datalong > 4) { sLog.outError("SCRIPT_COMMAND_TALK invalid chat type (%u), skipping.",step.script->datalong); break; diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp index a1e19eb178a..2f4bad688ef 100644 --- a/src/game/ObjectMgr.cpp +++ b/src/game/ObjectMgr.cpp @@ -4297,7 +4297,7 @@ void ObjectMgr::LoadScripts(ScriptMapMap& scripts, char const* tablename) { case SCRIPT_COMMAND_TALK: { - if(tmp.datalong > 3) + if(tmp.datalong > 4) { sLog.outErrorDb("Table `%s` has invalid talk type (datalong = %u) in SCRIPT_COMMAND_TALK for script id %u",tablename,tmp.datalong,tmp.id); continue; @@ -8377,7 +8377,10 @@ void ObjectMgr::LoadScriptNames() } barGoLink bar( result->GetRowCount() ); - uint32 count = 0; + + //OnEvent Changes + m_scriptNames.push_back("scripted_on_events"); + uint32 count = 1; do { diff --git a/src/game/ScriptCalls.cpp b/src/game/ScriptCalls.cpp index b8870c2a1dd..8a075448daf 100644 --- a/src/game/ScriptCalls.cpp +++ b/src/game/ScriptCalls.cpp @@ -59,6 +59,9 @@ bool LoadScriptingModule(char const* libName) } if( !(testScript->ScriptsInit =(scriptCallScriptsInit )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" )) + ||!(testScript->OnLogin =(scriptCallOnLogin )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogin" )) + ||!(testScript->OnLogout =(scriptCallOnLogout )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnLogout" )) + ||!(testScript->OnPVPKill =(scriptCallOnPVPKill )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"OnPVPKill" )) ||!(testScript->ScriptsFree =(scriptCallScriptsFree )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" )) ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" )) ||!(testScript->GossipHello =(scriptCallGossipHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" )) diff --git a/src/game/ScriptCalls.h b/src/game/ScriptCalls.h index 0eae69cb505..bb6ecee3b89 100644 --- a/src/game/ScriptCalls.h +++ b/src/game/ScriptCalls.h @@ -37,6 +37,11 @@ class InstanceData; bool LoadScriptingModule(char const* libName = ""); void UnloadScriptingModule(); +//On Event Handlers +typedef void(TRINITY_IMPORT * scriptCallOnLogin) (Player *pPlayer); +typedef void(TRINITY_IMPORT * scriptCallOnLogout) (Player *pPlayer); +typedef void(TRINITY_IMPORT * scriptCallOnPVPKill) (Player *killer, Player *killed); + typedef void(TRINITY_IMPORT * scriptCallScriptsInit) (char const*); typedef void(TRINITY_IMPORT * scriptCallScriptsFree) (); typedef char const* (TRINITY_IMPORT * scriptCallScriptsVersion) (); @@ -72,6 +77,10 @@ typedef struct scriptCallScriptsFree ScriptsFree; scriptCallScriptsVersion ScriptsVersion; + scriptCallOnLogin OnLogin; + scriptCallOnLogout OnLogout; + scriptCallOnPVPKill OnPVPKill; + scriptCallGossipHello GossipHello; scriptCallGOChooseReward GOChooseReward; scriptCallQuestAccept QuestAccept; diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index e73f8ec80de..607018cd8cb 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -53,6 +53,7 @@ #include "TemporarySummon.h" #include "Vehicle.h" #include "Transports.h" +#include "ScriptCalls.h" #include <math.h> @@ -778,6 +779,14 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa ((Player*)pVictim)->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED, health); Kill(pVictim, durabilityLoss); + + //Hook for OnPVPKill Event + if (pVictim->GetTypeId() == TYPEID_PLAYER && this->GetTypeId() == TYPEID_PLAYER) + { + Player *killer = ((Player*)this); + Player *killed = ((Player*)pVictim); + Script->OnPVPKill(killer, killed); + } } else // if (health <= damage) { diff --git a/src/game/World.h b/src/game/World.h index 9d5085c3b7f..6cd1fb6a82e 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -386,7 +386,7 @@ enum RealmZone }; // DB scripting commands -#define SCRIPT_COMMAND_TALK 0 // source = unit, target=any, datalong ( 0=say, 1=whisper, 2=yell, 3=emote text) +#define SCRIPT_COMMAND_TALK 0 // source = unit, target=any, datalong (0=say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text) #define SCRIPT_COMMAND_EMOTE 1 // source = unit, datalong = anim_id #define SCRIPT_COMMAND_FIELD_SET 2 // source = any, datalong = field_id, datalog2 = value #define SCRIPT_COMMAND_MOVE_TO 3 // source = Creature, datalog2 = time, x/y/z diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp index d80ede80bc7..4cb251d6524 100644 --- a/src/game/WorldSession.cpp +++ b/src/game/WorldSession.cpp @@ -40,6 +40,7 @@ #include "MapManager.h" #include "SocialMgr.h" #include "zlib/zlib.h" +#include "ScriptCalls.h" /// WorldSession constructor WorldSession::WorldSession(uint32 id, WorldSocket *sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale) : @@ -451,6 +452,9 @@ void WorldSession::LogoutPlayer(bool Save) sLog.outDebug( "SESSION: Sent SMSG_LOGOUT_COMPLETE Message" ); } + //Hook for OnLogout Event + Script->OnLogout(_player); + m_playerLogout = false; m_playerRecentlyLogout = true; LogoutRequest(0); |