-
Notifications
You must be signed in to change notification settings - Fork 8
/
LevelUpReward.lua
203 lines (182 loc) · 9.99 KB
/
LevelUpReward.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
--
-- Created by IntelliJ IDEA.
-- User: Silvia
-- Date: 28/02/2021
-- Time: 23:16
-- To change this template use File | Settings | File Templates.
-- Originally created by Honey for Azerothcore
-- requires ElunaLua module
-- Updated By: Ragundah
-- Date: 13/05/2021
--Players will receive rewards when their characters reach the levels in brackets.
------------------------------------------------------------------------------------------------
-- ADMIN GUIDE: - compile the core with ElunaLua module
-- - adjust config in this file
-- - create a character who appears as sender of the mails with senderGUID
-- - add this script to ../lua_scripts/
------------------------------------------------------------------------------------------------
local Config_Gold = {}
local Config_ItemId = {}
local Config_ItemAmount = {}
local LUR_playerCounter = {}
Config_Gold[10] = 10000 -- gold granted when reaching level [10] in copper. 10000 = 1 gold. Cost for spells 10-18 (mage): ~1g50s
Config_Gold[20] = 70000 -- Cost for spells 20-28 (mage): ~11g
Config_Gold[30] = 180000 -- Cost for spells 30-38 (mage): ~27g
Config_Gold[40] = 350000 -- Cost for spells 40-48 (mage): ~50g
Config_Gold[50] = 650000 -- Cost for spells 50-58 (mage): ~93g
Config_Gold[61] = 600000
Config_Gold[65] = 800000
Config_Gold[71] = 1000000
Config_Gold[75] = 1800000
Config_Gold[80] = 5000000
Config_ItemId[29] = 5740 -- item granted when reaching level [29] / 5740 is a cosmetic red rocket
Config_ItemAmount[29] = 5 -- amount of items to be granted when reaching level [29]. Missing amounts are automatically set to 1 if an ItemId is given
Config_ItemId[35] = 34412
Config_ItemAmount[35] = 10
Config_ItemId[39] = 9312
Config_ItemAmount[39] = 5
Config_ItemId[43] = 9313
Config_ItemAmount[43] = 5
Config_ItemId[46] = 35565
Config_ItemAmount[46] = 10
Config_ItemId[49] = 35563
Config_ItemAmount[49] = 10
Config_ItemId[59] = 9314
Config_ItemAmount[59] = 5
Config_ItemId[60] = 9315
Config_ItemAmount[60] = 5
Config_ItemId[64] = 9312
Config_ItemAmount[64] = 5
Config_ItemId[69] = 9313
Config_ItemAmount[69] = 5
Config_ItemId[70] = 9314
Config_ItemAmount[70] = 5
-- General Settings Config
local Config_mailText = 2 -- Which text to send in the mail to the player.
local Config_senderGUID = 10667 -- GUID/ID of the Player/Creature. If Config_preventReturn = true then you need to put Creature ID. If it's false Player GUID. 0 = No sender aka "From: Unknown".
local Config_mailStationery = 41 -- Stationary used in the mail sent to the player. (41 Normal Mail, 61 GM/Blizzard Support, 62 Auction, 64 Valentines, 65 Christmas) Note: Use 62, 64, and 65 At your own risk.
local Config_maxGMRank = 0 -- Checks the player's assigned GM rank. Anything above the assigned default will not receive mail/be counted for the player counter. Default 0 - Players Only. Max 3 - All GMS/Mods/Etc will receive as well.
local Config_preventReturn = true -- Modify's the Mail database to prevent returning of rewards. Note: If you are experiencing server lag after installing this module please disable this option to see if it helps.
-- Config_mailText == 1 Config
local Config_mailSubject1 = "Chromies reward for You!"
local Config_mailText1 = "!\n\nYou've done well while advancing on ChromieCraft. Here is a small reward to celebrate your heroic deeds. Go forth!\n\nKind regards,\nChromie"
-- Config_mailText == 2 Config
local Config_mailSubject2 = "Chromies reward for You!"
local Config_mailText2A = " and congratulations! \n\nThe bronze Dragonflight would like to inform you that you were the "
local Config_mailText2B = " adventurer to reach the "
local Config_mailText2C = " level of mastery.\nYour adventures have made me take notice of you, take this small reward as a token of my appreciation.\nGo forth!\n\nKind regards,\nChromie"
-- Name of Eluna dB scheme
local Config_customDbName = 'ac_eluna';
------------------------------------------
-- NO ADJUSTMENTS REQUIRED BELOW THIS LINE
------------------------------------------
CharDBQuery('CREATE DATABASE IF NOT EXISTS `'..Config_customDbName..'`;');
CharDBQuery('CREATE TABLE IF NOT EXISTS `'..Config_customDbName..'`.`levelup_reward` (`level` INT NOT NULL, `counter` INT DEFAULT 0, PRIMARY KEY (`level`) );');
local n
for n = 2,80,1 do
LUR_playerCounter[n] = 0
end
Data_SQL = CharDBQuery('SELECT `level`, `counter` FROM `'..Config_customDbName..'`.`levelup_reward`;');
if Data_SQL ~= nil then
local levelRow
repeat
levelRow = Data_SQL:GetUInt32(0)
LUR_playerCounter[levelRow] = Data_SQL:GetUInt32(1)
until not Data_SQL:NextRow()
end
local PLAYER_EVENT_ON_LEVEL_CHANGE = 13
local function PreventReturn(playerGUID)
if Config_preventReturn == true then
CharDBExecute('UPDATE `mail` SET `messageType` = 3 WHERE `sender` = '..Config_senderGUID..' AND `receiver` = '..playerGUID..' AND `messageType` = 0;')
end
end
local function GrantReward(event, player, oldLevel)
if oldLevel ~= nil and player:GetGMRank() <= Config_maxGMRank then
if Config_mailText == 1 then
if Config_ItemId[oldLevel + 1] ~= nil then
local playerName = player:GetName()
local playerGUID = tostring(player:GetGUID())
local itemAmount
if Config_ItemAmount[oldLevel + 1] ~= nil then
itemAmount = Config_ItemAmount[oldLevel + 1]
else
itemAmount = 1
end
if Config_Gold[oldLevel + 1] == nil then
Config_Gold[oldLevel + 1] = 0
end
SendMail(Config_mailSubject1, "Hello "..playerName..Config_mailText1, playerGUID, Config_senderGUID, Config_mailStationery, 0, Config_Gold[oldLevel + 1],0,Config_ItemId[oldLevel + 1], itemAmount)
print("LevelUpReward has granted "..Config_Gold[oldLevel + 1].." copper and "..itemAmount.." of item "..Config_ItemId[oldLevel + 1].." to character "..playerName.." with guid "..playerGUID..".")
PreventReturn(playerGUID)
playerName = nil
playerGUID = nil
return false
elseif Config_Gold[oldLevel + 1] ~= nil then
local playerName = player:GetName()
local playerGUID = tostring(player:GetGUID())
SendMail(Config_mailSubject1, "Hello "..playerName..Config_mailText1, playerGUID, Config_senderGUID, Config_mailStationery, 0, Config_Gold[oldLevel + 1])
print("LevelUpReward has granted "..Config_Gold[oldLevel + 1].." copper to character "..playerName.." with guid "..playerGUID..".")
PreventReturn(playerGUID)
playerName = nil
playerGUID = nil
return false
end
end
local playerCounterStr
local currentLevelStr
local currentLevel = oldLevel + 1
LUR_playerCounter[currentLevel] = LUR_playerCounter[currentLevel] + 1
CharDBExecute('REPLACE INTO `'..Config_customDbName..'`.`levelup_reward` VALUES ('..currentLevel..', '..LUR_playerCounter[currentLevel]..');');
playerCounterStr = tostring(LUR_playerCounter[currentLevel])
if string.sub(playerCounterStr, -1) == "1" then
playerCounterStr = playerCounterStr.."st"
elseif string.sub(playerCounterStr, -1) == "2" then
playerCounterStr = playerCounterStr.."nd"
elseif string.sub(playerCounterStr, -1) == "3" then
playerCounterStr = playerCounterStr.."rd"
else
playerCounterStr = playerCounterStr.."th"
end
currentLevelStr = tostring(currentLevel)
if string.sub(currentLevelStr, -1) == "1" then
currentLevelStr = currentLevelStr.."st"
elseif string.sub(currentLevelStr, -1) == "2" then
currentLevelStr = currentLevelStr.."nd"
elseif string.sub(currentLevelStr, -1) == "3" then
currentLevelStr = currentLevelStr.."rd"
else
currentLevelStr = currentLevelStr.."th"
end
if Config_mailText == 2 then
if Config_ItemId[oldLevel + 1] ~= nil and Config_mailText == 2 then
local playerName = player:GetName()
local playerGUID = tostring(player:GetGUID())
local itemAmount
if Config_ItemAmount[oldLevel + 1] ~= nil then
itemAmount = Config_ItemAmount[oldLevel + 1]
else
itemAmount = 1
end
if Config_Gold[oldLevel + 1] == nil then
Config_Gold[oldLevel + 1] = 0
end
SendMail(Config_mailSubject2, "Hello "..playerName..Config_mailText2A..playerCounterStr..Config_mailText2B..currentLevelStr..Config_mailText2C, playerGUID, Config_senderGUID, Config_mailStationery, 0, Config_Gold[oldLevel + 1],0,Config_ItemId[oldLevel + 1], itemAmount)
print("LevelUpReward has granted "..Config_Gold[oldLevel + 1].." copper and "..itemAmount.." of item "..Config_ItemId[oldLevel + 1].." to character "..playerName.." with guid "..playerGUID..".")
PreventReturn(playerGUID)
playerName = nil
playerGUID = nil
return false
elseif Config_Gold[oldLevel + 1] ~= nil and Config_mailText == 2 then
local playerName = player:GetName()
local playerGUID = tostring(player:GetGUID())
SendMail(Config_mailSubject2, "Hello "..playerName..Config_mailText2A..playerCounterStr..Config_mailText2B..currentLevelStr..Config_mailText2C, playerGUID, Config_senderGUID, Config_mailStationery, 0, Config_Gold[oldLevel + 1])
print("LevelUpReward has granted "..Config_Gold[oldLevel + 1].." copper to character "..playerName.." with guid "..playerGUID..".")
PreventReturn(playerGUID)
playerName = nil
playerGUID = nil
return false
end
end
end
end
RegisterPlayerEvent(PLAYER_EVENT_ON_LEVEL_CHANGE, GrantReward)