|
|
Модератор форума: Dimitro |
Форум ArcEmu ArcEmu Вкусняшки от буржуев) |
Вкусняшки от буржуев) |
Доброго времени суток ув.форумчане, для того чтобы понять принцип работы, предлагаю посмотреть видео
Перед "накаткой скрипта на ядро, нужно залить в БД скрипт Code CREATE TABLE `vehicle_powerup` ( `gameobject_entry` INT(10) NOT NULL, `creature_entry` INT(10) NOT NULL, `vehicle_time` INT(10) NOT NULL, `respawn_time` INT(10) NOT NULL, PRIMARY KEY (`gameobject_entry`) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB ROW_FORMAT=DEFAULT И сам скрипт на реализацию в ядре Code #include "Setup.h" /* * VehiclePower-Ups v3 - Code by Nirual * http://tinyurl.com/cklfzag */ struct VehiclePowerUp struct VehiclePowerUp { uint32 creature_entry; uint32 creature_entry; uint32 vehicle_time; uint32 vehicle_time; uint32 respawn_time; uint32 respawn_time; }; }; std::map<uint32, VehiclePowerUp*> m_VehicleStorage; std::map<uint32, VehiclePowerUp*> m_VehicleStorage; class PowerUpVehicle : public CreatureAIScript class PowerUpVehicle : public CreatureAIScript { public: public: ADD_CREATURE_FACTORY_FUNCTION(PowerUpVehicle); ADD_CREATURE_FACTORY_FUNCTION(PowerUpVehicle); PowerUpVehicle(Creature* pCreature) : CreatureAIScript(pCreature) {} PowerUpVehicle(Creature* pCreature) : CreatureAIScript(pCreature) {} void OnLastPassengerLeft( Unit *passenger ) void OnLastPassengerLeft( Unit *passenger ) { { _unit->Despawn(100, 0); _unit->Despawn(100, 0); } } }; }; class VehicleActivator : public GameObjectAIScript class VehicleActivator : public GameObjectAIScript { public: public: VehicleActivator(GameObject* goinstance) : GameObjectAIScript(goinstance) {} VehicleActivator(GameObject* goinstance) : GameObjectAIScript(goinstance) {} static GameObjectAIScript* Create(GameObject* GO) { return new VehicleActivator(GO); } static GameObjectAIScript* Create(GameObject* GO) { return new VehicleActivator(GO); } void OnCreate() void OnCreate() { { VehiclePowerUp* power_up = m_VehicleStorage[_gameobject->GetEntry()]; VehiclePowerUp* power_up = m_VehicleStorage[_gameobject->GetEntry()]; if(power_up == NULL) if(power_up == NULL) { { sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u should not have that script"); sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u should not have that script"); return; return; } } CreatureEntry = power_up->creature_entry; CreatureEntry = power_up->creature_entry; vehicle_time = power_up->vehicle_time; vehicle_time = power_up->vehicle_time; respawn_time = power_up->respawn_time; respawn_time = power_up->respawn_time; RegisterAIUpdateEvent(100); RegisterAIUpdateEvent(100); } } void AIUpdate() void AIUpdate() { { float d2 = 0; float d2 = 0; float dist = 0; float dist = 0; Player* ret = NULL; Player* ret = NULL; for(set<Object*>::iterator itr = _gameobject->GetInRangePlayerSetBegin(); itr != _gameobject->GetInRangePlayerSetEnd(); ++itr) for(set<Object*>::iterator itr = _gameobject->GetInRangePlayerSetBegin(); itr != _gameobject->GetInRangePlayerSetEnd(); ++itr) { { d2 = (TO< Player* >(*itr))->GetDistanceSq(_gameobject); d2 = (TO< Player* >(*itr))->GetDistanceSq(_gameobject); if(!ret || d2 < dist) if(!ret || d2 < dist) { { dist = d2; dist = d2; ret = TO< Player* >(*itr); ret = TO< Player* >(*itr); } } } } if(ret == NULL) if(ret == NULL) return; return; if(ret->GetCurrentVehicle() != NULL) if(ret->GetCurrentVehicle() != NULL) return; return; if(_gameobject->GetDistance2dSq(ret) > 1.5) if(_gameobject->GetDistance2dSq(ret) > 1.5) return; return; _gameobject->Despawn(1, respawn_time); _gameobject->Despawn(1, respawn_time); Creature* pVehicle = ret->GetMapMgr()->CreateCreature(CreatureEntry); Creature* pVehicle = ret->GetMapMgr()->CreateCreature(CreatureEntry); pVehicle->Load(CreatureProtoStorage.LookupEntry(CreatureEntry), ret->GetPositionX(), ret->GetPositionY(), ret->GetPositionZ(), ret->GetOrientation()); pVehicle->Load(CreatureProtoStorage.LookupEntry(CreatureEntry), ret->GetPositionX(), ret->GetPositionY(), ret->GetPositionZ(), ret->GetOrientation()); pVehicle->m_loadedFromDB = true; pVehicle->m_loadedFromDB = true; pVehicle->SetFaction(ret->GetFaction()); pVehicle->SetFaction(ret->GetFaction()); pVehicle->Phase(PHASE_SET, ret->GetPhase()); pVehicle->Phase(PHASE_SET, ret->GetPhase()); pVehicle->m_noRespawn = true; pVehicle->m_noRespawn = true; pVehicle->PushToWorld(_gameobject->GetMapMgr()); pVehicle->PushToWorld(_gameobject->GetMapMgr()); ret->EnterVehicle(pVehicle->GetGUID(), 200); ret->EnterVehicle(pVehicle->GetGUID(), 200); pVehicle->Despawn(vehicle_time, 0); pVehicle->Despawn(vehicle_time, 0); } } private: private: uint32 CreatureEntry, respawn_time, vehicle_time; uint32 CreatureEntry, respawn_time, vehicle_time; }; }; void SetupPowerUps(ScriptMgr* mgr) void SetupPowerUps(ScriptMgr* mgr) { QueryResult * query = WorldDatabase.Query("SELECT * FROM vehicle_powerup;"); QueryResult * query = WorldDatabase.Query("SELECT * FROM vehicle_powerup;"); if(query == NULL) if(query == NULL) return; return; uint32 gameobject_entry, creature_entry; uint32 gameobject_entry, creature_entry; uint32 i = 0; uint32 i = 0; do do { { gameobject_entry = query->Fetch()[0].GetUInt32(); gameobject_entry = query->Fetch()[0].GetUInt32(); creature_entry = query->Fetch()[1].GetUInt32(); creature_entry = query->Fetch()[1].GetUInt32(); CreatureProto* pCreatureProto = CreatureProtoStorage.LookupEntry(creature_entry); CreatureProto* pCreatureProto = CreatureProtoStorage.LookupEntry(creature_entry); CreatureInfo* pCreatureInfo = CreatureNameStorage.LookupEntry(creature_entry); CreatureInfo* pCreatureInfo = CreatureNameStorage.LookupEntry(creature_entry); if(GameObjectNameStorage.LookupEntry(gameobject_entry) == NULL) if(GameObjectNameStorage.LookupEntry(gameobject_entry) == NULL) sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u not found.", gameobject_entry ); sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u not found.", gameobject_entry ); else if(pCreatureProto == NULL || pCreatureInfo == NULL) else if(pCreatureProto == NULL || pCreatureInfo == NULL) sLog.Error("[VehiclePowerUp]", "Creature with entry %u not found (gameobject id: %u).", creature_entry, gameobject_entry ); sLog.Error("[VehiclePowerUp]", "Creature with entry %u not found (gameobject id: %u).", creature_entry, gameobject_entry ); else if(pCreatureProto->vehicleid == 0) else if(pCreatureProto->vehicleid == 0) sLog.Error("[VehiclePowerUp]", "Creature with entry %u is not a vehicle.", creature_entry ); sLog.Error("[VehiclePowerUp]", "Creature with entry %u is not a vehicle.", creature_entry ); else else { { VehiclePowerUp* power_up = new VehiclePowerUp; VehiclePowerUp* power_up = new VehiclePowerUp; power_up->creature_entry = creature_entry; power_up->creature_entry = creature_entry; power_up->vehicle_time = query->Fetch()[2].GetUInt32(); power_up->vehicle_time = query->Fetch()[2].GetUInt32(); power_up->respawn_time = query->Fetch()[3].GetUInt32(); power_up->respawn_time = query->Fetch()[3].GetUInt32(); m_VehicleStorage[gameobject_entry] = power_up; m_VehicleStorage[gameobject_entry] = power_up; mgr->register_creature_script(creature_entry, &PowerUpVehicle::Create); mgr->register_creature_script(creature_entry, &PowerUpVehicle::Create); mgr->register_gameobject_script(gameobject_entry, &VehicleActivator::Create); mgr->register_gameobject_script(gameobject_entry, &VehicleActivator::Create); i++; i++; } } } while (query->NextRow()); } while (query->NextRow()); delete query; delete query; printf("[VehiclePowerUp] Loaded %u gameobject(s). \n", i); printf("[VehiclePowerUp] Loaded %u gameobject(s). \n", i); } Code #include "Setup.h" /* * VehiclePower-Ups v3 - Code by Nirual * http://tinyurl.com/cklfzag */ struct VehiclePowerUp { uint32 creature_entry; uint32 vehicle_time; uint32 respawn_time; }; std::map<uint32, VehiclePowerUp*> m_VehicleStorage; class PowerUpVehicle : public CreatureAIScript { public: ADD_CREATURE_FACTORY_FUNCTION(PowerUpVehicle); PowerUpVehicle(Creature* pCreature) : CreatureAIScript(pCreature) {} void OnLastPassengerLeft( Unit *passenger ) { _unit->Despawn(100, 0); } }; class VehicleActivator : public GameObjectAIScript { public: VehicleActivator(GameObject* goinstance) : GameObjectAIScript(goinstance) {} static GameObjectAIScript* Create(GameObject* GO) { return new VehicleActivator(GO); } void OnCreate() { VehiclePowerUp* power_up = m_VehicleStorage[_gameobject->GetEntry()]; if(power_up == NULL) { sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u should not have that script"); return; } CreatureEntry = power_up->creature_entry; vehicle_time = power_up->vehicle_time; respawn_time = power_up->respawn_time; RegisterAIUpdateEvent(100); } void AIUpdate() { float d2 = 0; float dist = 0; Player* ret = NULL; for(set<Object*>::iterator itr = _gameobject->GetInRangePlayerSetBegin(); itr != _gameobject->GetInRangePlayerSetEnd(); ++itr) { d2 = (TO< Player* >(*itr))->GetDistanceSq(_gameobject); if(!ret || d2 < dist) { dist = d2; ret = TO< Player* >(*itr); } } if(ret == NULL) return; if(ret->GetCurrentVehicle() != NULL) return; if(_gameobject->GetDistance2dSq(ret) > 1.5) return; _gameobject->Despawn(1, respawn_time); Creature* pVehicle = ret->GetMapMgr()->CreateCreature(CreatureEntry); pVehicle->Load(CreatureProtoStorage.LookupEntry(CreatureEntry), ret->GetPositionX(), ret->GetPositionY(), ret->GetPositionZ(), ret->GetOrientation()); pVehicle->m_loadedFromDB = true; pVehicle->SetFaction(ret->GetFaction()); pVehicle->Phase(PHASE_SET, ret->GetPhase()); pVehicle->m_noRespawn = true; pVehicle->PushToWorld(_gameobject->GetMapMgr()); ret->EnterVehicle(pVehicle->GetGUID(), 200); pVehicle->Despawn(vehicle_time, 0); } private: uint32 CreatureEntry, respawn_time, vehicle_time; }; void SetupPowerUps(ScriptMgr* mgr) { QueryResult * query = WorldDatabase.Query("SELECT * FROM vehicle_powerup;"); if(query == NULL) return; uint32 gameobject_entry, creature_entry; uint32 i = 0; do { gameobject_entry = query->Fetch()[0].GetUInt32(); creature_entry = query->Fetch()[1].GetUInt32(); CreatureProto* pCreatureProto = CreatureProtoStorage.LookupEntry(creature_entry); CreatureInfo* pCreatureInfo = CreatureNameStorage.LookupEntry(creature_entry); if(GameObjectNameStorage.LookupEntry(gameobject_entry) == NULL) sLog.Error("[VehiclePowerUp]", "Gameobject with entry %u not found.", gameobject_entry ); else if(pCreatureProto == NULL || pCreatureInfo == NULL) sLog.Error("[VehiclePowerUp]", "Creature with entry %u not found (gameobject id: %u).", creature_entry, gameobject_entry ); else if(pCreatureProto->vehicleid == 0) sLog.Error("[VehiclePowerUp]", "Creature with entry %u is not a vehicle.", creature_entry ); else { VehiclePowerUp* power_up = new VehiclePowerUp; power_up->creature_entry = creature_entry; power_up->vehicle_time = query->Fetch()[2].GetUInt32(); power_up->respawn_time = query->Fetch()[3].GetUInt32(); m_VehicleStorage[gameobject_entry] = power_up; mgr->register_creature_script(creature_entry, &PowerUpVehicle::Create); mgr->register_gameobject_script(gameobject_entry, &VehicleActivator::Create); i++; } } while (query->NextRow()); delete query; printf("[VehiclePowerUp] Loaded %u gameobject(s). \n", i); }
Сообщение # 1 написано 20.02.2012 в 18:58
|
| |||
| |||