*Event Hooks (OnLogin, OnLogout, OnPVPKill) by Hawthorne

*Boss Emote Command for DB Scripts by XTElite1

--HG--
branch : trunk
This commit is contained in:
maximius
2009-09-13 00:01:35 -07:00
parent c61bb37a0e
commit eef5abe6e1
14 changed files with 105 additions and 4 deletions

View File

@@ -220,6 +220,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()
{

View File

@@ -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 );

View File

@@ -2645,6 +2645,10 @@
<Filter
Name="custom"
>
<File
RelativePath="..\scripts\custom\on_events.cpp"
>
</File>
<File
RelativePath="..\scripts\custom\npc_acherus_taxi.cpp"
>

View File

@@ -2643,6 +2643,10 @@
<Filter
Name="custom"
>
<File
RelativePath="..\scripts\custom\on_events.cpp"
>
</File>
<File
RelativePath="..\scripts\custom\npc_acherus_taxi.cpp"
>

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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
{

View File

@@ -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" ))

View File

@@ -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;

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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);