Skip to content

Commit

Permalink
feat(server/comands): claim veh command
Browse files Browse the repository at this point in the history
  • Loading branch information
Andyyy7666 committed Jan 18, 2025
1 parent fe922e1 commit 9d4708f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
16 changes: 14 additions & 2 deletions client/vehicle/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,9 @@ AddStateBagChangeHandler("locked", nil, function(bagName, key, value, reserved,
end)
end)

lib.callback.register("ND_Vehicles:getProps", function(netId)
local veh = getVehFromNetId(netId)
local function getProps(veh)
if not veh or not DoesEntityExist(veh) then return end

local props = lib.getVehicleProperties(veh)
local colorPrimary, colorSecondary = GetVehicleColours(veh)
if not props then return end
Expand All @@ -368,7 +369,18 @@ lib.callback.register("ND_Vehicles:getProps", function(netId)
props.className = vehicleClassNames[GetVehicleClass(veh)]
props.makeName = GetLabelText(GetMakeNameFromVehicleModel(props.model))
props.modelName = GetLabelText(GetDisplayNameFromVehicleModel(props.model))

return props
end

lib.callback.register("ND_Vehicles:getProps", function(netId)
local veh = getVehFromNetId(netId)
return getProps(veh)
end)

lib.callback.register("ND_Vehicles:getPropsFromCurrentVeh", function()
local veh = GetVehiclePedIsIn(cache.ped)
return getProps(veh)
end)

lib.callback.register("ND_Vehicles:getVehicleModelMakeLabel", function(model)
Expand Down
42 changes: 42 additions & 0 deletions server/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,45 @@ lib.addCommand("vehicle", {
Wait(100)
end
end)

lib.addCommand("claim-veh", {
help = "Admin command, add a copy of the vehicle you're inside to players garage.",
restricted = "group.admin",
params = {
{
name = "target",
type = "playerId",
help = "Target player's server id"
}
}
}, function(source, args, raw)
local player = NDCore.getPlayer(source)
if not player then return end

local targetPlayer = NDCore.getPlayer(args.target)
if not targetPlayer then
return player.notify({
title = "Player not found!",
description = "Target player not found, make sure they select a charcter!",
type = "error"
})
end


local properties = lib.callback.await("ND_Vehicles:getPropsFromCurrentVeh", source)
if not properties then
return player.notify({
title = "Vehicle data not found!",
description = "The vehicle properties data was not found!",
type = "error"
})
end

NDCore.setVehicleOwned(targetPlayer.id, properties, true)

player.notify({
title = "Vehicle added!",
description = ("The vehicle has now been added to %s's garage!"):format(targetPlayer.name),
type = "success"
})
end)

0 comments on commit 9d4708f

Please sign in to comment.