1. class endless_games_dynamic_events_1 : public CreatureScript
  2. {
  3. public:
  4. endless_games_dynamic_events_1() : CreatureScript("endless_games_dynamic_events_1") { }
  5. struct endless_games_dynamic_events_1AI : public ScriptedAI
  6. {
  7. endless_games_dynamic_events_1AI(Creature* creature) : ScriptedAI(creature) { }
  8. uint32 tickTimer;
  9. void Reset()
  10. {
  11. }
  12. void UpdateAI(uint32 diff)
  13. {
  14. //Look for in DB a mob with id = 5000
  15. QueryResult comprobar_mob = WorldDatabase.PQuery("SELECT id FROM creature WHERE `id` = 5000"); //Worl Server crash if there aren't entry 5000 in "creature"
  16. Field* fields = comprobar_mob->Fetch();
  17. uint32 comprobador = fields[0].GetUInt32();
  18. if (tickTimer >= 20000) //time 20 seconds, working.
  19. {
  20. tickTimer = 0;
  21. if (Player* player = me->SelectNearestPlayer(10.0f))
  22. {
  23. if(comprobador >= 1) //Maybe check if there are >=1 creatures with id 5000
  24. {
  25. player->GetSession()->SendAreaTriggerMessage("Check 1"); //Only for check if this "if" is working or not
  26. }
  27. else
  28. me->SummonCreature(5000, 1238.40f, -4417.21f, 23.20f, 0.36f, TEMPSUMMON_TIMED_DESPAWN, 15000); //summon a creature with ID 5000
  29. //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
  30. std::ostringstream ss;
  31. player->GetSession()->SendAreaTriggerMessage("Check 2"); //Only for check if this "else" is working or not
  32. ss << "|cFF81CF42" << player->GetName() << "|r ha activado el evento dinamico .:Guerra Fria:. en la Isla de Muerte Gelida (5 jugadores recomendados)|cFFFFFFFF";
  33. sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
  34. return;
  35. }
  36. }
  37. else
  38. tickTimer += diff;
  39. }
  40. };
  41. CreatureAI* GetAI(Creature* creature) const
  42. {
  43. return new endless_games_dynamic_events_1AI(creature);
  44. }
  45. };