Skip to content

Commit 1d4e09f

Browse files
authored
Refactor player kick and ban logic for permissions
1 parent a2c34ba commit 1d4e09f

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

server/oufits.lua

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,58 +80,56 @@ end)
8080
RegisterNetEvent("vMenu:kickPlayer")
8181
AddEventHandler("vMenu:kickPlayer", function(targetId, reason)
8282
local src = source
83-
local adminName = GetPlayerName(src)
84-
85-
if GetPlayerPing(targetId) > 0 then -- Check if player exists
86-
local targetName = GetPlayerName(targetId)
87-
DropPlayer(targetId, "Kicked by " .. adminName .. " - Reason: " .. reason)
88-
89-
TriggerClientEvent('chat:addMessage', -1, {
90-
color = {255, 165, 0},
91-
multiline = true,
92-
args = {"[Admin]", targetName .. " was kicked by " .. adminName .. " - Reason: " .. reason}
93-
})
94-
else
83+
local adminName = GetPlayerName(src) or "Console"
84+
if src ~= 0 and not IsPlayerAceAllowed(src, "vmenu.ban") then
9585
TriggerClientEvent('chat:addMessage', src, {
9686
color = {255, 0, 0},
9787
multiline = true,
98-
args = {"[Error]", "Player not found"}
88+
args = {"[Error]", "You do not have permission to use this command."}
9989
})
90+
return
91+
end
92+
if GetPlayerPing(targetId) > 0 then
93+
local targetName = GetPlayerName(targetId)
94+
DropPlayer(targetId, "Kicked by " .. adminName .. " - Reason: " .. reason)
95+
else
10096
end
10197
end)
10298

99+
103100
RegisterNetEvent("vMenu:banPlayer")
104101
AddEventHandler("vMenu:banPlayer", function(targetId, reason)
105102
local src = source
106-
local adminName = GetPlayerName(src)
107-
108-
if GetPlayerPing(targetId) > 0 then -- Check if player exists
109-
local targetName = GetPlayerName(targetId)
110-
local identifier = GetPlayerIdentifier(targetId, 0)
111-
112-
-- You would typically save this to a database
113-
-- For now, just kick the player
114-
DropPlayer(targetId, "Banned by " .. adminName .. " - Reason: " .. reason)
115-
116-
TriggerClientEvent('chat:addMessage', -1, {
117-
color = {255, 0, 0},
118-
multiline = true,
119-
args = {"[Admin]", targetName .. " was banned by " .. adminName .. " - Reason: " .. reason}
120-
})
121-
else
103+
local adminName = GetPlayerName(src) or "Console"
104+
if src ~= 0 and not IsPlayerAceAllowed(src, "vmenu.ban") then
122105
TriggerClientEvent('chat:addMessage', src, {
123106
color = {255, 0, 0},
124107
multiline = true,
125-
args = {"[Error]", "Player not found"}
108+
args = {"[Error]", "You do not have permission to use this command."}
126109
})
110+
return
111+
end
112+
113+
if GetPlayerPing(targetId) > 0 then
114+
local targetName = GetPlayerName(targetId)
115+
local identifier = GetPlayerIdentifier(targetId, 0)
116+
117+
DropPlayer(targetId, "Banned by " .. adminName .. " - Reason: " .. reason)
118+
119+
120+
121+
print(("[sMenu] %s banned %s (%s) - Reason: %s"):format(adminName, targetName, identifier or "unknown", reason or "none"))
122+
else
123+
127124
end
128125
end)
129126

127+
130128
RegisterNetEvent("vMenu:teleportToPlayer")
131129
AddEventHandler("vMenu:teleportToPlayer", function(targetId)
132130
local src = source
133131

134-
if GetPlayerPing(targetId) > 0 then -- Check if player exists
132+
if GetPlayerPing(targetId) > 0 then
135133
local targetPed = GetPlayerPed(targetId)
136134
local targetCoords = GetEntityCoords(targetPed)
137135

0 commit comments

Comments
 (0)