- class endless_games_dynamic_events_1 : public CreatureScript
- {
- public:
- endless_games_dynamic_events_1() : CreatureScript("endless_games_dynamic_events_1") { }
- struct endless_games_dynamic_events_1AI : public ScriptedAI
- {
- endless_games_dynamic_events_1AI(Creature* creature) : ScriptedAI(creature) { }
- uint32 tickTimer;
- void Reset()
- {
- }
- void UpdateAI(uint32 diff)
- {
- //Look for in DB a mob with id = 5000
- QueryResult comprobar_mob = WorldDatabase.PQuery("SELECT id FROM creature WHERE `id` = 5000"); //Worl Server crash if there aren't entry 5000 in "creature"
- Field* fields = comprobar_mob->Fetch();
- uint32 comprobador = fields[0].GetUInt32();
- if (tickTimer >= 20000) //time 20 seconds, working.
- {
- tickTimer = 0;
- if (Player* player = me->SelectNearestPlayer(10.0f))
- {
- if(comprobador >= 1) //Maybe check if there are >=1 creatures with id 5000
- {
- player->GetSession()->SendAreaTriggerMessage("Check 1"); //Only for check if this "if" is working or not
- }
- else
- me->SummonCreature(5000, 1238.40f, -4417.21f, 23.20f, 0.36f, TEMPSUMMON_TIMED_DESPAWN, 15000); //summon a creature with ID 5000
- //SaveToDb(); Maybe to solve WorldServer Error "Trying to delete not saved npc" that appears when you do .npc del (npc with id 5000), but dont know the function
- std::ostringstream ss;
- player->GetSession()->SendAreaTriggerMessage("Check 2"); //Only for check if this "else" is working or not
- ss << "|cFF81CF42" << player->GetName() << "|r ha activado el evento dinamico .:Guerra Fria:. en la Isla de Muerte Gelida (5 jugadores recomendados)|cFFFFFFFF";
- sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
- return;
- }
- }
- else
- tickTimer += diff;
- }
- };
- CreatureAI* GetAI(Creature* creature) const
- {
- return new endless_games_dynamic_events_1AI(creature);
- }
- };