-- 这个脚本会在玩家背后放置某些大型武器,当它们并未被选中但仍在武器轮中时。
-- 作者:minipunch
-- 最初为美国现实RP(https://usarrp.net)制作
-- 将武器添加到下面'comparable_weapon_hashes'表中,以使它们显示在玩家的背后(如果您不知道哈希,可以使用GetHashKey(...)) --
local SETTINGS = {
back_bone = 24816, -- 定义背部骨骼的索引
x = 0.075, -- x轴位置
y = -0.15, -- y轴位置
z = -0.02, -- z轴位置
x_rotation = 0.0, -- x轴旋转
y_rotation = 165.0, -- y轴旋转
z_rotation = 0.0, -- z轴旋转
compatable_weapon_hashes = { -- 兼容的武器哈希表
-- 近战武器:
-- = 1141786504, -- 位置仍需调整
["w_me_bat"] = -1786099057,
["prop_ld_jerrycan_01"] = 883325847,
-- 突击步枪:
["w_ar_carbinerifle"] = -2084633992,
["w_ar_carbineriflemk2"] = GetHashKey("WEAPON_CARBINERIFLE_MK2"),
["w_ar_assaultrifle"] = -1074790547,
["w_ar_specialcarbine"] = -1063057011,
["w_ar_bullpuprifle"] = 2132975508,
["w_ar_advancedrifle"] = -1357824103,
-- 冲锋枪:
["w_sb_microsmg"] = 324215364,
["w_sb_assaultsmg"] = -270015777,
["w_sb_smg"] = 736523883,
["w_sb_smgmk2"] = GetHashKey("WEAPON_SMG_MK2"),
["w_sb_gusenberg"] = 1627465347,
-- 狙击步枪:
["w_sr_sniperrifle"] = 100416529,
-- 猎枪:
["w_sg_assaultshotgun"] = -494615257,
["w_sg_bullpupshotgun"] = -1654528753,
["w_sg_pumpshotgun"] = 487013001,
["w_ar_musket"] = -1466123874,
["w_sg_heavyshotgun"] = GetHashKey("WEAPON_HEAVYSHOTGUN"),
-- = 2017895192 不显示,可能太小?
-- 发射器:
["w_lr_firework"] = 2138347493
}
}
local attached_weapons = {} -- 存储附加武器的表
Citizen.CreateThread(function() -- 创建一个新的线程
while true do
local me = GetPlayerPed(-1) -- 获取玩家角色
---------------------------------------
-- 如果玩家有大型武器则附加 --
---------------------------------------
for wep_name, wep_hash in pairs(SETTINGS.compatable_weapon_hashes) do
if HasPedGotWeapon(me, wep_hash, false) then -- 检查玩家是否拥有此武器
if not attached_weapons[wep_name] then -- 如果武器未附加
AttachWeapon(wep_name, wep_hash, SETTINGS.back_bone, SETTINGS.x, SETTINGS.y, SETTINGS.z, SETTINGS.x_rotation, SETTINGS.y_rotation, SETTINGS.z_rotation, isMeleeWeapon(wep_name))
end
end
end
--------------------------------------------
-- 如果装备/丢弃则从背上移除 --
--------------------------------------------
for name, attached_object in pairs(attached_weapons) do
-- 是否装备?从背后删除:
if GetSelectedPedWeapon(me) == attached_object.hash or not HasPedGotWeapon(me, attached_object.hash, false) then -- 已装备或不在武器轮中
DeleteObject(attached_object.handle) -- 删除对象
attached_weapons[name] = nil -- 从附加武器中移除
end
end
Wait(0) -- 等待下次执行
end
end)
function AttachWeapon(attachModel, modelHash, boneNumber, x, y, z, xR, yR, zR, isMelee) -- 附加武器的函数
local bone = GetPedBoneIndex(GetPlayerPed(-1), boneNumber) -- 获取骨骼索引
RequestModel(attachModel) -- 请求模型
while not HasModelLoaded(attachModel) do -- 等待模型加载
Wait(100)
end
attached_weapons[attachModel] = { -- 将武器信息存储在attached_weapons表中
hash = modelHash,
handle = CreateObject(GetHashKey(attachModel), 1.0, 1.0, 1.0, true, true, false)
}
if isMelee then x = 0.11 y = -0.14 z = 0.0 xR = -75.0 yR = 185.0 zR = 92.0 end -- 近战项目重新定位
if attachModel == "prop_ld_jerrycan_01" then x = x + 0.3 end -- 特殊物品位置调整
AttachEntityToEntity(attached_weapons[attachModel].handle, GetPlayerPed(-1), bone, x, y, z, xR, yR, zR, 1, 1, 0, 0, 2, 1) -- 将物体附加到玩家身上
end
function isMeleeWeapon(wep_name) -- 检查武器是否为近战武器的函数
if wep_name == "prop_golf_iron_01" then
return true
elseif wep_name == "w_me_bat" then
return true
elseif wep_name == "prop_ld_jerrycan_01" then
return true
else
return false
end
end