forked from Simnation/Main
87 lines
3.1 KiB
Lua
87 lines
3.1 KiB
Lua
![]() |
local QBCore = exports['qb-core']:GetCoreObject()
|
||
|
|
||
|
local function GetIdentifier(src)
|
||
|
local Player = QBCore.Functions.GetPlayer(src)
|
||
|
if not Player then return nil end
|
||
|
return Player.PlayerData[Config.UseIdentifier]
|
||
|
end
|
||
|
|
||
|
local function HasPermission(src)
|
||
|
local player = QBCore.Functions.GetPlayer(src)
|
||
|
if not player then return false end
|
||
|
local perms = Config.AllowedAdmins
|
||
|
return perms[player.PlayerData.group] ~= nil or IsPlayerAceAllowed(src, "command")
|
||
|
end
|
||
|
|
||
|
-- /ped
|
||
|
RegisterCommand("ped", function(source, args)
|
||
|
--if not HasPermission(source) then return end
|
||
|
local target = QBCore.Functions.GetPlayer(args[1]) --args[1]
|
||
|
local pedName = args[2]
|
||
|
if not target or not pedName then return end
|
||
|
|
||
|
if target == nil then return end
|
||
|
|
||
|
TriggerClientEvent("pyrion:client:SetPed", targetId, pedName)
|
||
|
end)
|
||
|
|
||
|
-- /pedBack
|
||
|
RegisterCommand("pedBack", function(source, args)
|
||
|
if not HasPermission(source) then return end
|
||
|
local target = args[1]
|
||
|
local targetId = target == "me" and source or tonumber(target)
|
||
|
TriggerClientEvent("pyrion:client:ResetPed", targetId)
|
||
|
end)
|
||
|
|
||
|
-- /pedGive
|
||
|
RegisterCommand("pedGive", function(source, args)
|
||
|
if not HasPermission(source) then return end
|
||
|
local target = args[1]
|
||
|
local pedName = args[2]
|
||
|
if not pedName then return end
|
||
|
|
||
|
local targetId = target == "me" and source or tonumber(target)
|
||
|
local identifier = GetIdentifier(targetId)
|
||
|
|
||
|
MySQL.query.await("REPLACE INTO player_peds (identifier, ped) VALUES (?, ?)", {identifier, pedName})
|
||
|
Config.Notification(source, "Ped gespeichert in der Datenbank!", "success")
|
||
|
TriggerClientEvent("pyrion:client:SetPed", targetId, pedName)
|
||
|
end)
|
||
|
|
||
|
-- /pedUpdate
|
||
|
RegisterCommand("pedUpdate", function(source, args)
|
||
|
if not HasPermission(source) then return end
|
||
|
local target = args[1]
|
||
|
local pedName = args[2]
|
||
|
if not pedName then return end
|
||
|
|
||
|
local targetId = target == "me" and source or tonumber(target)
|
||
|
local identifier = GetIdentifier(targetId)
|
||
|
|
||
|
MySQL.query.await("UPDATE player_peds SET ped = ? WHERE identifier = ?", {pedName, identifier})
|
||
|
Config.Notification(source, "Ped aktualisiert!", "primary")
|
||
|
end)
|
||
|
|
||
|
-- /pedDelete
|
||
|
RegisterCommand("pedDelete", function(source, args)
|
||
|
if not HasPermission(source) then return end
|
||
|
local target = args[1]
|
||
|
local targetId = target == "me" and source or tonumber(target)
|
||
|
local identifier = GetIdentifier(targetId)
|
||
|
|
||
|
MySQL.query.await("DELETE FROM player_peds WHERE identifier = ?", {identifier})
|
||
|
Config.Notification(source, "Ped gelöscht!", "error")
|
||
|
TriggerClientEvent("pyrion:client:ResetPed", targetId)
|
||
|
end)
|
||
|
|
||
|
-- Laden beim Spawn
|
||
|
AddEventHandler('QBCore:Server:PlayerLoaded', function(player)
|
||
|
local src = player.source
|
||
|
local identifier = player.PlayerData[Config.UseIdentifier]
|
||
|
|
||
|
local result = MySQL.query.await("SELECT ped FROM player_peds WHERE identifier = ?", {identifier})
|
||
|
if result and result[1] then
|
||
|
TriggerClientEvent("pyrion:client:SetPed", src, result[1].ped)
|
||
|
end
|
||
|
end)
|