forked from ornfelt/azerothcore_lua_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustom_XP.lua
More file actions
100 lines (82 loc) · 3.99 KB
/
Custom_XP.lua
File metadata and controls
100 lines (82 loc) · 3.99 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
CustomXPNamespace = {}
CustomXPNamespace.enabled = true
CustomXPNamespace.GMonly = false
function CustomXPNamespace.getPlayerCharacterGUID(player)
return player:GetGUIDLow()
end
function CustomXPNamespace.GMONLY(player)
-- player:SendBroadcastMessage("|cffff0000You don't have permission to use this command.|r")
end
function CustomXPNamespace.OnLogin(event, player)
local PUID = CustomXPNamespace.getPlayerCharacterGUID(player)
local Q = WorldDBQuery(string.format("SELECT * FROM custom_xp WHERE CharID=%i", PUID))
if Q then
local CharID, Rate = Q:GetUInt32(0), Q:GetFloat(1)
player:SendBroadcastMessage(string.format("|cff5af304Your experience rate is currently set to %.1f|r", Rate))
end
end
function CustomXPNamespace.OnFirstLogin(event, player)
local PUID = CustomXPNamespace.getPlayerCharacterGUID(player)
local defaultRate = 1
WorldDBExecute(string.format("INSERT INTO custom_xp VALUES (%i, %.2f)", PUID, defaultRate))
player:SendBroadcastMessage(string.format("|cff5af304Your experience rate is set to default: %.1fx|r", defaultRate))
end
function CustomXPNamespace.SetRate(event, player, command)
local mingmrank = 3
local PUID = CustomXPNamespace.getPlayerCharacterGUID(player)
if command:find("xp") or command:find("exp") then
if player:HasItem(800048, 1) then
player:SendBroadcastMessage("|cffff0000You do not have access to this feature in Slow and Steady Mode.|r")
return false
end
if command:find("q") or command:find("Q") or command:find("?") or command == "xp" or command == "exp" then
local Q = WorldDBQuery(string.format("SELECT * FROM custom_xp WHERE CharID=%i", PUID))
if Q then
local CharID, Rate = Q:GetUInt32(0), Q:GetFloat(1)
player:SendBroadcastMessage(string.format("|cff5af304Your experience rate is currently set to %.1fx|r", Rate))
else
player:SendBroadcastMessage("|cff5af304Your experience rate is not found, default experience rate will be applied.|r")
end
player:SendBroadcastMessage("|cff5af304To set your experience rate, type '.xp X' or '.exp X' where X is a value between 0.01 and 10.|r")
return false
end
local rate = tonumber(command:sub(command:find("xp") and 4 or 5))
if rate and rate >= 0.01 and rate <= 10 then
if CustomXPNamespace.GMonly and player:GetGMRank() < mingmrank then
CustomXPNamespace.GMONLY(player)
return false
elseif not CustomXPNamespace.GMonly or player:GetGMRank() >= mingmrank then
WorldDBExecute(string.format("DELETE FROM custom_xp WHERE CharID = %i", PUID))
WorldDBExecute(string.format("INSERT INTO custom_xp VALUES (%i, %.2f)", PUID, rate))
player:SendBroadcastMessage(string.format("|cff5af304You changed your experience rate to %.2fx|r", rate))
return false
end
end
end
end
function CustomXPNamespace.OnXP(event, player, amount, victim)
local PUID = CustomXPNamespace.getPlayerCharacterGUID(player)
local Q = WorldDBQuery(string.format("SELECT * FROM custom_xp WHERE CharID=%i", PUID))
local mingmrank = 3
if Q then
local CharID, Rate = Q:GetUInt32(0), Q:GetFloat(1)
Rate = tonumber(string.format("%.1f", Rate))
if (CustomXPNamespace.GMonly and player:GetGMRank() < mingmrank) then
return amount
end
if (CustomXPNamespace.GMonly and player:GetGMRank() >= mingmrank) then
return amount * Rate
end
if (not CustomXPNamespace.GMonly) then
return amount * Rate
end
else
return amount
end
end
if CustomXPNamespace.enabled then
RegisterPlayerEvent(3, CustomXPNamespace.OnLogin)
RegisterPlayerEvent(12, CustomXPNamespace.OnXP)
RegisterPlayerEvent(42, CustomXPNamespace.SetRate)
RegisterPlayerEvent(30, CustomXPNamespace.OnFirstLogin)
end