-
Notifications
You must be signed in to change notification settings - Fork 3
/
premium.lua
130 lines (100 loc) · 3.4 KB
/
premium.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
local playerPP = {}
function loadPlayerPP(player)
local xPlayer = ESX.GetPlayerFromId(player)
if not xPlayer then
return 0
end
local value = MySQL.scalar.await("SELECT premiumPoints FROM users WHERE identifier = ?", { xPlayer.identifier })
playerPP[player] = value
return value
end
function getPlayerPP(player)
if not playerPP[player] then
return loadPlayerPP(player)
end
return playerPP[player] or 0
end
exports("getPlayerPP", getPlayerPP)
function setPlayerPP(player, value)
local xPlayer = ESX.GetPlayerFromId(player)
if not xPlayer then
return false
end
playerPP[player] = value
MySQL.query("UPDATE users SET premiumPoints = ? WHERE identifier = ?", { value, xPlayer.identifier })
return true
end
exports("setPlayerPP", setPlayerPP)
function takePlayerPP(player, value)
local currentPP = getPlayerPP(player)
if currentPP < value then
return false
end
currentPP = currentPP - value
setPlayerPP(player, currentPP)
return true
end
exports("takePlayerPP", takePlayerPP)
RegisterCommand("setpp", function(player, args)
local xPlayer = ESX.GetPlayerFromId(player)
if not ADMIN_GROUPS[xPlayer.getGroup()] then
return chatbox("Nincs jogod ehhez!", { 255, 0, 0 }, player)
end
if #args < 2 or not tonumber(args[2]) then
return chatbox("/setpp [ID] [PP]", { 255, 150, 0 }, player)
end
local xTarget = ESX.GetPlayerFromId(args[1] == "me" and player or args[1])
if not xTarget then
return chatbox("Játékos nem található!", { 255, 0, 0 }, player)
end
local value = math.floor(tonumber(args[2]))
if value <= 0 then
return chatbox("Ne má", { 255, 0, 0 }, player)
end
setPlayerPP(xTarget.source, value)
chatbox(
GetPlayerName(player) .. " beállította a prémium pontjaid. Érték: " .. value,
{ 0, 255, 0 },
xTarget.source
)
end)
RegisterCommand("givepp", function(player, args)
local xPlayer = ESX.GetPlayerFromId(player)
if not ADMIN_GROUPS[xPlayer.getGroup()] then
return chatbox("Nincs jogod ehhez!", { 255, 0, 0 }, player)
end
if #args < 2 or not tonumber(args[2]) then
return chatbox("/givepp [ID] [PP]", { 255, 150, 0 }, player)
end
local xTarget = ESX.GetPlayerFromId(args[1] == "me" and player or args[1])
if not xTarget then
return chatbox("Játékos nem található!", { 255, 0, 0 }, player)
end
local value = math.floor(tonumber(args[2]))
if value <= 0 then
return chatbox("Ne má", { 255, 0, 0 }, player)
end
setPlayerPP(xTarget.source, getPlayerPP(xTarget.source) + value)
chatbox(GetPlayerName(player) .. " adott prémium pontot. Mennyiség: " .. value, { 0, 255, 0 }, xTarget.source)
end)
RegisterCommand("takepp", function(player, args)
local xPlayer = ESX.GetPlayerFromId(player)
if not ADMIN_GROUPS[xPlayer.getGroup()] then
return chatbox("Nincs jogod ehhez!", { 255, 0, 0 }, player)
end
if #args < 2 or not tonumber(args[2]) then
return chatbox("/takepp [ID] [PP]", { 255, 150, 0 }, player)
end
local xTarget = ESX.GetPlayerFromId(args[1] == "me" and player or args[1])
if not xTarget then
return chatbox("Játékos nem található!", { 255, 0, 0 }, player)
end
local value = math.floor(tonumber(args[2]))
if value <= 0 then
return chatbox("Ne má", { 255, 0, 0 }, player)
end
if not takePlayerPP(xTarget.source, value) then
return chatbox("Játékosnak nem lehet negatívba a prémiumja", { 255, 0, 0 }, player)
end
chatbox(GetPlayerName(player) .. " levont prémium pontot. Mennyiség: " .. value, { 0, 255, 0 }, xTarget.source)
end)