Advertisement
Guest User

Untitled

a guest
Jun 30th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.98 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 `gurubashi_lastspawned`");
  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 `gurubashi_themes`");
  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, "Next change possible in less than minute.");
  45.         else
  46.           sprintf(msg, "Next change possible in %u minute/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, "Good bye", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
  50.     player->SEND_GOSSIP_MENU(1,m_creature->GetGUID());
  51. }
  52.  
  53.  
  54. class Theme_NPC : public CreatureScript
  55. {
  56.     public:
  57.         Theme_NPC() : CreatureScript("Theme_NPC") {}
  58.  
  59.         bool OnGossipHello(Player * pPlayer, Creature * pCreature)
  60.         {
  61.             GossipObjects(pPlayer, pCreature);
  62.             return true;
  63.         }
  64.  
  65.         bool OnGossipSelect(Player *player, Creature * m_creature, uint32 sender, uint32 action)
  66.         {
  67.             if (action > OFFSET_THEME)
  68.             {
  69.                 QueryResult result;
  70.                 result = WorldDatabase.PQuery("DELETE FROM `gurubashi_lastspawned`");
  71.                 result = WorldDatabase.PQuery("INSERT INTO `gurubashi_lastspawned` VALUES (%u)", time (NULL));
  72.                 result = WorldDatabase.PQuery("SELECT `x`, `y`, `z`, `o`, `entry` FROM `gurubashi_spawns` WHERE `theme` = %u", action - OFFSET_THEME);
  73.                 if (result)
  74.                 {
  75.                     m_creature->MonsterSay("Spawning gameobjects..", LANG_UNIVERSAL, player->GetGUID());
  76.                     do
  77.                     {
  78.                         Field *fields = result->Fetch();
  79.                         m_creature->SummonGameObject(fields[4].GetInt32(), fields[0].GetFloat(), fields[1].GetFloat(), fields[2].GetFloat(), fields[3].GetFloat(), 0, 0, 0, 0, 600);
  80.                     }
  81.                     while (result->NextRow());
  82.                 }
  83.                 else
  84.                 {
  85.                     m_creature->MonsterSay("No gameobjects found.", LANG_UNIVERSAL, player->GetGUID());
  86.                 }
  87.                 player->PlayerTalkClass->SendCloseGossip();
  88.             }
  89.             else
  90.             {
  91.                 switch (action)
  92.                 {
  93.                 case GOSSIP_ACTION_INFO_DEF + 1:
  94.                     player->PlayerTalkClass->SendCloseGossip();
  95.                     break;
  96.                 case GOSSIP_ACTION_INFO_DEF + 2:
  97.                     GossipObjects(player, m_creature);
  98.                     break;
  99.                 }
  100.             }
  101.             return true;
  102.         }
  103. };
  104.  
  105.  
  106. void AddSC_npc_gurubashi_theme()
  107. {
  108.     new Theme_NPC();
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement