Advertisement
Rochet2

Guild Wars

Dec 19th, 2012
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include "ScriptPCH.h"
  2. #include "GuildMgr.h"
  3.  
  4. //===============
  5. // Guild Wars
  6. //  by Mager1794
  7. // Transcendent Scripting
  8.  
  9. // Translated raw to TC on 19th of Dec 2012 by Rochet2
  10. //===============
  11.  
  12. /*
  13. -- SQL (execute to character database
  14.  
  15. CREATE TABLE guild_wars (
  16.     aguild INT(10) UNSIGNED NOT NULL,
  17.     bguild INT(10) UNSIGNED NOT NULL,
  18.     PRIMARY KEY (aguild, bguild)
  19. )
  20. COLLATE='latin1_swedish_ci'
  21. ENGINE=InnoDB;
  22.  
  23. */
  24.  
  25. class Custom_GuildWars : public CreatureScript
  26. {
  27. public:
  28.     Custom_GuildWars() : CreatureScript("Custom_GuildWars") { }
  29.  
  30.     bool OnGossipHello(Player* player, Creature* creature)
  31.     {
  32.         player->ADD_GOSSIP_ITEM_EXTENDED(1, "Propose A Guild War", 1, 0, "Enter guild name", 0, true);
  33.         player->ADD_GOSSIP_ITEM_EXTENDED(1, "Propose A Guild Peace", 1, 1, "Enter guild name", 0, true);
  34.         player->SEND_GOSSIP_MENU(2593, creature->GetGUID());
  35.         return true;
  36.     }
  37.  
  38.     bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, const char* code)
  39.     {
  40.         player->PlayerTalkClass->ClearMenus();
  41.         uint32 friendly = player->GetGuildId();
  42.         Guild* guilda;
  43.  
  44.         if(!friendly || !(guilda = sGuildMgr->GetGuildById(friendly)))
  45.             player->GetSession()->SendNotification("You are not in a guild");
  46.         else if(Guild* guildb = sGuildMgr->GetGuildByName(code))
  47.         {
  48.             uint32 enemy = guildb->GetId();
  49.             if(friendly == enemy)
  50.                 player->GetSession()->SendNotification("You cannot declare war on your own guild");
  51.             else if(guilda->GetLeaderGUID() != player->GetGUID())
  52.                 player->GetSession()->SendNotification("You must be the guild leader");
  53.             else
  54.             {
  55.                 std::ostringstream ss;
  56.                 if(!action)
  57.                 {
  58.                     CharacterDatabase.PExecute("REPLACE INTO guild_wars VALUES(%u,%u)", friendly, enemy);
  59.                     CharacterDatabase.PExecute("REPLACE INTO guild_wars VALUES(%u,%u)", enemy, friendly);
  60.                     ss << "[Guild Wars] " << guilda->GetName().c_str() << " has declared war on " << guildb->GetName().c_str();
  61.                 }
  62.                 else
  63.                 {
  64.                     CharacterDatabase.PExecute("DELETE FROM guild_wars WHERE aguild = %u AND bguild= %u", friendly, enemy);
  65.                     CharacterDatabase.PExecute("DELETE FROM guild_wars WHERE aguild = %u AND bguild= %u", enemy, friendly);
  66.                     ss << "[Guild Wars] " << guilda->GetName().c_str() << " has declared peace with " << guildb->GetName().c_str();
  67.                 }
  68.                 sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
  69.             }
  70.         }
  71.         else
  72.             player->GetSession()->SendNotification("Invalid guild name inserted");
  73.         OnGossipHello(player, creature);
  74.         return true;
  75.     }
  76. };
  77.  
  78. class Custom_GuildWars_PvP : public PlayerScript
  79. {
  80. public:
  81.     Custom_GuildWars_PvP() : PlayerScript("Custom_GuildWars_PvP") { }
  82.  
  83.     void OnPVPKill(Player* killer, Player* killed)
  84.     {
  85.         uint32 aguild = killer->GetGuildId();
  86.         uint32 vguild = killed->GetGuildId();
  87.         if(!aguild || !vguild || aguild == vguild)
  88.             return;
  89.         QueryResult result = CharacterDatabase.PQuery("SELECT 1 FROM guild_wars WHERE aguild = %u AND bguild = %u", aguild, vguild);
  90.         if(result)
  91.         {
  92.             if(result->Fetch())
  93.             {
  94.                 killer->ModifyMoney(10000);
  95.                 killed->ModifyMoney(-5000);
  96.             }
  97.         }
  98.     }
  99. };
  100.  
  101. void AddSC_Custom_GuildWars()
  102. {
  103.     new Custom_GuildWars();
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement