Advertisement
Guest User

Grandelf

a guest
Jan 10th, 2010
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.00 KB | None | 0 0
  1. --[[
  2.  
  3.     Guild forge and rename system
  4.     Scripted by Grandelf
  5.  
  6. ]]--
  7.  
  8. GUILDS = {}
  9. GUILDS.NPCID = 4315         -- Put your npc id here.
  10.  
  11. function GUILDS.GuildForgeOnTalk(pUnit, event, player)
  12.     if (player:IsInGuild() == true) and (player:GetGuildLeader() == player:GetName()) then
  13.         pUnit:GossipCreateMenu(50, player, 0)
  14.         pUnit:GossipMenuAddItem(0, "Enter the guildname to forge with.", 1, 1)
  15.         pUnit:GossipMenuAddItem(0, "Change my guild name.", 2, 1)
  16.         pUnit:GossipMenuAddItem(0, "Nevermind", 3, 0)
  17.         pUnit:GossipSendMenu(player)
  18.     else
  19.         player:SendBroadcastMessage("You have to be the guildmaster of a guild in order to use this.")
  20.     end
  21. end
  22.  
  23. function GUILDS.GuildForgeOnGossip(pUnit, event, player, id, intid, code)
  24.     if (intid == 1) then
  25.         if (CharDBQuery("SELECT guildName FROM guilds WHERE guildName = '"..code.."'", 0) ~= false) then
  26.             local GuildId = player:GetGuildId()
  27.             if (string.lower(CharDBQuery("SELECT guildName FROM guilds WHERE guildId = '"..GuildId.."'", 0)) ~= string.lower(code)) then
  28.                 if (GUILDS[player:GetName()] == nil) or (GUILDS[player:GetName()].IsForging == 0) then
  29.                     local GuildIdB = CharDBQuery("SELECT guildId FROM guilds WHERE guildName = '"..code.."'", 0)
  30.                     local LeaderGuid = CharDBQuery("SELECT leaderGuid FROM guilds WHERE guildId = '"..GuildIdB.."'", 0)
  31.                     local plr = GetPlayer(CharDBQuery("SELECT name FROM characters WHERE guid = '"..LeaderGuid.."'", 0))
  32.                     if (plr ~= nil) then
  33.                         plr:SendBroadcastMessage(""..player:GetName().." wants to forge guilds with you. Typ #yes to accept and #no to decline. You have 20 seconds.")
  34.                         GUILDS[player:GetName()] = {}
  35.                         GUILDS[plr:GetName()] = {}
  36.                         GUILDS[player:GetName()].IsForging = 1
  37.                         GUILDS[plr:GetName()].IsForging = 1
  38.                         GUILDS[plr:GetName()].MsgAllowed = 1
  39.                         GUILDS[plr:GetName()].GuildId = player:GetGuildId()
  40.                         GUILDS[plr:GetName()].GuildIdB = GuildIdB
  41.                         GUILDS[plr:GetName()].ForgingWith = player:GetName()
  42.                         RegisterTimedEvent("GUILDS.Time", 20000, 1, player, plr)
  43.                         player:SendBroadcastMessage("Sending offer...")
  44.                         player:GossipComplete()
  45.                     else
  46.                         player:SendBroadcastMessage("The guildmaster of this guild is not online at this moment.")
  47.                         player:GossipComplete()
  48.                     end
  49.                 else
  50.                     player:SendBroadcastMessage("You are already forging")
  51.                     player:GossipComplete()
  52.                 end
  53.             else
  54.                 player:SendBroadcastMessage("You cannot forge your own guild with your guild.")
  55.                 player:GossipComplete()
  56.             end
  57.         else
  58.             player:SendBroadcastMessage("This guild does not exist.")
  59.             player:GossipComplete()
  60.         end
  61.     end
  62.     if (intid == 2) then
  63.         if (GUILDS[player:GetName()] == nil) or (GUILDS[player:GetName()].IsForging == 0) then
  64.             CharDBQuery("UPDATE guilds SET guildName = '"..code.."' WHERE guildId = '"..player:GetGuildId().."'", 0)
  65.             player:SendBroadcastMessage("Your guildname is succesfully changed to "..code..". It will take effect after the next server restart.")
  66.             player:GossipComplete()
  67.         else
  68.             player:SendBroadcastMessage("You cannot do this while forging your guild. Try again after next server restart.")
  69.             player:GossipComplete()
  70.         end
  71.     end
  72.     if (intid == 3) then
  73.         player:GossipComplete()
  74.     end
  75. end
  76.  
  77. function GUILDS.OnForgeGuildChat(event, player, message, type, language)
  78.     if (GUILDS[player:GetName()] == nil) or (GUILDS[player:GetName()].MsgAllowed == 0) then
  79.     else
  80.         if (message == "#yes") then
  81.             local GuildId = GUILDS[player:GetName()].GuildId
  82.             local GuildIdB = GUILDS[player:GetName()].GuildIdB
  83.             local LeaderGuid = CharDBQuery("SELECT leaderGuid FROM guilds WHERE guildId = '"..GuildId.."'", 0)
  84.             local plr = GetPlayer(CharDBQuery("SELECT name FROM characters WHERE guid = '"..LeaderGuid.."'", 0))
  85.             GUILDS.ForgeGuilds(GuildId, GuildIdB)
  86.             player:SendBroadcastMessage("You have succesfully forged your guild. After the next server restart your guilds are forged")
  87.             plr:SendBroadcastMessage("You have succesfully forged your guild. After the next server restart your guilds are forged")
  88.             GUILDS[player:GetName()].IsForging = 2
  89.         elseif (message == "#no") then 
  90.             player:SendBroadcastMessage("You have declined to forge guilds")
  91.             local GuildId = GUILDS[player:GetName()].GuildId
  92.             local LeaderGuid = CharDBQuery("SELECT leaderGuid FROM guilds WHERE guildId = '"..GuildId.."'", 0)
  93.             local plr = GetPlayer(CharDBQuery("SELECT name FROM characters WHERE guid = '"..LeaderGuid.."'", 0))
  94.             plr:SendBroadcastMessage(""..player:GetName().." has declined your offer.")
  95.             GUILDS[plr:GetName()].IsForging = 0
  96.             GUILDS[player:GetName()].IsForging = 0
  97.             GUILDS[player:GetName()].MsgAllowed = 0
  98.         end
  99.         return 0
  100.     end
  101. end
  102.  
  103. function GUILDS.Time(player, plr)
  104.     if (GUILDS[plr:GetName()].IsForging == 1) then
  105.         GUILDS[player:GetName()].IsForging = 0
  106.         GUILDS[plr:GetName()].IsForging = 0
  107.         GUILDS[plr:GetName()].MsgAllowed = 0
  108.         player:SendBroadcastMessage(""..plr:GetName().." did not respond. Try to forge your guild later.")
  109.     end
  110. end
  111.    
  112. function GUILDS.ForgeGuilds(GuildId, GuildIdB)
  113.     local LeaderGuid = CharDBQuery("SELECT leaderGuid FROM guilds WHERE guildId = '"..GuildIdB.."'", 0)
  114.     CharDBQuery("UPDATE guild_data SET guildRank = '4' WHERE guildid = '"..GuildIdB.."'", 0)
  115.     CharDBQuery("UPDATE guild_data SET guildRank = '0' WHERE playerid = '"..LeaderGuid.."'", 0)
  116.     CharDBQuery("UPDATE guild_data SET guildid = '"..GuildId.."' WHERE guildid = '"..GuildIdB.."'", 0)
  117.     CharDBQuery("DELETE FROM guilds WHERE guildId = '"..GuildIdB.."'", 0)
  118.     CharDBQuery("DELETE FROM guild_ranks WHERE guildId = '"..GuildIdB.."'", 0)
  119.     CharDBQuery("DELETE FROM guild_logs WHERE guildid = '"..GuildIdB.."'", 0)
  120.     CharDBQuery("DELETE FROM guild_banktabs WHERE guildId = '"..GuildIdB.."'", 0)
  121.     CharDBQuery("DELETE FROM guild_bankitems WHERE guildId = '"..GuildIdB.."'", 0)
  122.     CharDBQuery("DELETE FROM guild_banklogs WHERE guildid = '"..GuildIdB.."'", 0)
  123. end
  124.  
  125. RegisterUnitGossipEvent(GUILDS.NPCID, 1, "GUILDS.GuildForgeOnTalk")
  126. RegisterUnitGossipEvent(GUILDS.NPCID, 2, "GUILDS.GuildForgeOnGossip")  
  127. RegisterServerHook(16, "GUILDS.OnForgeGuildChat")  
  128.                
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement