32 Commits

Author SHA1 Message Date
Andyyy7666
70a1487420 wip(compat/qb/server): basic functions 2024-03-09 19:07:30 +01:00
Andy
626f0ad06f Merge pull request #66 from ND-Framework/feat/custom-group-info
Feat/custom group info
2024-03-09 19:03:19 +01:00
Andyyy7666
d5c3acbd81 tweak(server/player): adding job group 2024-03-09 19:02:18 +01:00
Andyyy7666
98cba87bec feat(server/player): adding custom group info 2024-03-09 19:00:15 +01:00
Andyyy7666
001fc22ef6 fix: syntax error 2024-02-29 23:17:08 +01:00
Andy
87420e99e9 Merge pull request #65 from ND-Framework/feat/discord-groups
feat: receive groups by discord roles
2024-02-29 22:29:13 +01:00
Andyyy7666
c5597161d9 feat: receive groups by discord roles
Player can receive groups based on the discord roles they have, ace perms are also added when group is received.
2024-02-29 22:28:25 +01:00
Andyyy7666
898b9aefe9 feat(server/player): updatecharacter server event 2024-02-28 14:12:18 +01:00
Andyyy7666
5545650dd5 feat: impound non parked vehicles 2024-02-27 23:13:40 +01:00
Andy
f4f01a5b1c fix: config discord invinte 2024-02-27 20:43:15 +01:00
Andyyy7666
3252118f93 tweak: move clothing menu command to core 2024-02-25 23:54:10 +01:00
Andyyy7666
9d4708a1f8 tweak(server/player): save inventory when character created 2024-02-25 23:43:00 +01:00
Andyyy7666
d0d04ae282 tweak(death): damage event for ambulance 2024-02-17 23:57:42 +01:00
Andyyy7666
c005c1b28b tweak(client/death): player death checks 2024-02-12 23:28:18 +01:00
Andyyy7666
590044b5d6 refactor(client): revive function 2024-02-12 23:27:43 +01:00
Andyyy7666
3146172c0c fix: register unloaded event 2024-02-04 16:44:55 +01:00
Andy
2ce47ef8d1 Merge pull request #62 from ND-Framework/tweak/peds-clothing-command
tweak(client/peds): copying clothing
2024-01-30 14:38:25 +01:00
Andyyy7666
6258651d8b tweak(client/peds): copying clothing 2024-01-30 14:37:44 +01:00
Andy
eecbc8f690 Merge pull request #59 from Hakkodevelopment/patch-1
Fix: Command grammar/spelling mistakes/fluidity
2024-01-26 04:29:52 +01:00
Andyyy7666
1d25b54e0f tweak: notifiacitons 2024-01-26 04:16:24 +01:00
Hakko
e18389a52a Fix: Command grammar/spelling mistakes/fluidity 2024-01-21 21:06:51 -07:00
Andy
539e522373 Merge pull request #57 from ND-Framework/fix/driving-locked-vehicle
fix(client/vehicle): vehicle keys issues
2024-01-16 23:31:40 +01:00
Andyyy7666
2bacdd2a20 fix(client/vehicle): vehicle keys issues 2024-01-16 23:31:12 +01:00
Andy
6242a44c0b Merge pull request #53 from realCallMeJ/main
feat: config for requiring discord server membership
2024-01-16 20:59:48 +01:00
Andyyy7666
74e4ccc2de feat: police vehicle callsigns mod 2024-01-15 19:48:24 +01:00
Andyyy7666
2fda7655b5 feat(server/player): save only one column 2024-01-11 00:36:18 +01:00
CallMeJ
ade82436a5 feat: config for requiring discord server membership 2024-01-09 15:50:09 -10:00
Andyyy7666
f512d0ed0c Update fxmanifest.lua 2024-01-09 13:27:11 +01:00
Andyyy7666
0a19fe8a33 fix(client(vehicle): hide weapon while using key 2024-01-09 13:03:42 +01:00
Andyyy7666
2882c7c1ae tweak:(database/characters): phonenumber column 2024-01-07 21:25:44 +01:00
Andyyy7666
6291690bd4 feat(database/characters): phonenumber column 2024-01-07 21:14:30 +01:00
Andyyy7666
af82c447c1 feat(server/player): phonenumber player data 2024-01-07 21:13:56 +01:00
14 changed files with 308 additions and 123 deletions

View File

@@ -29,14 +29,13 @@ AddEventHandler("gameEventTriggered", function(name, args)
local victim = args[1]
if not IsPedAPlayer(victim) or NetworkGetPlayerIndexFromPed(victim) ~= cache.playerId then return end
if not IsPedDeadOrDying(victim, true) then
local hit, bone = GetPedLastDamageBone(victim)
if hit and usingAmbulance then
local damageWeapon = ambulance:getLastDamagingWeapon(victim)
return damageWeapon and ambulance:updateBodyDamage(bone, damageWeapon)
end
return
local hit, bone = GetPedLastDamageBone(victim)
if hit and usingAmbulance then
local damageWeapon = ambulance:getLastDamagingWeapon(victim)
ambulance:updateBodyDamage(bone, damageWeapon)
end
if not IsPedDeadOrDying(victim, true) or GetEntityHealth(victim) > 100 then return end
local killerEntity, deathCause = GetPedSourceOfDeath(cache.ped), GetPedCauseOfDeath(cache.ped)
local killerClientId = NetworkGetPlayerIndexFromPed(killerEntity)

View File

@@ -22,5 +22,50 @@ RegisterNetEvent("ND:updateLastLocation", function(location)
end)
RegisterNetEvent("ND:revivePlayer", function()
NDCore.revivePlayer(true)
if source == "" then return end
local veh = GetVehiclePedIsIn(cache.ped)
local seat = cache.seat
local coords = GetEntityCoords(cache.ped)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, GetEntityHeading(cache.ped), true, true, false)
local ped = PlayerPedId()
if cache.ped ~= ped then
DeleteEntity(cache.ped)
ClearAreaOfPeds(coords.x, coords.y, coords.z, 0.2, false)
end
SetEntityInvincible(ped, false)
FreezeEntityPosition(ped, false)
SetEntityVisible(ped, true)
SetEveryoneIgnorePlayer(ped, false)
SetPedCanBeTargetted(ped, true)
SetEntityCanBeDamaged(ped, true)
SetBlockingOfNonTemporaryEvents(ped, false)
SetPedCanRagdollFromPlayerImpact(ped, true)
ClearPedTasksImmediately(ped)
if veh and veh ~= 0 then
SetPedIntoVehicle(ped, veh, seat)
end
end)
RegisterNetEvent("ND:characterUnloaded")
RegisterNetEvent("ND:clothingMenu", function()
if GetResourceState("fivem-appearance") ~= "started" then return end
local function customize(appearance)
if not appearance then return end
TriggerServerEvent("ND:updateClothing", appearance)
end
exports["fivem-appearance"]:startPlayerCustomization(customize, {
ped = false,
headBlend = true,
faceFeatures = true,
headOverlays = true,
components = true,
props = true,
tattoos = true
})
end)

View File

@@ -33,56 +33,8 @@ function NDCore.getConfig(info)
return Config[info]
end
function NDCore.revivePlayer(reset, keepDead)
local usingAmbulance = GetResourceState("ND_Ambulance") == "started"
if not keepDead then
LocalPlayer.state.dead = false
if usingAmbulance then
local state = Player(cache.serverId).state
state:set("isDead", false, true)
end
end
local veh = GetVehiclePedIsIn(cache.ped)
local seat = cache.seat
local coords = GetEntityCoords(cache.ped)
NetworkResurrectLocalPlayer(coords.x, coords.y, coords.z, GetEntityHeading(cache.ped), true, true, false)
local ped = PlayerPedId()
if cache.ped ~= ped then
DeleteEntity(cache.ped)
ClearAreaOfPeds(coords.x, coords.y, coords.z, 0.2, false)
end
SetEntityInvincible(ped, false)
FreezeEntityPosition(ped, false)
SetEntityVisible(ped, true)
SetEveryoneIgnorePlayer(ped, false)
SetPedCanBeTargetted(ped, true)
SetEntityCanBeDamaged(ped, true)
SetBlockingOfNonTemporaryEvents(ped, false)
SetPedCanRagdollFromPlayerImpact(ped, true)
ClearPedTasksImmediately(ped)
if veh and veh ~= 0 then
SetPedIntoVehicle(ped, veh, seat)
end
if reset and GetPedMovementClipset(ped) == `move_m@injured` then
ClearEntityLastDamageEntity(ped)
SetPedMoveRateOverride(ped, 1.0)
ResetPedMovementClipset(ped, 0)
end
if reset and usingAmbulance then
exports["ND_Ambulance"]:resetBodyDamage()
end
end
function NDCore.notify(...)
if GetResourceState("ModernHUD") == "started" then
exports["ModernHUD"]:notify(...)
elseif GetResourceState("ox_lib") == "started" then
lib.notify(...)
end
lib.notify(...)
end
for name, func in pairs(NDCore) do

View File

@@ -7,11 +7,12 @@ Config = {
discordAsset = GetConvar("core:discordAsset", "andyyy"),
discordAssetSmall = GetConvar("core:discordAssetSmall", "andyyy"),
discordActionText = GetConvar("core:discordActionText", "DISCORD"),
discordActionLink = GetConvar("discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
discordActionLink = GetConvar("core:discordActionLink", "https://discord.gg/Z9Mxu72zZ6"),
discordActionText2 = GetConvar("core:discordActionText2", "STORE"),
discordActionLink2 = GetConvar("core:discordActionLink2", "https://andyyy.tebex.io/category/fivem-scripts"),
randomUnlockedVehicleChance = GetConvarInt("core:randomUnlockedVehicleChance", 30),
disableVehicleAirControl = GetConvarInt("core:disableVehicleAirControl", 1) == 1,
randomUnlockedVehicleChance = GetConvarInt("core:randomUnlockedVehicleChance", 30),
requireKeys = GetConvarInt("core:requireKeys", 1) == 1,
useInventoryForKeys = GetConvarInt("core:useInventoryForKeys", 1) == 1,
groups = json.decode(GetConvar("core:groups", "[]")),
compatibility = json.decode(GetConvar("core:compatibility", "[]"))

View File

@@ -218,10 +218,10 @@ end)
RegisterCommand("getclothing", function(source, args, rawCommand)
local info = ""
for k, v in pairs(clothingComponents) do
info = ("%s\n%s = {\n drawable = %s,\n texture = %s\n},"):format(info, k, GetPedDrawableVariation(cache.ped, v), GetPedTextureVariation(cache.ped, v))
info = ("%s\n%s = { drawable = %s, texture = %s },"):format(info, k, GetPedDrawableVariation(cache.ped, v), GetPedTextureVariation(cache.ped, v))
end
for k, v in pairs(clothingProps) do
info = ("%s\n%s = {\n drawable = %s,\n texture = %s\n},"):format(info, k, GetPedPropIndex(cache.ped, v), GetPedPropTextureIndex(cache.ped, v))
info = ("%s\n%s = { drawable = %s, texture = %s },"):format(info, k, GetPedPropIndex(cache.ped, v), GetPedPropTextureIndex(cache.ped, v))
end
lib.setClipboard(info)
end, false)

View File

@@ -293,6 +293,7 @@ AddStateBagChangeHandler("props", nil, function(bagName, key, value, reserved, r
lib.setVehicleProperties(entity, props)
end)
local playingKey = 0
local function playKeyFob(veh)
local keyFob
local ped = cache.ped
@@ -300,12 +301,21 @@ local function playKeyFob(veh)
if #(coords-GetEntityCoords(veh)) > 25.0 then return end
if not playerVehicle then
playingKey += 1
SetPedCurrentWeaponVisible(ped, false, false)
ClearPedTasks(ped)
lib.requestAnimDict("anim@mp_player_intmenu@key_fob@")
TaskPlayAnim(ped, "anim@mp_player_intmenu@key_fob@", "fob_click_fp", 8.0, 8.0, -1, 48, 1, false, false, false)
keyFob = CreateObject(`lr_prop_carkey_fob`, 0, 0, 0, true, true, true)
AttachEntityToEntity(keyFob, ped, GetPedBoneIndex(ped, 0xDEAD), 0.12, 0.04, -0.025, -100.0, 100.0, 0.0, true, true, false, true, 1, true)
Wait(700)
SetTimeout(400, function()
playingKey -= 1
end)
SetTimeout(1200, function()
if playingKey > 0 then return end
SetPedCurrentWeaponVisible(ped, true, false)
end)
end
PlaySoundFromEntity(-1, "Remote_Control_Fob", ped, "PI_Menu_Sounds", true, 0)
@@ -470,22 +480,35 @@ CreateThread(function()
local wait = 500
while true do
Wait(wait)
local reset = true
playerVehicle = cache.seat == -1 and cache.vehicle
if playerVehicle then
if Config.disableVehicleAirControl and not vehicleClassNotDisableAirControl[GetVehicleClass(playerVehicle)] and (IsEntityInAir(playerVehicle) or IsEntityUpsidedown(playerVehicle)) then
wait = 0
DisableControlAction(0, 59) -- disable vehicle air control.
DisableControlAction(0, 60)
elseif not GetIsVehicleEngineRunning(playerVehicle) and not hasVehicleKeysCheck(playerVehicle) then
wait = 0
DisableControlAction(0, 59)
if DoesEntityExist(playerVehicle) and IsVehicleEngineStarting(playerVehicle) then
SetVehicleEngineOn(playerVehicle, false, true, true) -- don't turn on engine if no keys.
end
else
wait = 500
local entering = GetVehiclePedIsEntering(cache.ped)
if entering and DoesEntityExist(entering) and IsVehicleNeedsToBeHotwired(entering) then
SetVehicleNeedsToBeHotwired(entering, false)
end
if not playerVehicle then goto skip end
if Config.disableVehicleAirControl and not vehicleClassNotDisableAirControl[GetVehicleClass(playerVehicle)] and (IsEntityInAir(playerVehicle) or IsEntityUpsidedown(playerVehicle)) then
wait = 0
reset = false
DisableControlAction(0, 59) -- disable vehicle air control.
DisableControlAction(0, 60)
end
if Config.requireKeys and not GetIsVehicleEngineRunning(playerVehicle) and not hasVehicleKeysCheck(playerVehicle) then
wait = 0
reset = false
DisableControlAction(0, 59)
DisableControlAction(0, 71)
if DoesEntityExist(playerVehicle) and IsVehicleEngineStarting(playerVehicle) then
SetVehicleEngineOn(playerVehicle, false, true, true) -- don't turn on engine if no keys.
end
elseif wait ~= 500 then
end
::skip::
if (reset or not playerVehicle) and wait ~= 500 then
wait = 500
end
end

View File

@@ -1 +1,73 @@
if not lib.table.contains(Config.compatibility, "qb") then return end
local QBCore = {}
QBCore.Config = QBConfig
QBCore.Shared = QBShared
QBCore.ClientCallbacks = {}
QBCore.ServerCallbacks = {}
QBCore.Players = {}
QBCore.Functions = {}
QBCore.Player_Buckets = {}
QBCore.Entity_Buckets = {}
QBCore.UsableItems = {}
function QBCore.Functions.GetCoords(entity)
local coords = GetEntityCoords(entity)
local heading = GetEntityHeading(entity)
return vec4(coords.x, coords.y, coords.z, heading)
end
function QBCore.Functions.GetIdentifier(source, idtype)
if GetConvarInt("sv_fxdkMode", 0) == 1 then return "license:fxdk" end
return GetPlayerIdentifierByType(source, idtype or "license")
end
function QBCore.Functions.GetSource(identifier)
for src, _ in pairs(NDCore.players) do
local idens = GetPlayerIdentifiers(src)
for _, id in pairs(idens) do
if identifier == id then
return src
end
end
end
return 0
end
local function createPlayer(player)
end
function QBCore.Functions.GetPlayer(source)
if type(source) == "number" then
return createPlayer(NDCore.players[source])
else
return createPlayer(NDCore.players[QBCore.Functions.GetSource(source)])
end
end
function QBCore.Functions.GetPlayerByCitizenId(citizenid)
for src in pairs(NDCore.players) do
if NDCore.players[src].id == citizenid then
return NDCore.players[src]
end
end
end
-- function QBCore.Functions.GetOfflinePlayerByCitizenId(citizenid)
-- return QBCore.Player.GetOfflinePlayer(citizenid)
-- end
-- function QBCore.Functions.GetPlayerByLicense(license)
-- return QBCore.Player.GetPlayerByLicense(license)
-- end
function QBCore.Functions.GetPlayerByPhone(number)
for src in pairs(NDCore.players) do
if NDCore.players[src].phonenumber == number then
return createPlayer(NDCore.players[src])
end
end
end

View File

@@ -1,15 +1,16 @@
CREATE TABLE IF NOT EXISTS `nd_characters` (
`charid` INT(10) NOT NULL AUTO_INCREMENT,
`identifier` VARCHAR(200) NOT NULL DEFAULT '0',
`name` VARCHAR(50) DEFAULT NULL,
`firstname` VARCHAR(50) DEFAULT NULL,
`lastname` VARCHAR(50) DEFAULT NULL,
`dob` VARCHAR(50) DEFAULT NULL,
`gender` VARCHAR(50) DEFAULT NULL,
`cash` INT(10) DEFAULT '0',
`bank` INT(10) DEFAULT '0',
`groups` LONGTEXT DEFAULT ('[]'),
`metadata` LONGTEXT DEFAULT ('[]'),
`inventory` LONGTEXT DEFAULT ('[]'),
PRIMARY KEY (`charid`) USING BTREE
`charid` INT(10) NOT NULL AUTO_INCREMENT,
`identifier` VARCHAR(200) NOT NULL DEFAULT '0',
`name` VARCHAR(50) DEFAULT NULL,
`firstname` VARCHAR(50) DEFAULT NULL,
`lastname` VARCHAR(50) DEFAULT NULL,
`dob` VARCHAR(50) DEFAULT NULL,
`gender` VARCHAR(50) DEFAULT NULL,
`cash` INT(10) DEFAULT '0',
`bank` INT(10) DEFAULT '0',
`phonenumber` VARCHAR(20) DEFAULT NULL,
`groups` LONGTEXT DEFAULT ('[]'),
`metadata` LONGTEXT DEFAULT ('[]'),
`inventory` LONGTEXT DEFAULT ('[]'),
PRIMARY KEY (`charid`) USING BTREE
);

View File

@@ -1,15 +1,15 @@
CREATE TABLE IF NOT EXISTS `nd_vehicles` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`owner` INT(11) DEFAULT NULL,
`plate` VARCHAR(255) DEFAULT NULL,
`glovebox` LONGTEXT DEFAULT ('[]'),
`trunk` LONGTEXT DEFAULT ('[]'),
`properties` LONGTEXT DEFAULT ('[]'),
`id` INT(11) NOT NULL AUTO_INCREMENT,
`owner` INT(11) DEFAULT NULL,
`plate` VARCHAR(255) DEFAULT NULL,
`glovebox` LONGTEXT DEFAULT ('[]'),
`trunk` LONGTEXT DEFAULT ('[]'),
`properties` LONGTEXT DEFAULT ('[]'),
`stored` INT(11) DEFAULT '1',
`impounded` INT(11) DEFAULT '0',
`stolen` INT(11) DEFAULT '0',
`impounded` INT(11) DEFAULT '0',
`stolen` INT(11) DEFAULT '0',
`metadata` LONGTEXT DEFAULT ('[]'),
PRIMARY KEY (`id`) USING BTREE,
INDEX `owner` (`owner`) USING BTREE,
CONSTRAINT `vehowner` FOREIGN KEY (`owner`) REFERENCES `nd_characters` (`charid`) ON UPDATE CASCADE ON DELETE CASCADE
PRIMARY KEY (`id`) USING BTREE,
INDEX `owner` (`owner`) USING BTREE,
CONSTRAINT `vehowner` FOREIGN KEY (`owner`) REFERENCES `nd_characters` (`charid`) ON UPDATE CASCADE ON DELETE CASCADE
);

View File

@@ -2,7 +2,7 @@
author "Andyyy#7666"
description "ND Framework Core"
version "2.0.2"
version "2.1.2"
fx_version "cerulean"
game "gta5"

View File

@@ -262,7 +262,7 @@ lib.addCommand("pay", {
end)
lib.addCommand("unlock", {
help = "Admin force unlock vehicles",
help = "Admin Command, force unlock vehicle.",
restricted = "group.admin",
}, function(source, args, raw)
local ped = GetPlayerPed(source)
@@ -309,13 +309,13 @@ lib.addCommand("revive", {
end)
lib.addCommand("dv", {
help = "Admin command, delete vehicles within the range.",
help = "Admin command, delete vehicles within the range or the closest.",
restricted = "group.admin",
params = {
{
name = "range",
type = "number",
help = "The range to select vehicles for deleteion from",
help = "Range to delete vehicles in",
optional = true
}
}

View File

@@ -7,6 +7,7 @@ local tempPlayersInfo = {}
Config = {
serverName = GetConvar("core:serverName", "Unconfigured ND-Core Server"),
discordInvite = GetConvar("core:discordInvite", "https://discord.gg/Z9Mxu72zZ6"),
discordMemeberRequired = GetConvarInt("core:discordMemeberRequired", 1) == 1,
discordAppId = GetConvar("core:discordAppId", "858146067018416128"),
discordAsset = GetConvar("core:discordAsset", "andyyy"),
discordAssetSmall = GetConvar("core:discordAssetSmall", "andyyy"),
@@ -23,6 +24,7 @@ Config = {
groups = json.decode(GetConvar("core:groups", "[]")),
admins = json.decode(GetConvar("core:admins", "[]")),
adminDiscordRoles = json.decode(GetConvar("core:adminDiscordRoles", "[]")),
groupRoles = json.decode(GetConvar("core:groupRoles", "[]")),
multiCharacter = false,
compatibility = json.decode(GetConvar("core:compatibility", "[]"))
}
@@ -101,7 +103,7 @@ AddEventHandler("playerConnecting", function(name, setKickReason, deferrals)
if mainIdentifier and Config.discordBotToken ~= "false" and Config.discordGuildId ~= "false" then
discordInfo = checkDiscordIdentifier(identifiers)
if not discordInfo then
if not discordInfo and Config.discordMemeberRequired then
deferrals.done(("Your discord was not found, join our discord here: %s."):format(Config.discordInvite))
Wait(0)
end
@@ -153,3 +155,10 @@ RegisterNetEvent("ND:playerEliminated", function(info)
deathInfo = info
})
end)
RegisterNetEvent("ND::updateClothing", function(clothing)
local src = source
local player = NDCore.getPlayer(src)
if not player or not clothing or type(clothing) ~= "table" then return end
player.setMetadata("clothing", clothing)
end)

View File

@@ -25,6 +25,7 @@ local function createCharacterTable(info)
gender = info.gender,
cash = info.cash,
bank = info.bank,
phonenumber = info.phonenumber,
groups = info.groups,
metadata = info.metadata,
inventory = info.inventory
@@ -113,6 +114,7 @@ local function createCharacterTable(info)
end
end
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
end
---@param key string|table
@@ -127,6 +129,7 @@ local function createCharacterTable(info)
self.metadata[key] = value
end
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
return self.metadata
end
@@ -164,8 +167,23 @@ local function createCharacterTable(info)
end
-- Save character information to database
function self.save()
local affectedRows = MySQL.update.await("UPDATE nd_characters SET name = ?, firstname = ?, lastname = ?, dob = ?, gender = ?, cash = ?, bank = ?, `groups` = ?, metadata = ? WHERE charid = ?", {
function self.save(key)
if key then
local charData = self[key]
if not charData or type(charData) == "function" then
return lib.print.error(key, "Is not valid character data.")
end
if type(charData) == "table" then
charData = json.encode(charData)
end
local query = ("UPDATE nd_characters SET `%s` = ? WHERE charid = ?"):format(key)
local affectedRows = MySQL.update.await(query, {charData, self.id})
return affectedRows > 0
end
local affectedRows = MySQL.update.await("UPDATE nd_characters SET name = ?, firstname = ?, lastname = ?, dob = ?, gender = ?, cash = ?, bank = ?, phonenumber = ?, `groups` = ?, metadata = ? WHERE charid = ?", {
self.name,
self.firstname,
self.lastname,
@@ -173,6 +191,7 @@ local function createCharacterTable(info)
self.gender,
self.cash,
self.bank,
self.phonenumber,
json.encode(self.groups),
json.encode(self.metadata),
self.id
@@ -207,6 +226,7 @@ local function createCharacterTable(info)
self.metadata.licenses = {license}
end
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
end
function self.getLicense(identifier)
@@ -252,11 +272,7 @@ local function createCharacterTable(info)
function self.notify(...)
if not self.source then return end
if GetResourceState("ModernHUD") == "started" then
TriggerClientEvent("ModernHUD:notify", self.source, ...)
elseif GetResourceState("ox_lib") == "started" then
TriggerClientEvent("ox_lib:notify", self.source, ...)
end
TriggerClientEvent("ox_lib:notify", self.source, ...)
return true
end
@@ -293,6 +309,12 @@ local function createCharacterTable(info)
self.addGroup("admin")
end
end
for group, role in pairs(Config.groupRoles) do
if lib.table.contains(roles, role) then
self.addGroup(group)
end
end
end
for name, _ in pairs(self.groups) do
@@ -307,10 +329,10 @@ local function createCharacterTable(info)
---@param rank number
---@param isJob boolean
---@return boolean
function self.addGroup(name, rank, isJob)
function self.addGroup(name, rank, info, isJob)
local groupRank = tonumber(rank) or 1
local groupInfo = Config.groups?[name]
local bossRank = groupInfo and groupInfo.minimumBossRank
local groupInfo = info or Config.groups?[name]
local bossRank = groupInfo?.minimumBossRank
-- if not groupInfo then return end
if isJob then
@@ -321,8 +343,8 @@ local function createCharacterTable(info)
self.groups[name] = {
name = name,
label = groupInfo and groupInfo.label or name,
rankName = groupInfo and groupInfo.ranks[groupRank] or groupRank,
label = groupInfo?.label or name,
rankName = groupInfo?.ranks?[groupRank] or groupRank,
rank = groupRank,
isJob = isJob,
isBoss = bossRank and groupRank >= bossRank
@@ -330,8 +352,11 @@ local function createCharacterTable(info)
if not isJob then
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
end
lib.addPrincipal(self.source, ("group.%s"):format(name))
return self.groups[name]
end
@@ -353,6 +378,7 @@ local function createCharacterTable(info)
self.groups[name] = nil
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
lib.removePrincipal(self.source, ("group.%s"):format(name))
return group
end
@@ -362,12 +388,13 @@ local function createCharacterTable(info)
---@return boolean
function self.setJob(name, rank)
self.removeGroup(self.job)
local job = self.addGroup(name, rank, true)
local job = self.addGroup(name, rank, nil, true)
if job then
self.job = job.name
self.jobInfo = job
end
self.triggerEvent("ND:updateCharacter", removeCharacterFunctions(self))
TriggerEvent("ND:updateCharacter", self)
return job
end
@@ -407,12 +434,13 @@ function NDCore.newCharacter(src, info)
gender = info.gender or "",
cash = info.cash or 0,
bank = info.bank or 0,
phonenumber = info.phonenumber,
groups = info.groups or {},
metadata = info.metadata or {},
inventory = info.inventory or {},
inventory = info.inventory or {}
}
charInfo.id = MySQL.insert.await("INSERT INTO nd_characters (identifier, name, firstname, lastname, dob, gender, cash, bank, `groups`, metadata) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {
charInfo.id = MySQL.insert.await("INSERT INTO nd_characters (identifier, name, firstname, lastname, dob, gender, cash, bank, phonenumber, `groups`, metadata, inventory) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {
identifier,
charInfo.name,
charInfo.firstname,
@@ -421,8 +449,10 @@ function NDCore.newCharacter(src, info)
charInfo.gender,
charInfo.cash,
charInfo.bank,
charInfo.phonenumber,
json.encode(charInfo.groups),
json.encode(charInfo.metadata)
json.encode(charInfo.metadata),
json.encode(charInfo.inventory)
})
return createCharacterTable(charInfo)
@@ -451,6 +481,7 @@ function NDCore.fetchCharacter(id, src)
gender = info.gender,
cash = info.cash,
bank = info.bank,
phonenumber = info.phonenumber,
groups = json.decode(info.groups),
metadata = json.decode(info.metadata),
inventory = json.decode(info.inventory)
@@ -476,9 +507,10 @@ function NDCore.fetchAllCharacters(src)
gender = info.gender,
cash = info.cash,
bank = info.bank,
phonenumber = info.phonenumber,
groups = json.decode(info.groups),
metadata = json.decode(info.metadata),
inventory = json.decode(info.inventory),
inventory = json.decode(info.inventory)
})
end
return characters

View File

@@ -90,6 +90,9 @@ function NDCore.getVehicle(entity)
if saveProperties and self.id and self.owner then
local properties = lib.callback.await("ND_Vehicles:getProps", NetworkGetEntityOwner(entity), self.netId)
if properties then
if self.properties?.callsign then
properties.callsign = true
end
MySQL.query("UPDATE nd_vehicles SET properties = ? WHERE id = ?", {json.encode(properties), self.id})
end
end
@@ -102,6 +105,11 @@ function NDCore.getVehicle(entity)
if not DoesEntityExist(entity) then return end
local properties = type(props) == "string" and json.decode(props) or props
local state = Entity(entity).state
if self.properties?.callsign then
properties.callsign = true
end
state.props = properties
self.properties = properties
@@ -406,11 +414,27 @@ function NDCore.spawnOwnedVehicle(source, vehicleId, coords, heading)
if not vehicle or not vehicle.available or vehicle.owner ~= player.id then return end
MySQL.query.await("UPDATE nd_vehicles SET stored = ? WHERE id = ?", {0, vehicleId})
local properties = vehicle.properties
if properties.callsign then
local callsign = player.getMetadata("callsign")
if not callsign or callsign == "" then goto skip end
callsign = tostring(callsign)
if not callsign or callsign:len() ~= 3 then goto skip end
properties.modFender = tonumber(callsign:sub(1, 1))
properties.modRightFender = tonumber(callsign:sub(2, 2))
properties.modRoof = tonumber(callsign:sub(3, 3))
end
::skip::
return NDCore.createVehicle({
owner = player.id,
model = vehicle.properties.model,
model = properties.model,
coords = vec4(coords.x, coords.y, coords.z, coords.w or coords.heading or heading),
properties = vehicle.properties,
properties = properties,
vehicleId = vehicleId,
source = source
})
@@ -706,3 +730,30 @@ lib.callback.register("ND_Vehicles:getOwnedVehicles", function(src)
if not player then return end
return NDCore.getVehicles(player.id)
end)
AddEventHandler("ND:characterLoaded", function(player)
local ownedExistingVehicles = {}
local ownedVehicles = NDCore.getVehicles(player.id)
local vehicles = GetAllVehicles()
local vehiclesToImpound = {}
for i=1, #vehicles do
local veh = vehicles[i]
local state = Entity(veh).state
if state.owner == player.id then
ownedExistingVehicles[#ownedExistingVehicles+1] = state.id
end
end
for i=1, #ownedVehicles do
local veh = ownedVehicles[i]
if veh and not veh.stored and not veh.impounded and not lib.table.contains(ownedExistingVehicles, veh.id) then
vehiclesToImpound[#vehiclesToImpound+1] = veh.id
end
end
if #vehiclesToImpound == 0 then return end
local query = ("UPDATE nd_vehicles SET impounded = ? WHERE owner = ? AND id IN (%s)"):format(table.concat(vehiclesToImpound, ", "))
MySQL.rawExecute(query, {1, player.id})
end)