-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcFunctions.lua
executable file
·223 lines (172 loc) · 3.88 KB
/
cFunctions.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
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
--- lib of usefull functions used in my-addons
cFunctions = {}
cFunctions.__index = cFunctions
function cFunctions.create()
local handle = {} -- our new object
setmetatable(handle,cFunctions) -- handle lookup
return handle
end
function cFunctions:dummy(str)
local s = "hallo welt...!!!! sasasd"
if str ~= nil then s=s..str;end
print(s)
return str
end
-----------------------------------
--
--
--
function cFunctions:GetColorCode(colorname)
clYellow = "|cffffff00"
clWhite = "|cffffffff"
clRed = "|cffff0000"
clGreen = "|cff00ff00"
local t = {
yellow = clYellow, white = clWhite, red = clRed, green = clGreen
}
local cn = string.lower(colorname)
local c = clWhite
for i,v in pairs(t) do
if i == cn then c = v; break;end;
end
return c
end
--
--
--
function cFunctions:ColorStr(colorname,txt)
local msg = self:GetColorCode(colorname)..txt.."|r"
return msg
end
--
--
--
function cFunctions:GetLink(item)
--print(":GetLink("..item..")")
local r = "|cff0070dd|Hitem:43102:0:0:0:0:0:0:0:19|h[Gefrorene Kugel]|h|r"
if GetItemInfo ~= nil
then
local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount,itemEquipLoc, itemTexture = GetItemInfo(item)
if itemLink ~= nil then r = itemLink end
end
return r
end
--
--
--
function cFunctions:splitItemLink(itemLink)
local _, _, Color, Ltype, Id, Enchant, Gem1, Gem2, Gem3, Gem4, Suffix, Unique, LinkLvl, Name = string.find(itemLink, "|?c?f?f?(%x*)|?H?([^:]*):?(%d+):?(%d*):?(%d*):?(%d*):?(%d*):?(%d*):?(%-?%d*):?(%-?%d*):?(%d*)|?h?%[?([^%[%]]*)%]?|?h?|?r?")
r = {
id = Id,
name = Name
}
return r
end
--
--
--
function cFunctions:dt(t)
if t == nil then t = time() end
return date("%m/%d/%y %H:%M:%S",t)
end
-- t = { 1,2,3,{ 4.1,4.2,4.3, {4.31,4.32} },5,6 }; showtable(t)
function cFunctions:showtable(t,str)
if ( str == nil ) then str = "" else str = str .. "." end
for i,v in ipairs(t) do
if type(v) ~= "table"
then print(str.."["..i.."]"..v)
else showtable(v,str)
end
end
end
--
--
--
function cFunctions:split(str, pat)
local t = {} -- NOTE: use {n = 0} in Lua-5.0
if str ~= nil then
local fpat = "(.-)" .. pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
end
return t
end
--
--
--
function cFunctions:trim (s)
return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end
--
--
--
function cFunctions:indexof(t,suche)
local found=-1
if type(t) == "table" then
for i=1,#t do
if string.lower(t[i]) == string.lower(suche) then found=i;break;end
end
end
return found
end
--
-- items zu einer liste hinzufügen
--
function cFunctions:AddUniqueToTable(t,item)
local r={}
if type(t) == "table"
then
if self:indexof(t,item) == -1 then table.insert(t,item);end
r=t
else
r={item}
end
return r
end
--
--
--
function cFunctions:DeleteFromTable(t,item)
found = self:indexof(t,item)
if found > -1 then table.remove(t,found);end
return t
end
--
--
--
function cFunctions:getkeys(t)
local keys = {};
for k,_ in pairs(t) do keys[#keys+1] = k end;
--for _,v in ipairs(keys) do print(v) end
return keys
end
--
-- sortieren einer tabelle
--item["buyoutPrice"] = buyoutPrice
-- item["count"] = count
-- t[#t+1] = item
function cFunctions:sortmultitable(t,key)
function swap(t,i,j)
local x = t[i]; t[i] = t[j];t[j] = x
return t
end
local n = #t
for i=1,n do
local item = t[i]
for j=i+1,n do
if t[j][key] < t[i][key] then t = swap(t,i,j);end
end
end
return t
end