Share Pastebin
Guest
Public paste!

Kzan

By: a guest | Mar 16th, 2010 | Syntax: Lua | Size: 5.22 KB | Hits: 48 | Expires: Never
Copy text to clipboard
  1. shop = {}
  2.  
  3. local BuyZone = "#buy zone"
  4. local SellZone = "#sell zone"
  5. local AddTele = "#add tele"
  6. local TeleMsg = "#area tele"
  7. local Commands = "#shop commands"
  8.  
  9. local BUYPRICE = 50000                 
  10. local SELLPRICE = 50000                
  11.  
  12. local NotBuyableAreas = {
  13.         1741,
  14.         2177,
  15. }
  16.        
  17.  
  18. function shop.ZoneCommands(event, player, message, type, language)
  19.         local msg = message:lower(msg)
  20.         if (msg == BuyZone) and (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
  21.                 if (shopAreaCheck(player) == true) then
  22.                         if (AreaCheck(player) == true) then
  23.                                 if (RestrictedArea(player) == true) and (player:GetInstanceID() == nil) then
  24.                                         if (player:GetCoinage() >= BUYPRICE) then
  25.                                                 AddArea(player)
  26.                                                 player:DealGoldCost(BUYPRICE)
  27.                                                 player:SendBroadcastMessage("You succesfully bought this zone!")
  28.                                         else
  29.                                                 player:SendBroadcastMessage("You dont have enough gold to buy this zone.")
  30.                                         end
  31.                                 else
  32.                                         player:SendBroadcastMessage("This zone is not for sale.")
  33.                                 end    
  34.                         else
  35.                                 player:SendBroadcastMessage("This zone is already bought by a shop.")
  36.                         end
  37.                 else
  38.                         player:SendBroadcastMessage("Your shop already owns the maximum of allowed zones.")
  39.                 end
  40.                 return 0       
  41.         end    
  42.         if (msg:find(SellZone.." ") == 1) (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
  43.                 local AreaId = msg:gsub(SellZone.." ", "")
  44.                 if (OwnsArea(player, AreaId) == 1) then
  45.                         CharDBQuery("UPDATE shop SET Zone1 = '0' WHERE ShopId = '"..player:GetShopId().."'", 0)
  46.                         player:SendBroadcastMessage("You succesfully sold zone "..AreaId..".")
  47.                         player:DealGoldMerit(SELLPRICE)
  48.                 else
  49.                         player:SendBroadcastMessage("This zone is not yours!")
  50.                 end
  51.                 return 0
  52.         end
  53.         if (msg == AddTele) (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
  54.                 local AreaId = tostring(player:GetAreaId())
  55.                 if (OwnsArea(player, AreaId) == 1) then
  56.                         CharDBQuery("UPDATE shop SET Map = '"..player:GetMapId().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
  57.                         CharDBQuery("UPDATE shop SET PosX = '"..player:GetX().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
  58.                         CharDBQuery("UPDATE shop SET PosY = '"..player:GetY().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
  59.                         CharDBQuery("UPDATE shop SET PosZ = '"..player:GetZ().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
  60.                         player:SendBroadcastMessage("You and your shopmembers can now teleport here by using "..TeleMsg..".")
  61.                 else
  62.                         player:SendBroadcastMessage("This zone is not yours!")
  63.                 end
  64.                 return 0
  65.         end
  66.         if (msg == TeleMsg) then
  67.                 if (player:IsInshop() == true) then
  68.                         if (CharDBQuery("SELECT PosX FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) ~= "0") then
  69.                                 player:Teleport(CharDBQuery("SELECT Map FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0), CharDBQuery("SELECT PosX FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0), CharDBQuery("SELECT PosY FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0), CharDBQuery("SELECT PosZ FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0))
  70.                         else
  71.                                 player:SendBroadcastMessage("Your shop does not have a zone or the shopmaster did not set a teleport position.")
  72.                         end
  73.                 else
  74.                         player:SendBroadcastMessage("You have to be in a shop in order to use this command.")
  75.                 end
  76.                 return 0
  77.         end    
  78.  
  79.         if (msg == Commands) then
  80.                 if (player:IsGm() == true) and (player:GetGmRank() == player:GetName()) then
  81.                         player:SendBroadcastMessage("Commands available for you:")
  82.                         player:SendBroadcastMessage(""..BuyZone.." - To buy a zone.")
  83.                         player:SendBroadcastMessage(""..SellZone.." AreaId - To sell a zone.")
  84.                         player:SendBroadcastMessage(""..AddTele.." - To add a teleport you and your shop members can use.")
  85.                         player:SendBroadcastMessage(""..TeleMsg.." - Teleport to the place your shopmaster set.")
  86.  
  87.                 elseif (player:IsGm() == true) then
  88.                         player:SendBroadcastMessage("Commands available for you:")
  89.                         player:SendBroadcastMessage(""..TeleMsg.." - Teleport to the place your shopmaster set.")
  90.                 end
  91.                 return 0
  92.         end            
  93. end    
  94.                                
  95. function shopAreaCheck(player)
  96.         if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == false) then
  97.                 CharDBQuery("INSERT INTO shop(ShopId, Zone1, Map, PosX, PosY, PosZ) VALUES ('"..player:GetShopId().."', '0', '0', '0', '0', '0', '0')", 0)
  98.                 return true
  99.         elseif (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == "0") then
  100.                 return true
  101.         else
  102.                 return false
  103.         end
  104. end    
  105.  
  106. function AreaCheck(player)
  107.         if (CharDBQuery("SELECT Zone1 FROM shop WHERE Zone1 = '"..player:GetAreaId().."'", 0) == false) then
  108.                 return true
  109.         else
  110.                 return false
  111.         end
  112. end    
  113.  
  114. function AddArea(player)
  115.         if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == "0") then
  116.                 CharDBQuery("UPDATE shop SET Zone1 = '"..player:GetAreaId().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
  117. end
  118. end
  119.  
  120. function RestrictedArea(player)
  121.         for k, v in pairs(NotBuyableAreas) do
  122.                 if (player:GetAreaId() ~= v) then
  123.                         return true
  124.                 else
  125.                         return false
  126.                 end
  127.         end
  128. end    
  129.                        
  130. function OwnsArea(player, AreaId)
  131.         if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == AreaId) then
  132.                 return 1
  133. end    
  134. end
  135.  
  136. RegisterServerHook(16, "shop.ZoneCommands")