RegisterNetEvent('phmodel:nvhaiwen')
AddEventHandler('phmodel:nvhaiwen', function ()
TriggerEvent(Config['Event'][2]) -- 触发配置事件
if not wheel then
-- 进入创建物体流程
wheel = true
local ped = GetPlayerPed(-1) -- 获取玩家角色
local position = GetEntityCoords(ped, false) -- 获取玩家的位置
local object = GetClosestObjectOfType(position.x, position.y, position.z, 15.0, GetHashKey(Config.prop3), false, false, false)
if object ~= 0 then
DeleteObject(object) -- 删除附近的物体
end
local x, y, z = table.unpack(GetEntityCoords(ped)) -- 解包坐标
-- 在脚旁边生成物体,偏移值可以根据实际需要调整
local prop = CreateObject(GetHashKey(Config.prop3), x, y, z + 0.0, true, true, true)
local boneIndex = GetPedBoneIndex(ped, 64524) -- 更改为右腿骨骼索引
-- 附加物体时调整位置到右腿旁边
AttachEntityToEntity(prop, ped, boneIndex, 0.1, 0.0, -0.15, 0.0, 179.142, 193.120, true, true, false, true, 1, true)
else
-- 进入删除物体流程
local ped = GetPlayerPed(-1)
local position = GetEntityCoords(ped, false)
local object = GetClosestObjectOfType(position.x, position.y, position.z, 15.0, GetHashKey(Config.prop3), false, false, false)
if object ~= 0 then
DeleteObject(object)
end
local x, y, z = table.unpack(GetEntityCoords(ped))
local prop = CreateObject(GetHashKey(Config.prop3), x, y, z + 0.0, true, true, true)
local boneIndex = GetPedBoneIndex(ped, 64524) -- 更改为右腿骨骼索引
-- 附加物体时调整位置到右腿旁边
AttachEntityToEntity(prop, ped, boneIndex, 0.1, 0.0, -0.15, 0.0, 90.0, 180.0, true, true, false, true, 1, true)
ClearPedTasks(ped)
wheel = false
DetachEntity(prop, ped, boneIndex, 0.10, 0.01, 0.00, 0.0, 90.00, 180.0, true, true, false, true, 1, true)
DeleteObject(prop)
end
end)