-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrops.lua
More file actions
51 lines (47 loc) · 1.52 KB
/
drops.lua
File metadata and controls
51 lines (47 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
---------------------------------------------------------------------------------------
-- DROPS --
---------------------------------------------------------------------------------------
--[[
Dependencies:
heroinventory.lua
itemstofind.lua
Example:
_items = {
{item = itemTable, amount = 5},
{item = itemTable2, amount = 2}
}
]]--
function AddDropToEntity(_entity, _items, _dropEntity, _pickCallback)
if not drops then
drops = {}
drops.Trigger = Trigger.RequestTrigger(Events.LOGIC_EVENT_ENTITY_DESTROYED,"","Drops_EntityDestroyed",1)
end
local eName = GetEntityName(_entity)
_items.dropEntity = _dropEntity
_items.pickCallback = _pickCallback
drops[eName] = _items
if Logic.IsHero(GetEntityId(_entity)) == 1 then
SetupDestroy{
Target = eName,
Callback = function() CreateDroppedItem(eName, GetPosition(eName)); end
}
end
end
function Drops_EntityDestroyed()
local eID = Event.GetEntityID()
local eName = GetEntityName(eID)
if drops[eName] then
local pos = GetPosition(eID)
CreateDroppedItem(eName, pos)
drops[eName] = nil
end
end
function CreateDroppedItem(_eName, _pos)
local itemTable = drops[_eName]
for i = 1, table.getn(itemTable) do
AddItemToFind(itemTable[i].Item, itemTable[i].Amount, _pos, nil, itemTable.dropEntity, nil, itemTable.pickCallback)
if i == 1 then
itemTable.pickCallback = nil
end
end
end