Advertisement
Guest User

Consume Item Lua

a guest
Dec 21st, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.95 KB | None | 0 0
  1. function ConsumeItemGainCharges( keys )
  2.     local caster = keys.caster
  3.     local ability = keys.ability
  4.    
  5.     local charges = caster:GetModifierStackCount("modifier_consume_item_charges", caster) + 2
  6.     if not caster:HasModifier("modifier_consume_item_charges") then
  7.         ability:ApplyDataDrivenModifier(caster, caster, "modifier_consume_item_charges", {})
  8.     end
  9.     caster:SetModifierStackCount("modifier_consume_item_charges", ability, charges)
  10. end
  11.  
  12. function ConsumeItemOn( keys )
  13.     local caster = keys.caster
  14.     local ability = keys.ability
  15.     local player = caster:GetPlayerOwner()
  16.     local pID = caster:GetPlayerOwnerID()
  17.  
  18.  
  19.     owner = {}
  20.    
  21.     if caster:HasModifier("modifier_consume_item_charges") then
  22.         for i=0, 5 do
  23.             local item = caster:GetItemInSlot(i)
  24.        
  25.             if item == nil then
  26.                 caster:AddItem(CreateItem("item_dummy_datadriven", caster, caster))
  27.             else
  28.                 owner[i] = item:GetPurchaser()
  29.                 print(owner[i]:GetName())
  30.                 local item_name = item:GetName()
  31.                 local consume_item_name = item_name .. "_datadriven"
  32.                 if item:IsPermanent() and item_name ~= "item_aegis" then
  33.                     local item_charges = item:GetCurrentCharges()
  34.                     caster:RemoveItem(item)
  35.                     caster:AddItem(CreateItem(consume_item_name, owner[i], owner[i]))
  36.                     local checkitem = caster:GetItemInSlot(i)
  37.                     if checkitem == nil then
  38.                         caster:AddItem(CreateItem(item_name, owner[i], owner[i]))
  39.                         checkitem = caster:GetItemInSlot(i)
  40.                     end
  41.                     checkitem:SetCurrentCharges(item_charges)
  42.                 end
  43.             end
  44.         end
  45.         for j=0, 5 do
  46.             local temp_item = caster:GetItemInSlot(j)
  47.             local temp_item_name = temp_item:GetName()
  48.             if temp_item_name == "item_dummy_datadriven" then
  49.                 caster:RemoveItem(temp_item)
  50.             end
  51.         end
  52.     else
  53.         ability:ToggleAbility()
  54.  
  55.         -- Play Error Sound
  56.         EmitSoundOnClient("General.CastFail_InvalidTarget_Hero", player)
  57.  
  58.         -- This makes use of the Custom Error Flash module by zedor. https://github.com/zedor/CustomError
  59.         FireGameEvent( 'custom_error_show', { player_ID = pID, _error = "Ability is out of item charges" } )
  60.     end
  61. end
  62.  
  63. function ConsumeItemOff( keys )
  64.     local caster = keys.caster
  65.     local ability = keys.ability
  66.    
  67.     for i=0, 5 do
  68.         local item = caster:GetItemInSlot(i)
  69.        
  70.         if item == nil then
  71.             caster:AddItem(CreateItem("item_dummy_datadriven", caster, caster))
  72.         else
  73.             owner[i] = item:GetPurchaser()
  74.             print(owner[i]:GetName())
  75.             local item_name = item:GetName()
  76.             local item_charges = item:GetCurrentCharges()
  77.             if item:IsPermanent() and item:GetName() ~= "item_aegis" then
  78.                 caster:RemoveItem(item)
  79.                 item_name = item_name:gsub("_datadriven", "")
  80.                 caster:AddItem(CreateItem(item_name, owner[i], owner[i]))
  81.                 local checkitem = caster:GetItemInSlot(i)
  82.                 checkitem:SetCurrentCharges(item_charges)
  83.             end
  84.         end
  85.     end
  86.     for j=0, 5 do
  87.         local temp_item = caster:GetItemInSlot(j)
  88.         local temp_item_name = temp_item:GetName()
  89.         if temp_item_name == "item_dummy_datadriven" then
  90.             caster:RemoveItem(temp_item)
  91.         end
  92.     end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement