forked from peonso/Magical-Items-1.2-3-Otx3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_third.lua
110 lines (100 loc) · 2.49 KB
/
run_third.lua
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
local slots = {
[{'head'}] = "head",
[{'neck', 'necklace'}] = "necklace",
[{'backpack', 'bag'}] = "backpack",
[{'armor', 'body'}] = "armor",
[{'right-hand', 'right', 'shield', 'hand'}] = "right-hand", -- hand
[{'left-hand', 'left','distance','two-handed','club','sword','wand','axe'}] = "left-hand", -- hand
[{'legs'}] = 'legs',
[{'feet'}] = 'feet',
[{'ring'}] = 'ring',
[{'ammo', 'ammunition'}] = 'ammo'
}
--[[
Slot Id's of equipment
1 - helmet
2 - necklace slot (amulet of loss etc.)
3 - backpack, bag
4 - armor
5 - left hand
6 - right hand
7 - legs
8 - boots
9 - ring slot
10 - ammo slot (arrows etc.)
]]
local slotNum = {
["head"] = 1,
["necklace"] = 2,
["backpack"] = 3,
["armor"] = 4,
["left-hand"] = 5,
["right-hand"] = 6,
['legs'] = 7,
['feet'] = 8,
['ring'] = 9,
['ammo'] = 10
}
local slotStr = {
[1] = "head",
[2] = "necklace",
[3] = "backpack",
[4] = "armor",
[5] = "left-hand",
[6] = "right-hand",
[7] = 'legs',
[8] = 'feet',
[9] = 'ring',
[10] = 'ammo'
}
function isInArray(a, f)
for k, v in pairs(a) do
if v == f then
return true
end
end
return false
end
function isInTable(t, f)
for n, m in pairs(t) do
if isInArray(n, f) then
return m
end
end
return 0
end
function cwd(name)
local chr = os.tmpname():sub(1,1)
if chr == "/" then
-- linux
chr = "/[^/]*$"
else
-- windows
chr = "\\[^\\]*$"
end
return arg[0]:sub(1, arg[0]:find(chr))..(name or '')
end
local path = cwd('items.lua')
dofile(path)
local showDesc = false
local showType = false
movement = function(name, itemid, slot, type, desc) return '\n\t\t<!-- '..name..(showType and ' | type = '..type..' ' or '')..(showDesc and (desc and ' | description = '..desc or '') or '')..' -->\n\t\t<movevent event="Equip" itemid="'..itemid..'" slot="'..slot..'" script="magical_items.lua" />\n\t\t<movevent event="DeEquip" itemid="'..itemid..'" slot="'..slot..'" script="magical_items.lua" />\n' end
local fileEx = cwd()..'movements.xml'
local s = {}
file = io.open(fileEx, "w+")
for name, t in pairs(items) do
local sl = slotNum[isInTable(slots, t.slot)]
if not sl then
elseif not s[sl] then
s[sl] = {}
else
table.insert(s[sl], movement(name, t.itemid, isInTable(slots, t.slot), t.slot, t.description))
end
end
for i in pairs(s) do
file:write('\n\t<!-- '..slotStr[i]..' -->\n')
for x = 1, #s[i] do
file:write(s[i][x])
end
end
file:close()