更改绑定骨骼位置为右腿骨骼
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, 64729) -- 获取骨骼索引
-- 附加物体时调整位置到脚旁边
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, 64729)
-- 附加物体时调整位置到脚旁边
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)
要将绑定的骨骼位置更改为右腿骨骼,您需要找到正确的骨骼索引。右腿通常对应于 `GetPedBoneIndex(ped, 64524)`。在代码中进行适当的修改。以下是更新后的代码:
RegisterNetEvent('phmodel:nvhaiwen')
AddEventHandler('phmodel:nvhaiwen', function ()
TriggerEvent(Config['Event']) -- 触发配置事件
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)
### 修改说明:
1. 将 `local boneIndex = GetPedBoneIndex(ped, 64729)` 更改为 `local boneIndex = GetPedBoneIndex(ped, 64524)`,以便使用右腿的骨骼索引。
2. 其他部分保持不变,以确保功能正常。
这段代码应该放在 `client.lua` 文件中,因为它涉及到与玩家的客户端交互和对象的创建与附加。 使饰品在右腿旁而不是在腿上 15604402 发表于 2025-02-27 03:38
使饰品在右腿旁而不是在腿上
要使饰品在右腿旁,而不是直接附加在腿上,您需要调整附加物体时的位置偏移值(即 `AttachEntityToEntity` 方法中的偏移参数)。以下是更新后的代码:
RegisterNetEvent('phmodel:nvhaiwen')
AddEventHandler('phmodel:nvhaiwen', function ()
TriggerEvent(Config['Event']) -- 触发配置事件
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.3, 0.0, -0.1, 0.0, 180.0, 0.0, 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.3, 0.0, -0.1, 0.0, 180.0, 0.0, true, true, false, true, 1, true)
ClearPedTasks(ped)
wheel = false
DetachEntity(prop, ped, boneIndex, 0.10, 0.01, 0.00, 0.0, 180.00, 0.0, true, true, false, true, 1, true)
DeleteObject(prop)
end
end)
### 修改说明:
1. 在 `AttachEntityToEntity` 函数中,将偏移值调整为 `(0.3, 0.0, -0.1)`。其中:
- `0.3` 是横向偏移(向右),可以根据需要调整;
- `0.0` 是前后偏移;
- `-0.1` 是上下偏移,这里设为负值将饰品放置在腿的下方,可以根据需要进行微调。
这段代码依然应放在 `client.lua` 文件中,以保持与客户端相关的操作。 饰品倒立了,使其翻转过来 15604402 发表于 2025-02-27 03:40
饰品倒立了,使其翻转过来
要使饰品翻转过来,您需要在 `AttachEntityToEntity` 方法中的旋转参数进行调整。具体是通过更改旋转的角度,使其朝向正确的方向。以下是更新后的代码:
RegisterNetEvent('phmodel:nvhaiwen')
AddEventHandler('phmodel:nvhaiwen', function ()
TriggerEvent(Config) -- 触发配置事件
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.3, 0.0, -0.1, 0.0, 0.0, 180.0, 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.3, 0.0, -0.1, 0.0, 0.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, 0.0, 180.0, true, true, false, true, 1, true)
DeleteObject(prop)
end
end)
### 修改说明:
1. 在 `AttachEntityToEntity` 函数的旋转参数中,您可以调整最后三个参数(即 `0.0, 0.0, 180.0`),其中:
- 第一个参数(俯仰)为 `0.0`;
- 第二个参数(偏航)为 `0.0`;
- 第三个参数(滚转)为 `180.0`,用于将物体旋转180度,使其翻转过来。
此代码依然应放在 `client.lua` 文件中,以保持与客户端相关操作的统一。您可以根据实际效果进一步微调旋转角度以实现最佳效果。
页:
[1]