Files
qb-core/server/commands.lua
T
2021-04-08 19:11:32 -05:00

162 lines
7.3 KiB
Lua

QBCore.Commands = {}
QBCore.Commands.List = {}
QBCore.Commands.Add = function(name, help, arguments, argsrequired, callback, permission) -- [name] = command name (ex. /givemoney), [help] = help text, [arguments] = arguments that need to be passed (ex. {{name="id", help="ID of a player"}, {name="amount", help="amount of money"}}), [argsrequired] = set arguments required (true or false), [callback] = function(source, args) callback, [permission] = rank or job of a player
QBCore.Commands.List[name:lower()] = {
name = name:lower(),
permission = permission ~= nil and permission:lower() or "user",
help = help,
arguments = arguments,
argsrequired = argsrequired,
callback = callback,
}
end
QBCore.Commands.Refresh = function(source)
local Player = QBCore.Functions.GetPlayer(tonumber(source))
if Player ~= nil then
for command, info in pairs(QBCore.Commands.List) do
if QBCore.Functions.HasPermission(source, "god") or QBCore.Functions.HasPermission(source, QBCore.Commands.List[command].permission) then
TriggerClientEvent('chat:addSuggestion', source, "/"..command, info.help, info.arguments)
end
end
end
end
QBCore.Commands.Add("tp", "Teleport to a player or location", {{name="id/x", help="ID of player or X position"}, {name="y", help="Y position"}, {name="z", help="Z position"}}, false, function(source, args)
if (args[1] ~= nil and (args[2] == nil and args[3] == nil)) then
-- tp to player
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
TriggerClientEvent('QBCore:Command:TeleportToPlayer', source, Player.PlayerData.source)
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
else
-- tp to location
if args[1] ~= nil and args[2] ~= nil and args[3] ~= nil then
local x = tonumber(args[1])
local y = tonumber(args[2])
local z = tonumber(args[3])
TriggerClientEvent('QBCore:Command:TeleportToCoords', source, x, y, z)
else
TriggerClientEvent('QBCore:Notify', source, "Not every argument has been entered (x, y, z)", "error")
end
end
end, "admin")
QBCore.Commands.Add("addpermission", "Grant permissions to someone (god/admin)", {{name="id", help="ID of player"}, {name="permission", help="Permission level"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
local permission = tostring(args[2]):lower()
if Player ~= nil then
QBCore.Functions.AddPermission(Player.PlayerData.source, permission)
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "god")
QBCore.Commands.Add("removepermission", "Remove permissions from someone", {{name="id", help="ID of player"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
QBCore.Functions.RemovePermission(Player.PlayerData.source)
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "god")
QBCore.Commands.Add("sv", "Spawn a vehicle", {{name="model", help="Model name of the vehicle"}}, true, function(source, args)
TriggerClientEvent('QBCore:Command:SpawnVehicle', source, args[1])
end, "admin")
QBCore.Commands.Add("debug", "Turn debug mode on / off", {}, false, function(source, args)
TriggerClientEvent('koil-debug:toggle', source)
end, "admin")
QBCore.Commands.Add("dv", "Despawn a vehicle", {}, false, function(source, args)
TriggerClientEvent('QBCore:Command:DeleteVehicle', source)
end, "admin")
QBCore.Commands.Add("tpm", "Teleport to your waypoint", {}, false, function(source, args)
TriggerClientEvent('QBCore:Command:GoToMarker', source)
end, "admin")
QBCore.Commands.Add("givemoney", "Give money to a player", {{name="id", help="Player ID"},{name="moneytype", help="Type of money (cash, bank, crypto)"}, {name="amount", help="Amount of money"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
Player.Functions.AddMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "admin")
QBCore.Commands.Add("setmoney", "set a players money amount", {{name="id", help="Player ID"},{name="moneytype", help="Type of money (cash, bank, crypto)"}, {name="amount", help="Amount of money"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
Player.Functions.SetMoney(tostring(args[2]), tonumber(args[3]))
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "admin")
QBCore.Commands.Add("setjob", "Assign a job to a player", {{name="id", help="Speler ID"}, {name="job", help="Job name"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
Player.Functions.SetJob(tostring(args[2]))
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "admin")
QBCore.Commands.Add("job", "See what job you have", {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
TriggerClientEvent('QBCore:Notify', source, "Job: "..Player.PlayerData.job.label)
end)
QBCore.Commands.Add("setgang", "Assign a player to a gang", {{name="id", help="Player ID"}, {name="job", help="Name of a gang"}}, true, function(source, args)
local Player = QBCore.Functions.GetPlayer(tonumber(args[1]))
if Player ~= nil then
Player.Functions.SetGang(tostring(args[2]))
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "admin")
QBCore.Commands.Add("gang", "See what gang you're in", {}, false, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)
if Player.PlayerData.gang.name ~= "geen" then
TriggerClientEvent('QBCore:Notify', source, "Gang: "..Player.PlayerData.gang.label)
else
TriggerClientEvent('QBCore:Notify', source, "You're not in a gang!", "error")
end
end)
QBCore.Commands.Add("testnotify", "test notify", {{name="text", help="Tekst enzo"}}, true, function(source, args)
TriggerClientEvent('QBCore:Notify', source, table.concat(args, " "), "success")
end, "god")
QBCore.Commands.Add("clearinv", "Clear the inventory of a player", {{name="id", help="Player ID"}}, false, function(source, args)
local playerId = args[1] ~= nil and args[1] or source
local Player = QBCore.Functions.GetPlayer(tonumber(playerId))
if Player ~= nil then
Player.Functions.ClearInventory()
else
TriggerClientEvent('QBCore:Notify', source, "Player is not online!", "error")
end
end, "admin")
QBCore.Commands.Add("ooc", "Out of Character message", {}, false, function(source, args)
local message = table.concat(args, " ")
TriggerClientEvent("QBCore:Client:LocalOutOfCharacter", -1, source, GetPlayerName(source), message)
local Players = QBCore.Functions.GetPlayers()
local Player = QBCore.Functions.GetPlayer(source)
for k, v in pairs(QBCore.Functions.GetPlayers()) do
if QBCore.Functions.HasPermission(v, "admin") then
if QBCore.Functions.IsOptin(v) then
TriggerClientEvent('chatMessage', v, "OOC " .. GetPlayerName(source), "normal", message)
TriggerEvent("qb-log:server:CreateLog", "ooc", "OOC", "white", "**"..GetPlayerName(source).."** (CitizenID: "..Player.PlayerData.citizenid.." | ID: "..source..") **Message:** " ..message, false)
end
end
end
end)