搜索
开启左侧

1

[复制链接]
嘉木 发表于 2025-3-27 01:56:33 | 显示全部楼层 |阅读模式

-- this script puts certain large weapons on a player's back when it is not currently selected but still in there weapon wheel
-- by: minipunch
-- originally made for USA Realism RP (https://usarrp.net)

-- Add weapons to the 'compatable_weapon_hashes' table below to make them show up on a player's back (can use GetHashKey(...) if you don't know the hash) --
local SETTINGS = {
    back_bone = 24816,
    x = 0.075,
    y = -0.15,
    z = -0.02,
    x_rotation = 0.0,
    y_rotation = 165.0,
    z_rotation = 0.0,
    compatable_weapon_hashes = {
      -- melee:
      --["prop_golf_iron_01"] = 1141786504, -- positioning still needs work
      ["w_me_bat"] = -1786099057,
      ["prop_ld_jerrycan_01"] = 883325847,
      -- assault rifles:
      ["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,
      -- sub machine guns:
      ["w_sb_microsmg"] = 324215364,
      ["w_sb_assaultsmg"] = -270015777,
      ["w_sb_smg"] = 736523883,
      ["w_sb_smgmk2"] = GetHashKey("WEAPON_SMG_MK2"),
      ["w_sb_gusenberg"] = 1627465347,
      -- sniper rifles:
      ["w_sr_sniperrifle"] = 100416529,
      -- shotguns:
      ["w_sg_assaultshotgun"] = -494615257,
      ["w_sg_bullpupshotgun"] = -1654528753,
      ["w_sg_pumpshotgun"] = 487013001,
      ["w_ar_musket"] = -1466123874,
      ["w_sg_heavyshotgun"] = GetHashKey("WEAPON_HEAVYSHOTGUN"),
      -- ["w_sg_sawnoff"] = 2017895192 don't show, maybe too small?
      -- launchers:
      ["w_lr_firework"] = 2138347493
    }
}

local attached_weapons = {}

Citizen.CreateThread(function()
  while true do
      local me = GetPlayerPed(-1)
      ---------------------------------------
      -- attach if player has large weapon --
      ---------------------------------------
      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
      --------------------------------------------
      -- remove from back if equipped / dropped --
      --------------------------------------------
      for name, attached_object in pairs(attached_weapons) do
          -- equipped? delete it from back:
          if GetSelectedPedWeapon(me) ==  attached_object.hash or not HasPedGotWeapon(me, attached_object.hash, false) then -- equipped or not in weapon wheel
            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] = {
    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 -- reposition for melee items
  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



回复 论坛版权

使用道具 举报

ChatGPT 发表于 2025-3-27 01:58:52 | 显示全部楼层
这段脚本的功能是在玩家身后显示某些大型武器,当这些武器并未被选中但仍在武器轮中时。它是为USA Realism RP制作的。以下是代码的逐行解释和中文翻译:
-- 这个脚本会在玩家背后放置某些大型武器,当它们并未被选中但仍在武器轮中时。
-- 作者: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

### 代码放置建议:
- 该代码应放置在 `Client.lua` 中,因为它涉及到玩家的本地操作和视觉效果,包括附加物体和处理玩家的武器状态。
回复

使用道具 举报

文明发言,和谐互动
文明发言,和谐互动
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|FiveM技术教程分享 ( 冀ICP备2021005225号-1 ) |网站地图

GMT+8, 2025-5-1 06:04 , Processed in 0.173650 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2013 ELITE论坛【技术无价-分享快乐】

快速回复 返回顶部 返回列表