-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathadvance-reward.xml
132 lines (115 loc) · 4.09 KB
/
advance-reward.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
<?xml version="1.0" encoding="UTF-8"?>
<mod name="advance-reward" version="1.0" author="slawkens" contact="[email protected]" enabled="yes">
<config name="advance-reward-config"><![CDATA[
rewards = {
-- {skill = SKILL__LEVEL, level = 100, storage = 3100, item = 2160, count = 30},
-- {skill = SKILL_FISHING, level = 20, storage = 3101, item = 3976, count = 100},
-- more examples
--{skill = SKILL_SWORD, level = 110, storage = 3102, item = 2400, message = "Take this as a reward for advancing in 120 sword fighting level!", effect = 61}
--[[ items in a backpack
{skill = SKILL__LEVEL, level = 50, storage = 3103, item = 2000,
inside = {
{id = 2160, count = 1},
{id = 2152, count = 50},
{id = 2195}
}
}
]]--
--[[ only for specified vocations (in this case - sorcerers & druids)
{skill = SKILL_AXE, level = 50, storage = 3104, item = 7884,
callback = function(cid, reward)
return isInArray({1, 2, 5, 6}, getPlayerVocation(cid))
end
}
]]--
--[[ this one will only broadcast message (without giving any reward)
{skill = SKILL__LEVEL, level = 300, storage = 3105, message = false,
callback = function(cid, reward)
doBroadcastMessage(getCreatureName(cid) .. " has advanced to Level 300. Congratulations!", MESSAGE_EVENT_ADVANCE)
return true
end
},
]]--
}
-- message player see when getting reward, can be personalized for each reward
message = "Congratulations, you advanced in {SKILL} level {LEVEL} and received {ITEM} as a reward!"
messageType = MESSAGE_INFO_DESCR
-- uncomment if you want to see magic effect when reward is added
--effect = 30 -- magic effect id
]]></config>
<event type="advance" name="advance-reward-event" event="script"><![CDATA[
domodlib('advance-reward-config')
local config = {
rewards = rewards,
message = message,
messageType = messageType,
effect = effect
}
function onAdvance(cid, skill, oldLevel, newLevel)
if(not config.rewards) then
return true
end
for _, reward in pairs(config.rewards) do
if(reward.skill == skill and newLevel >= reward.level
and (reward.storage <= 0 or getPlayerStorageValue(cid, reward.storage) ~= 1))
then
if(not reward.callback or reward.callback(cid, reward)) then
local continue = true
if(reward.item) then
if(not reward.inside) then
if(doPlayerAddItem(cid, reward.item, reward.count or 1) == false) then
continue = false
end
elseif(isItemContainer(reward.item)) then
local container = doCreateItemEx(reward.item, 1)
for _, item in ipairs(reward.inside) do
doAddContainerItem(container, item.id, item.count or 1)
end
if(doPlayerAddItemEx(cid, container, false) ~= RETURNVALUE_NOERROR) then
continue = false
end
end
end
if(continue) then
if(reward.storage > 0) then
setPlayerStorageValue(cid, reward.storage, 1)
end
local message = reward.message or config.message
if(type(reward.message) == 'boolean') then
message = reward.message
end
if(message) then
local t = {
["NAME"] = getCreatureName(cid),
["SKILL"] = SKILL_NAMES[skill],
["OLDLEVEL"] = oldLevel,
["NEWLEVEL"] = newLevel,
["LEVEL"] = reward.level
}
if(reward.item) then
t["ITEM"] = getItemNameById(reward.item)
if(reward.count) then
t["ITEMCOUNT"] = reward.count
end
end
local messageType = reward.messageType or config.messageType
if(messageType) then
doPlayerSendTextMessage(cid, messageType, tostring(message:gsub("{(.-)}", function(v) return t[v] end)))
end
end
local effect = reward.effect or config.effect
if(effect) then
doSendMagicEffect(getCreaturePosition(cid), effect)
end
end
end
end
end
return true
end
]]></event>
<event type="login" name="advance-reward-login" event="buffer"><![CDATA[
registerCreatureEvent(cid, "advance-reward-event")
_result = true
]]></event>
</mod>