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(!comprobar_mob || !comprobador)
  19. return;
  20. if (tickTimer >= 20000) //time 20 seconds, working.
  21. {
  22. tickTimer = 0;
  23. if (Player* player = me->SelectNearestPlayer(10.0f))
  24. {
  25. if(comprobador >= 1) //Maybe check if there are >=1 creatures with id 5000
  26. {
  27. player->GetSession()->SendAreaTriggerMessage("Check 1"); //Only for check if this "if" is working or not
  28. return;
  29. }
  30. else
  31. me->SummonCreature(5000, 1238.40f, -4417.21f, 23.20f, 0.36f, TEMPSUMMON_TIMED_DESPAWN, 15000); //summon a creature with ID 5000
  32. //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
  33. std::ostringstream ss;
  34. player->GetSession()->SendAreaTriggerMessage("Check 2"); //Only for check if this "else" is working or not
  35. ss << "|cFF81CF42" << player->GetName() << "|r ha activado el evento dinamico .:Guerra Fria:. en la Isla de Muerte Gelida (5 jugadores recomendados)|cFFFFFFFF";
  36. sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
  37. return;
  38. }
  39. }
  40. else
  41. tickTimer += diff;
  42. }
  43. };
  44. CreatureAI* GetAI(Creature* creature) const
  45. {
  46. return new endless_games_dynamic_events_1AI(creature);
  47. }
  48. };