function CustomUI:OnBuyItem(keys)
local playerid = keys["1"]
local hero_entindex = keys["0"]
local hero = EntIndexToHScript(hero_entindex)
local item = keys["2"]
local panel_string = keys["3"]
local cost = GetItemCost(item)
local radiant = Vector(math.random(-7164, -7200), math.random(-6528, -6608), 392.75)
local dire = Vector(math.random(7000, 7130), math.random(6440, 6520), 392.75)
local place;
local gold = hero:GetGold()
local player = hero:GetPlayerOwner()
print(cost)
if hero:GetTeamNumber() == 2 then
place = radiant
else
place = dire
end
if item == "item_glove_of_the_creator" and hero:HasItemInInventory("item_inf_balvanka") == false then
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 2} )
return
else
if hero:HasItemInInventory("item_inf_balvanka") then
for i=0, 5, 1 do
local current_item = hero:GetItemInSlot(i)
if current_item ~= nil then
if current_item:GetName() == "item_inf_balvanka" then --Refresher Orb does not refresh itself.
current_item:RemoveSelf()
end
end
end
end
end
if gold >= cost then
PlayerResource:SpendGold(playerid, cost, DOTA_ModifyGold_PurchaseItem)
if panel_string ~= nil then
CustomGameEventManager:Send_ServerToPlayer( player, "RemovePanelQuickBuy", {panel = panel_string} )
end
else
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 2} )
return
end
local shop = Entities:FindByClassnameNearest("ent_dota_shop", hero:GetAbsOrigin(), 800)
if shop ~= nil then
if gold >= cost then
local item_new = CreateItem(item, hero, hero)
hero:AddItem(item_new)
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 1} )
else
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 2} )
end
else
if gold >= cost then
local item_new = CreateItem(item, hero, hero)
local num;
local courier;
local cour = Entities:FindAllByName("npc_dota_courier")
if cour ~= nil then
for k,v in pairs(cour) do
if v:GetTeam() == hero:GetTeam() then
courier = v
break
end
end
if courier == nil then
hero:AddItem(item_new)
hero:DropItemAtPositionImmediate(item_new, place)
Notifications:Bottom(hero:GetPlayerOwnerID(), {text="#inBase", duration=3, style={color="red", ["font-size"]="50px", border="0px solid blue"}})
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 3, IsInCour = 2} )
return
end
local m = 0;
for i=0, 5, 1 do
local current_item = courier:GetItemInSlot(i)
if current_item ~= nil then
m = m + 1
end
end
if m < 6 then
courier:AddItem(item_new)
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 3, IsInCour = 1} )
Notifications:Bottom(hero:GetPlayerOwnerID(), {text="#inCour", duration=3, style={color="red", ["font-size"]="50px", border="0px solid blue"}})
else
hero:AddItem(item_new)
hero:DropItemAtPositionImmediate(item_new, place)
Notifications:Bottom(hero:GetPlayerOwnerID(), {text="#inBase", duration=3, style={color="red", ["font-size"]="50px", border="0px solid blue"}})
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 3, IsInCour = 2} )
end
else
hero:AddItem(item_new)
hero:DropItemAtPositionImmediate(item_new, place)
Notifications:Bottom(hero:GetPlayerOwnerID(), {text="#inBase", duration=3, style={color="red", ["font-size"]="50px", border="0px solid blue"}})
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 3, IsInCour = 2} )
end
else
CustomGameEventManager:Send_ServerToPlayer( player, "ShopResult", {result = 4} )
end
end
end