Advertisement
Guest User

Untitled

a guest
Jun 30th, 2013
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include "ScriptPch.h"
  2. #include <cstring>
  3. #include <stdio.h>
  4. #include <time.h>
  5.  
  6. #define OFFSET_THEME 10000
  7.  
  8. int GetLastThemeTime()
  9. {
  10.     QueryResult result;
  11.       result = WorldDatabase.PQuery("SELECT `time` FROM `evento_gurubashi_lastspawn`");
  12.  
  13.       if (result)
  14.       {
  15.        Field *fields = result->Fetch();
  16.        return fields[0].GetInt32();
  17.       }
  18.       else
  19.           return 0;
  20.  
  21. }
  22.  
  23. void GossipObjects(Player *player, Creature *m_creature)
  24. {
  25.    if (GetLastThemeTime() + 600 <= time (NULL))
  26.     {
  27.         QueryResult result;
  28.           result = WorldDatabase.PQuery("SELECT `id`, `name` FROM `evento_gurubashi_reliquias`");
  29.         if (result)
  30.         {
  31.             do
  32.           {
  33.             Field *fields = result->Fetch();
  34.             player->ADD_GOSSIP_ITEM(4, fields[1].GetString(), GOSSIP_SENDER_MAIN, OFFSET_THEME + fields[0].GetInt32());
  35.           }
  36.           while (result->NextRow());
  37.         }
  38.     }
  39.     else
  40.     {
  41.         char msg[100];
  42.         int time2 = GetLastThemeTime() + 600 - time (NULL);
  43.         if (time2 < 60)
  44.           sprintf(msg, "La siguiente reliquia se podrá spawnear en menos de un minuto.");
  45.         else
  46.           sprintf(msg, "La siguiente reliquia se podrá spawnear en %u minuto/s.", time2 / 60);      
  47.           player->ADD_GOSSIP_ITEM(0, msg, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
  48.     }
  49.     player->ADD_GOSSIP_ITEM(0, "Salir.", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
  50.     player->SEND_GOSSIP_MENU(1,m_creature->GetGUID());
  51. }    
  52.          
  53. class NPC_Evento_Gurubashi : public CreatureScript
  54. {
  55.     public:
  56.         NPC_Evento_Gurubashi() : CreatureScript("NPC_Evento_Gurubashi") {}
  57.  
  58.         bool OnGossipHello(Player * pPlayer, Creature * pCreature)
  59.         {
  60.             GossipObjects(pPlayer, pCreature);
  61.             return true;
  62.         }
  63.  
  64.         bool OnGossipSelect(Player *player, Creature * m_creature, uint32 sender, uint32 action)
  65.         {
  66.             if (action > OFFSET_THEME)
  67.             {
  68.                 QueryResult result;
  69.                 result = WorldDatabase.PQuery("DELETE FROM `evento_gurubashi_lastspawn`");
  70.                 result = WorldDatabase.PQuery("INSERT INTO `evento_gurubashi_lastspawn` VALUES (%u)", time (NULL));
  71.                 result = WorldDatabase.PQuery("SELECT `x`, `y`, `z`, `o`, `entry` FROM `evento_gurubashi_spawns` WHERE `theme` = %u", action - OFFSET_THEME);
  72.                 if (result)
  73.                 {
  74.                     player->CastSpell(player, 20217, 1);
  75.                     player->CastSpell(player, 93744, 1);
  76.                     player->CastSpell(player, 1126, 1);
  77.                     player->CastSpell(player, 1459, 1);
  78.                     player->GetSession()->SendAreaTriggerMessage("Has sido buffeado como obsequio por spawnear una reliquia.");
  79.                     sWorld->SendGlobalText("Una |cFFFF6060Reliquia Zalandari|r ha aparecido en la arena gurubashi. Obtendrás valiosas recompensas si acudes al evento y te haces con la reliquia.", NULL);
  80.                     m_creature->MonsterSay("Spawneando gameobjects...", LANG_UNIVERSAL, player->GetGUID());
  81.                     do
  82.                     {
  83.                         Field *fields = result->Fetch();
  84.                         m_creature->SummonGameObject(fields[4].GetInt32(), fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), 0, 0, 0, 0, 600);
  85.                     }
  86.                     while (result->NextRow());
  87.                 }
  88.                 else
  89.                 {
  90.                     m_creature->MonsterSay("No se han encontrado gameobjects.", LANG_UNIVERSAL, player->GetGUID());
  91.                 }
  92.                 player->PlayerTalkClass->SendCloseGossip();
  93.             }
  94.             else
  95.             {
  96.                 switch (action)
  97.                 {
  98.                 case GOSSIP_ACTION_INFO_DEF + 1:
  99.                     player->PlayerTalkClass->SendCloseGossip();
  100.                     break;
  101.                 case GOSSIP_ACTION_INFO_DEF + 2:
  102.                     GossipObjects(player, m_creature);
  103.                     break;
  104.                 }
  105.             }
  106.             return true;
  107.         }
  108. };
  109.  
  110.  
  111. void AddSC_Script_Evento_Gurubashi()
  112. {
  113.     new NPC_Evento_Gurubashi();
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement