shop = {}
local BuyZone = "#buy zone"
local SellZone = "#sell zone"
local AddTele = "#add tele"
local TeleMsg = "#area tele"
local Commands = "#shop commands"
local BUYPRICE = 50000
local SELLPRICE = 50000
local NotBuyableAreas = {
1741,
2177,
}
function shop.ZoneCommands(event, player, message, type, language)
local msg = message:lower(msg)
if (msg == BuyZone) and (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
if (shopAreaCheck(player) == true) then
if (AreaCheck(player) == true) then
if (RestrictedArea(player) == true) and (player:GetInstanceID() == nil) then
if (player:GetCoinage() >= BUYPRICE) then
AddArea(player)
player:DealGoldCost(BUYPRICE)
player:SendBroadcastMessage("You succesfully bought this zone!")
else
player:SendBroadcastMessage("You dont have enough gold to buy this zone.")
end
else
player:SendBroadcastMessage("This zone is not for sale.")
end
else
player:SendBroadcastMessage("This zone is already bought by a shop.")
end
else
player:SendBroadcastMessage("Your shop already owns the maximum of allowed zones.")
end
return 0
end
if (msg:find(SellZone.." ") == 1) (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
local AreaId = msg:gsub(SellZone.." ", "")
if (OwnsArea(player, AreaId) == 1) then
CharDBQuery("UPDATE shop SET Zone1 = '0' WHERE ShopId = '"..player:GetShopId().."'", 0)
player:SendBroadcastMessage("You succesfully sold zone "..AreaId..".")
player:DealGoldMerit(SELLPRICE)
else
player:SendBroadcastMessage("This zone is not yours!")
end
return 0
end
if (msg == AddTele) (player:IsGm() == true) and (player:GetGmRank()() == player:GetName()) then
local AreaId = tostring(player:GetAreaId())
if (OwnsArea(player, AreaId) == 1) then
CharDBQuery("UPDATE shop SET Map = '"..player:GetMapId().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
CharDBQuery("UPDATE shop SET PosX = '"..player:GetX().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
CharDBQuery("UPDATE shop SET PosY = '"..player:GetY().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
CharDBQuery("UPDATE shop SET PosZ = '"..player:GetZ().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
player:SendBroadcastMessage("You and your shopmembers can now teleport here by using "..TeleMsg..".")
else
player:SendBroadcastMessage("This zone is not yours!")
end
return 0
end
if (msg == TeleMsg) then
if (player:IsInshop() == true) then
if (CharDBQuery("SELECT PosX FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) ~= "0") then
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))
else
player:SendBroadcastMessage("Your shop does not have a zone or the shopmaster did not set a teleport position.")
end
else
player:SendBroadcastMessage("You have to be in a shop in order to use this command.")
end
return 0
end
if (msg == Commands) then
if (player:IsGm() == true) and (player:GetGmRank() == player:GetName()) then
player:SendBroadcastMessage("Commands available for you:")
player:SendBroadcastMessage(""..BuyZone.." - To buy a zone.")
player:SendBroadcastMessage(""..SellZone.." AreaId - To sell a zone.")
player:SendBroadcastMessage(""..AddTele.." - To add a teleport you and your shop members can use.")
player:SendBroadcastMessage(""..TeleMsg.." - Teleport to the place your shopmaster set.")
elseif (player:IsGm() == true) then
player:SendBroadcastMessage("Commands available for you:")
player:SendBroadcastMessage(""..TeleMsg.." - Teleport to the place your shopmaster set.")
end
return 0
end
end
function shopAreaCheck(player)
if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == false) then
CharDBQuery("INSERT INTO shop(ShopId, Zone1, Map, PosX, PosY, PosZ) VALUES ('"..player:GetShopId().."', '0', '0', '0', '0', '0', '0')", 0)
return true
elseif (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == "0") then
return true
else
return false
end
end
function AreaCheck(player)
if (CharDBQuery("SELECT Zone1 FROM shop WHERE Zone1 = '"..player:GetAreaId().."'", 0) == false) then
return true
else
return false
end
end
function AddArea(player)
if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == "0") then
CharDBQuery("UPDATE shop SET Zone1 = '"..player:GetAreaId().."' WHERE ShopId = '"..player:GetShopId().."'", 0)
end
end
function RestrictedArea(player)
for k, v in pairs(NotBuyableAreas) do
if (player:GetAreaId() ~= v) then
return true
else
return false
end
end
end
function OwnsArea(player, AreaId)
if (CharDBQuery("SELECT Zone1 FROM shop WHERE ShopId = '"..player:GetShopId().."'", 0) == AreaId) then
return 1
end
end
RegisterServerHook(16, "shop.ZoneCommands")