-
Notifications
You must be signed in to change notification settings - Fork 9
/
command-points.xml
338 lines (291 loc) · 13 KB
/
command-points.xml
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<?xml version="1.0" encoding="UTF-8"?>
<mod name="command-points" version="1.0" author="slawkens" contact="slawkens@gmail.com" enabled="yes">
<config name="command-points-config"><![CDATA[
config = {
logFile = "data/logs/points.log", -- set file name where to save logs. Leave empty do disable logs.
pointsRune = {
enabled = "yes",
points = 50,
runeId = 2294,
minLevel = 8
},
pacc = {
enabled = "yes",
points = 50,
days = 14,
maxDays = 360 -- maximum premium account days
},
changeName = {
enabled = "yes",
points = 50,
storage = 3008,
delay = 30 * 24 * 60 * 60 -- 30 days, in seconds
},
changeSex = {
enabled = "yes",
points = 20
},
removeSkull = {
enabled = "yes",
points = 50
},
refuelStamina = {
enabled = "yes",
points = 30,
full = 42 * 60 -- full stamina in minutes
}
}
]]></config>
<!--
TODO:
* add /points command for admins to check/manage player points
-->
<lib name="command-points-lib"><![CDATA[
domodlib('command-points-config')
config.pointsRune.enabled = getBooleanFromString(config.pointsRune.enabled)
config.pacc.enabled = getBooleanFromString(config.pacc.enabled)
config.changeName.enabled = getBooleanFromString(config.changeName.enabled)
config.changeSex.enabled = getBooleanFromString(config.changeSex.enabled)
config.removeSkull.enabled = getBooleanFromString(config.removeSkull.enabled)
config.refuelStamina.enabled = getBooleanFromString(config.refuelStamina.enabled)
function getPlayerPoints(cid)
return getAccountPoints(getPlayerAccountId(cid))
end
function doPlayerAddPoints(cid, points)
return doAccountAddPoints(getPlayerAccountId(cid), points)
end
function doPlayerRemovePoints(cid, points)
return doPlayerAddPoints(cid, -points)
end
function getAccountPoints(accountId)
local result = db.getResult('SELECT premium_points FROM accounts WHERE id = ' .. accountId)
local v = 0
if(result:getID() ~= -1) then
v = tonumber(result:getDataInt("premium_points"))
result:free()
end
return v
end
function doAccountAddPoints(accountId, points)
if(points < 0 and getAccountPoints(accountId) < math.abs(points)) then
return false
end
return db.executeQuery('UPDATE accounts SET premium_points = premium_points + ' .. points .. ' WHERE id = ' .. accountId)
end
command_points = {
config = config,
logAction = function (str)
if(command_points.config.logFile:trim() == '') then
return
end
doWriteLogFile(command_points.config.logFile, str)
end,
pointsRune = function (cid)
if(command_points.config.pointsRune.minLevel and getPlayerLevel(cid) < command_points.config.pointsRune.minLevel) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You need " .. command_points.config.pointsRune.minLevel .. " level to buy this rune.")
return true
end
if(getPlayerPoints(cid) < command_points.config.pointsRune.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. This rune cost " .. command_points.config.pointsRune.points .. " points.")
return true
end
local item = doCreateItemEx(command_points.config.pointsRune.runeId, 1)
local status = doPlayerAddItemEx(cid, item, false)
if(status ~= RETURNVALUE_NOERROR and status) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Not enought space for rune.")
return true
end
if(doPlayerRemovePoints(cid, command_points.config.pointsRune.points)) then
doSendMagicEffect(getCreaturePos(cid), 40)
doPlayerSave(cid)
command_points.logAction("pointsRune: " .. getCreatureName(cid))
else
doPlayerSendCancel(cid, "ERROR. Please try again later.")
end
end,
pacc = function(cid)
if(getPlayerPoints(cid) < command_points.config.pacc.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. Premium account cost " .. command_points.config.pacc.points .. " points.")
return true
end
if(getPlayerPremiumDays(cid) > command_points.config.pacc.maxDays) then
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You can not buy more than " .. config.days + command_points.config.pacc.maxDays .. " days of Premium Account.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return
end
if(not doPlayerRemovePoints(cid, command_points.config.pacc.points)) then
doPlayerSendCancel(cid, "You don't have enough points, " .. command_points.config.pacc.days .. " days premium account costs " .. command_points.config.pacc.points .. " points.")
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return
end
doPlayerAddPremiumDays(cid, command_points.config.pacc.days)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought " .. command_points.config.pacc.days .. " days of premium account.")
end,
changeName = function (cid)
if(not getTileInfo(getCreaturePosition(cid)).protection) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You can use this command only in protection zone.")
return true
end
local lastChange = getPlayerStorageValue(cid, command_points.config.changeName.storage)
if(os.time() < lastChange + command_points.config.changeName.delay) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, this command have limited usage. You will be able to use it next time at " .. os.date("%X on %d.%m.%y", lastChange + command_points.config.changeName.delay) .. ".")
return true
end
if(getPlayerPoints(cid) < command_points.config.changeName.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. Namelock cost " .. command_points.config.changeName.points .. " points.")
return true
end
if(doPlayerRemovePoints(cid, command_points.config.changeName.points)) then
setPlayerStorageValue(cid, command_points.config.changeName.storage, os.time())
doAddPlayerBanishment(getCreatureName(cid), BAN_PLAYER, -1, ACTION_NAMELOCK)
command_points.logAction("changeName: " .. getCreatureName(cid))
doRemoveCreature(cid)
else
doPlayerSendCancel(cid, "ERROR. Please try again later.")
end
end,
changeSex = function (cid)
if(getPlayerPoints(cid) < command_points.config.changeSex.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. Change sex cost " .. command_points.config.changeSex.points .. " points.")
return true
end
local partner = getPlayerPartner(cid)
if(partner and partner ~= 0) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, you cannot change your sex while being married.")
return true
end
if(doPlayerRemovePoints(cid, command_points.config.changeSex.points)) then
local newSex = getPlayerSex(cid) == PLAYERSEX_FEMALE and PLAYERSEX_MALE or PLAYERSEX_FEMALE
doPlayerSetSex(cid, newSex)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Sex changed to " .. (newSex == PLAYERSEX_FEMALE and "female" or "male") .. ".")
doPlayerSave(cid)
command_points.logAction("changeSex: " .. getCreatureName(cid))
else
doPlayerSendCancel(cid, "ERROR. Please try again later.")
end
end,
removeSkull = function (cid)
local skull = getCreatureSkullType(cid)
if(skull ~= SKULL_RED and skull ~= SKULL_BLACK) then
doPlayerSendCancel(cid, "You do not have red/black skull.")
return true
end
if(getPlayerPoints(cid) < command_points.config.removeSkull.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. Remove skull cost " .. command_points.config.removeSkull.points .. " points.")
return true
end
if(doPlayerRemovePoints(cid, command_points.config.pointsRune.points)) then
db.executeQuery("UPDATE killers SET unjustified = 0 WHERE id IN (SELECT kill_id FROM player_killers WHERE player_id = " .. getPlayerGUID(cid) .. ")")
doCreatureSetSkullType(cid, SKULL_NONE)
doPlayerSetSkullEnd(cid, 0, skull)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_RED, "Your skull has been taken off!\nRemaining premium points: " .. getPlayerPoints(cid))
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_YELLOW_RINGS)
doPlayerSave(cid)
command_points.logAction("removeSkull: " .. getCreatureName(cid))
else
doPlayerSendCancel(cid, "ERROR. Please try again later.")
end
end,
refuelStamina = function (cid)
if(getPlayerPoints(cid) < command_points.config.refuelStamina.points) then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, not enought points on your account. Stamina refill cost " .. command_points.config.refuelStamina.points .. " points.")
return true
end
if(getPlayerStamina(cid) >= command_points.config.refuelStamina.full) then
doPlayerSendCancel(cid, "Your stamina is already full.")
elseif(not isPremium(cid)) then
doPlayerSendCancel(cid, "You must have a premium account.")
else
if(doPlayerRemovePoints(cid, command_points.config.refuelStamina.points)) then
doPlayerSetStamina(cid, command_points.config.refuelStamina.full)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Your stamina has been refilled.")
doPlayerSave(cid)
command_points.logAction("refuelStamina: " .. getCreatureName(cid))
else
doPlayerSendCancel(cid, "ERROR. Please try again later.")
end
end
end
}
]]></lib>
<talkaction words="!points" event="script"><![CDATA[
domodlib('command-points-lib')
function onSay(cid, words, param, channel)
if(param == '') then
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You have " .. getPlayerPoints(cid) .. " points on your account.")
return true
end
param = param:lower():trim()
if(command_points.config.changeName.enabled and isInArray({"name", "namelock", "changename"}, param)) then
command_points.changeName(cid)
elseif(command_points.config.changeSex.enabled and isInArray({"sex", "changesex", "changender", "changegender"}, param)) then
command_points.changeSex(cid)
elseif(command_points.config.pacc.enabled and isInArray({"pacc", "premium"}, param)) then
command_points.pacc(cid)
elseif(command_points.config.pointsRune.enabled and isInArray({"rune", "pointsrune"}, param)) then
command_points.pointsRune(cid)
elseif(command_points.config.removeSkull.enabled and isInArray({"rs", "skull", "frags"}, param)) then
command_points.removeSkull(cid)
elseif(command_points.config.refuelStamina.enabled and isInArray({"stamina"}, param)) then
command_points.refuelStamina(cid)
else
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Invalid option.")
end
return true
end
]]></talkaction>
<!--
<talkaction words="!rs" event="script"><![CDATA[
domodlib('command-points-lib')
function onSay(cid, words, param, channel)
command_points.removeSkull(cid)
return true
end
]]></talkaction>
<talkaction words="!changename" event="script"><![CDATA[
domodlib('command-points-lib')
function onSay(cid, words, param, channel)
command_points.changeName(cid
return true
end
]]></talkaction>
<talkaction words="!changesex" event="script"><![CDATA[
domodlib('command-points-lib')
function onSay(cid, words, param, channel)
command_points.changeSex(cid
return true
end
]]></talkaction>
<talkaction words="!pacc" event="script"><![CDATA[
domodlib('command-points-lib')
function onSay(cid, words, param, channel)
command_points.pacc(cid
return true
end
]]></talkaction>
-->
<!-- Points rune -->
<!-- You can remove/comment below lines if you don't want to use it -->
<action itemid="2294" allowfaruse="1" blockwalls="1" event="script"><![CDATA[
domodlib('command-points-lib')
function onUse(cid, item, fromPosition, itemEx, toPosition)
if(not isPlayer(itemEx.uid) or not command_points.config.pointsRune.enabled) then
return false
end
if(doRemoveItem(item.uid, 1)) then
doPlayerAddPoints(itemEx.uid, command_points.config.pointsRune.points)
doSendMagicEffect(toPosition, CONST_ME_BIGCLOUDS)
doPlayerSave(cid)
command_points.logAction("pointsRune: " .. getCreatureName(cid) .. " (used)")
else
doPlayerSendTextMessage(cid, "Points couldn't be added. Please try again later.")
end
return true
end
]]></action>
<item id="2294" article="a" name="points rune" override="yes">
<attribute key="runeSpellName" value="Points Rune"/>
<attribute key="weight" value="120"/>
<attribute key="description" value="50 points. Use it on yourself or other player to add points."/>
</item>
</mod>