-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdressMe.lua
More file actions
223 lines (203 loc) · 7.47 KB
/
dressMe.lua
File metadata and controls
223 lines (203 loc) · 7.47 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
local MODULE_NAME = "Eluna dressMe"
local MODULE_VERSION = '1.3.6'
local MODULE_AUTHOR = "Mpromptu Gaming"
print("["..MODULE_NAME.."]: Loaded, Version "..MODULE_VERSION.." Active")
local copperCost = 1
local EQUIPMENT_SLOT_START = 0
local EQUIPMENT_SLOT_HEAD = 0
local EQUIPMENT_SLOT_NECK = 1
local EQUIPMENT_SLOT_SHOULDERS = 2
local EQUIPMENT_SLOT_BODY = 3
local EQUIPMENT_SLOT_CHEST = 4
local EQUIPMENT_SLOT_WAIST = 5
local EQUIPMENT_SLOT_LEGS = 6
local EQUIPMENT_SLOT_FEET = 7
local EQUIPMENT_SLOT_WRISTS = 8
local EQUIPMENT_SLOT_HANDS = 9
local EQUIPMENT_SLOT_FINGER1 = 10
local EQUIPMENT_SLOT_FINGER2 = 11
local EQUIPMENT_SLOT_TRINKET1 = 12
local EQUIPMENT_SLOT_TRINKET2 = 13
local EQUIPMENT_SLOT_BACK = 14
local EQUIPMENT_SLOT_MAINHAND = 15
local EQUIPMENT_SLOT_OFFHAND = 16
local EQUIPMENT_SLOT_RANGED = 17
local EQUIPMENT_SLOT_TABARD = 18
local EQUIPMENT_SLOT_END = 19
local INVENTORY_SLOT_BAG_0 = 255
local PLAYER_VISIBLE_ITEM_1_ENTRYID = 283
local HIDDEN_ENTRY = 11930
local ITEM_SLOT_MULTIPLIER = 2
local entryMap = {}
local dataMap = {}
local slotNames = {
["head"] = "00",
["shoulders"] = "02",
["chest"] = "04",
["waist"] = "05",
["legs"] = "06",
["feet"] = "07",
["wrists"] = "08",
["hands"] = "09",
["back"] = "14",
}
local function GetFakeEntry(item)
local guid = item and item:GetGUIDLow()
if guid and dataMap[guid] then
if entryMap[dataMap[guid]] then
return entryMap[dataMap[guid]][guid]
end
end
end
local function LoadPlayer(player)
print("["..MODULE_NAME.."]: Loaded "..player:GetName())
local playerGUID = player:GetGUIDLow()
entryMap[playerGUID] = {}
local result = CharDBQuery("SELECT GUID, FakeEntry FROM eluna_transmog WHERE Owner = "..playerGUID)
if result then
repeat
local itemGUID = result:GetUInt32(0)
local fakeEntry = result:GetUInt32(1)
dataMap[itemGUID] = playerGUID
entryMap[playerGUID][itemGUID] = fakeEntry
until not result:NextRow()
for slot = EQUIPMENT_SLOT_START, EQUIPMENT_SLOT_END-1 do
local item = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slot)
if item then
if entryMap[playerGUID] then
if entryMap[playerGUID][item:GetGUIDLow()] then
player:UpdateUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * ITEM_SLOT_MULTIPLIER), entryMap[playerGUID][item:GetGUIDLow()])
end
end
end
end
end
end
local function DeleteFakeFromDB(itemGUID)
if dataMap[itemGUID] then
if entryMap[dataMap[itemGUID]] then
entryMap[dataMap[itemGUID]][itemGUID] = nil
end
dataMap[itemGUID] = nil
end
CharDBExecute("DELETE FROM eluna_transmog WHERE GUID = "..itemGUID)
end
local function DeleteFakeEntry(item)
if not GetFakeEntry(item) then
return false
end
item:GetOwner():UpdateUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * ITEM_SLOT_MULTIPLIER), item:GetEntry())
if item then
DeleteFakeFromDB(item:GetGUIDLow())
end
return true
end
local function SetFakeEntry(player, item, entry)
if item then
local pGUID = player:GetGUIDLow()
local iGUID = item:GetGUIDLow()
player:UpdateUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (item:GetSlot() * ITEM_SLOT_MULTIPLIER), entry)
if not entryMap[pGUID] then
entryMap[pGUID] = {}
end
entryMap[pGUID][iGUID] = entry
dataMap[iGUID] = pGUID
CharDBExecute("REPLACE INTO eluna_transmog (GUID, FakeEntry, Owner) VALUES ("..iGUID..", "..entry..", "..pGUID..")")
end
end
local function DeleteAllTransmogs(player)
print("["..MODULE_NAME.."]: Reset All")
player:SendAreaTriggerMessage("Transmogs have been reset")
for slot = EQUIPMENT_SLOT_START, EQUIPMENT_SLOT_END-1 do
local item = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slot)
if item then
DeleteFakeEntry(item)
end
end
CharDBExecute("DELETE FROM eluna_transmog WHERE Owner = "..player:GetGUIDLow())
end
local function ProcessCopper(player)
player:ModifyMoney(1)
player:ModifyMoney(-1)
end
local function wait(seconds)
local start = os.time()
repeat until os.time() > start + seconds
end
local function onChatMessage(event, player, msg, _, lang)
if (msg:find('#transmog') == 1 and #msg == 9) then
player:SendBroadcastMessage("Command '#transmog' help:\n#transmog apply\n#transmog hybrid\n#transmog nude\n#transmog hide [slot] (slots: head, shoulders, chest, waist, legs, feet, wrists, hands, back")
return false
elseif (msg:find('#transmog apply') == 1) then
player:PlayDirectSound(3337)
ProcessCopper(player)
LoadPlayer(player)
return false
elseif (msg:find('#transmog hybrid') == 1) then
local hybridClass = GetHybridClass(player)
HybridSetTransmog(player, hybridClass)
return false
elseif (msg:find('#transmog reset') == 1) then
player:PlayDirectSound(3337)
ProcessCopper(player)
DeleteAllTransmogs(player)
LoadPlayer(player)
return false
elseif (msg:find('#transmog nude') == 1) then
for i, v in pairs(slotNames) do
player:SendUnitSay("#transmog "..v.." "..HIDDEN_ENTRY, 0)
end
return false
elseif (msg:find('#transmog hide') == 1) then
local slotName = slotNames[string.sub(msg, 16)]
if slotName then
player:SendUnitSay("#transmog "..slotName.." "..HIDDEN_ENTRY, 0)
else
player:SendBroadcastMessage("Unknown slot name")
end
return false
elseif (msg:find('#transmog') == 1) then
local slotID = string.sub(msg, 10, 12)
local entry = string.sub(msg, 14)
local item = player:GetItemByPos(INVENTORY_SLOT_BAG_0, slotID)
player:PlayDirectSound(3337, player)
ProcessCopper(player)
SetFakeEntry(player, item, entry)
return false
end
end
local function onLogin(event, player)
ProcessCopper(player)
LoadPlayer(player)
end
local function onLogout(event, player)
local pGUID = player:GetGUIDLow()
entryMap[pGUID] = nil
end
local function onEquip(event, player, item, bag, slot)
local fentry = GetFakeEntry(item)
if fentry then
if item:GetOwnerGUID() ~= player:GetGUID() then
DeleteFakeFromDB(item:GetGUIDLow())
return
end
player:SetUInt32Value(PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * ITEM_SLOT_MULTIPLIER), fentry)
end
end
CharDBQuery([[
CREATE TABLE IF NOT EXISTS `eluna_transmog` (
`GUID` INT(10) UNSIGNED NOT NULL COMMENT 'Item guidLow',
`FakeEntry` INT(10) UNSIGNED NOT NULL COMMENT 'Item entry',
`Owner` INT(10) UNSIGNED NOT NULL COMMENT 'Player guidLow',
PRIMARY KEY (`GUID`)
)
COMMENT='version 4.0'
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB;
]])
print("["..MODULE_NAME.."]: Deleting non-existing transmogrification entries")
CharDBQuery("DELETE FROM eluna_transmog WHERE NOT EXISTS (SELECT 1 FROM item_instance WHERE item_instance.guid = eluna_transmog.GUID)")
RegisterPlayerEvent(18, onChatMessage)
RegisterPlayerEvent(3, onLogin)
RegisterPlayerEvent(4, onLogout)
RegisterPlayerEvent(29, onEquip)