Likes: 0
Results 1 to 1 of 1
Thread: ¤Trinity¤ Dynamic Teleporter
-
07-09-12, 08:08 AM #1
¤Trinity¤ Dynamic Teleporter
Register to remove this adThis instruction not somehow broken.
So with to we let go!
###################################
#### Dynamic Teleporter (v1.0) ####
###################################
You need to change a location?To remove or completely redo teleporter?No problem, you can do it for the server!Wallop no? XD
Finally you properly will practice CTRL+C.
Lets go!
SQL:
Table include to world DB:
Code:/*Table structure for table `dynamic_teleporter` */ CREATE TABLE `dynamic_teleporter` ( `entry` int(11) unsigned NOT NULL, `menu_parent` int(11) unsigned NOT NULL DEFAULT '0', `menu_sub` int(11) NOT NULL DEFAULT '-1', `icon` tinyint(3) unsigned NOT NULL DEFAULT '0', `faction` int(11) unsigned NOT NULL DEFAULT '0', `name` char(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `map` smallint(5) unsigned NOT NULL DEFAULT '0', `position_x` float NOT NULL DEFAULT '0', `position_y` float NOT NULL DEFAULT '0', `position_z` float NOT NULL DEFAULT '0', `position_o` float NOT NULL DEFAULT '0', PRIMARY KEY (`entry`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC;
(intended location src/server/scripts/Custom/dynamic_teleporter.cpp)
Code:/******************************************************* * File:'dynamic_teleporter.cpp' * ScriptName:'npc_dynamic_teleporter' * (c)2011 - Wolf Officious *******************************************************/ /* -- NPC SQL EXAMPLE REPLACE INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction_A`, `faction_H`, `npcflag`, `speed_walk`, `speed_run`, `scale`, `rank`, `mindmg`, `maxdmg`, `dmgschool`, `attackpower`, `dmg_multiplier`, `baseattacktime`, `rangeattacktime`, `unit_class`, `unit_flags`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `minrangedmg`, `maxrangedmg`, `rangedattackpower`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `spell1`, `spell2`, `spell3`, `spell4`, `spell5`, `spell6`, `spell7`, `spell8`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `InhabitType`, `Health_mod`, `Mana_mod`, `Armor_mod`, `RacialLeader`, `questItem1`, `questItem2`, `questItem3`, `questItem4`, `questItem5`, `questItem6`, `movementId`, `RegenHealth`, `equipment_id`, `mechanic_immune_mask`, `flags_extra`, `ScriptName`, `WDBVerified`) VALUES('700020','0','0','0','0','0','736','0','0','0','Dynamic Teleporter','TEST','','0','80','80','1','35','35','1','1','1.14286','2','0','5000','5000','0','35000','10','1','0','1','512','0','0','0','0','0','0','10000','10000','68','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','','0','3','20','20','20','0','0','0','0','0','0','0','0','255','0','0','0','npc_dynamic_teleporter','0'); */ #include "ScriptPCH.h" #include "DynamicTeleportMgr.h" class npc_dynamic_teleporter : public CreatureScript { private: // COMBAT CHECKER inline bool isInCombat(Player *player) { if(player->isInCombat()) { player->GetSession()->SendNotification("You are in combat!"); return true; } return false; } // SHOW MENU BY ID inline void ShowMenu(Player *player, Creature *_Creature, uint32 menu_id) { if(!sDynamicTeleportMgr->isLoaded()) { player->CLOSE_GOSSIP_MENU(); return; } uint32 count = 0; uint8 send_counter = 0; if(player->isGameMaster() && menu_id == 0) { ++count; player->ADD_GOSSIP_ITEM(5, "~RELOAD TELEPORTER DATA~\n", GOSSIP_SENDER_MAIN, 666); } for(uint32 itr = 0; itr < sDynamicTeleportMgr->GetCount(); itr++) { TeleportData const* td; td = sDynamicTeleportMgr->GetTeleportData(itr); if(td) { if(td->menu_parent == menu_id) { if(td->faction == 0 || player->GetTeam() == td->faction) // HORDE 67, ALLIANCE 469 { uint8 icon_id = td->icon; if(icon_id > 9) { icon_id = 0; } player->ADD_GOSSIP_ITEM(icon_id, td->name.c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + td->entry); ++count; ++send_counter; if(send_counter >= 10) { player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, _Creature->GetGUID()); send_counter = 0; } } } } else { sLog->outError("TD_ERROR: UNK1 (!td)"); return; } } if(send_counter != 0 || count == 0) player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, _Creature->GetGUID()); } // TELEPORT PROCESS inline void TeleportToTarget(Player *player, uint32 target_id) { if(!sDynamicTeleportMgr->isLoaded()) { player->CLOSE_GOSSIP_MENU(); return; } TeleportLoc const* tl; tl = sDynamicTeleportMgr->GetTeleportLoc(target_id); if(tl) { player->TeleportTo(tl->map, tl->position_x, tl->position_y, tl->position_z, tl->position_o); } else { sLog->outError("TD_ERROR: UNK1 (!tl)"); } return; } // ACTION TYPE HANDLER inline bool HandleMenuAction(Player *player, Creature *_Creature, uint32 action) { if(!sDynamicTeleportMgr->isLoaded()) return false; for(uint32 itr = 0; itr < sDynamicTeleportMgr->GetCount(); itr++) { TeleportData const* td; td = sDynamicTeleportMgr->GetTeleportData(itr); if(td) { if(td->entry == action - GOSSIP_ACTION_INFO_DEF) { if(td->menu_sub < 0) { TeleportToTarget(player, action - GOSSIP_ACTION_INFO_DEF); return true; } else { ShowMenu(player, _Creature, td->menu_sub); return true; } } } else { sLog->outError("TD_ERROR: UNK1 (!td)"); return false; } } return false; } public: npc_dynamic_teleporter() : CreatureScript("npc_dynamic_teleporter") { } bool OnGossipHello(Player *player, Creature *_Creature) { if(isInCombat(player) || !sDynamicTeleportMgr->isLoaded()) return false; ShowMenu(player, _Creature, 0); return true; } bool OnGossipSelect(Player *player, Creature *_Creature, uint32 sender, uint32 action) { if(sender != GOSSIP_SENDER_MAIN || isInCombat(player) || !sDynamicTeleportMgr->isLoaded()) { player->CLOSE_GOSSIP_MENU(); return true; } player->PlayerTalkClass->ClearMenus(); if(action == 666 && player->isGameMaster()) { player->CLOSE_GOSSIP_MENU(); sDynamicTeleportMgr->Update(); player->GetSession()->SendNotification("Reloaded.."); return true; } if(!HandleMenuAction(player, _Creature, action)) { player->CLOSE_GOSSIP_MENU(); } return true; } }; void AddSC_npc_dynamic_teleporter() { new npc_dynamic_teleporter(); }
Create a new file: src / server / game / Entities / Player / DynamicTeleportMgr.h
Code:/******************************************************* * File:'DynamicTeleportMgr.h' * * (c)2011 - Wolf Officious *******************************************************/ #ifndef _DYNTEL_H #define _DYNTEL_H #include <ace/Singleton.h> #include "Common.h" #include "World.h" //#include "SQLStorage.h" struct TeleportData { uint32 entry; uint32 menu_parent; int32 menu_sub; uint8 icon; uint32 faction; std::string name; }; struct TeleportLoc { uint32 map; float position_x; float position_y; float position_z; float position_o; }; typedef UNORDERED_MAP<uint32, TeleportData> TeleportDataMap; typedef UNORDERED_MAP<uint32, TeleportLoc> TeleportLocMap; class DynamicTeleportMgr { public: DynamicTeleportMgr() { m_isLoaded = false; } ~DynamicTeleportMgr() {} bool Init(); void Update(); bool isLoaded() { return m_isLoaded; } inline TeleportData const* GetTeleportData(uint32 id) const { TeleportDataMap::const_iterator itr = mTeleportData.find(id); return itr != mTeleportData.end() ? &itr->second : NULL; } uint32 GetCount() { return mTeleportData.size(); } inline TeleportLoc const* GetTeleportLoc(uint32 id) const { TeleportLocMap::const_iterator itr = mTeleportLoc.find(id); return itr != mTeleportLoc.end() ? &itr->second : NULL; } private: TeleportDataMap mTeleportData; TeleportLocMap mTeleportLoc; bool m_isLoaded; }; #define sDynamicTeleportMgr ACE_Singleton<DynamicTeleportMgr, ACE_Null_Mutex>::instance() #endif // _DYNTEL_H
Code:/******************************************************* * File:'DynamicTeleportMgr.cpp' * * (c)2011 - Wolf Officious *******************************************************/ #include "DynamicTeleportMgr.h" bool DynamicTeleportMgr::Init() { uint32 oldMSTime = getMSTime(); mTeleportData.clear(); mTeleportLoc.clear(); // 0 1 2 3 4 5 6 7 8 9 10 QueryResult result = WorldDatabase.Query("SELECT entry, menu_parent, menu_sub, icon, faction, name, map, position_x, position_y, position_z, position_o " "FROM dynamic_teleporter ORDER BY entry"); if(!result) { sLog->outString(">> Loaded 0 Dynamic Teleporter rows. DB table `dynamic_teleporter` is empty!"); return false; } uint32 counter = 0; do { Field *fields = result->Fetch(); TeleportData td; td.entry = fields[0].GetUInt32(); td.menu_parent = fields[1].GetUInt32(); td.menu_sub = fields[2].GetInt32(); td.icon = fields[3].GetUInt8(); td.faction = fields[4].GetUInt32(); td.name = fields[5].GetString(); if(td.menu_sub < 0) { TeleportLoc tl; tl.map = fields[6].GetUInt32(); tl.position_x = fields[7].GetFloat(); tl.position_y = fields[8].GetFloat(); tl.position_z = fields[9].GetFloat(); tl.position_o = fields[10].GetFloat(); mTeleportLoc[td.entry] = tl; } mTeleportData[counter] = td; ++counter; } while(result->NextRow()); sLog->outString(">> Loaded %u Dynamic Teleporter rows in %u ms", counter, GetMSTimeDiffToNow(oldMSTime)); m_isLoaded = true; return true; } void DynamicTeleportMgr::Update() { m_isLoaded = false; Init(); }
file: src / server / game / World / World.cpp
From roughly the beginning of the file, add include:
Code:# include "DynamicTeleportMgr.h" / / WLK - DYNAMIC Teleporter
Code:+ / / WLK - DYNAMIC Teleporter + SDynamicTeleportMgr-> Init (); uint32 startupDuration = GetMSTimeDiffToNow (startupBegin); sLog-> outString (); sLog-> outString ("WORLD: World initialized in% u minutes% u seconds", (startupDuration / 60000), ((startupDuration% 60000) / 1000)); sLog-> outString (); }
Credits to xDrive for this script
› See More: ¤Trinity¤ Dynamic Teleporter