Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

扩展开发教程:增加一把新的枪械/修改一把枪械的数据 #24

Closed
kiccer opened this issue Jul 16, 2019 · 0 comments
Closed
Labels
扩展开发教程🌟 Teach you how to change scripts by yourself

Comments

@kiccer
Copy link
Owner

kiccer commented Jul 16, 2019

假设你已经看完了Lua语言基础和Logitech的API文档,并且成功使用了 Soldier76.lua
然后此刻的你已经迫不及待的想要增加一把自己配置数据的枪械了,那么请看下面我准备的这份教程,内容不多,全是重点,请仔细阅读~

第一步:数据模块

如果你已经看过脚本配置项下方核心区域的代码,你应该发现了有许多长得很像的重复函数:

pubg["UMP45"] = function ()

	return pubg.execOptions({
		ratio = 1,
		interval = 100,
		ballistic = {
			{1, 0},
			{5, 70},
			{10, 95},
			{15, 96},
			{35, 103},
		}
	})

end

这里我拿 UMP45 举例,你需要做的就是复制一份相同的函数,然后将 UMP45 改为你新增的枪械的名字,假设为 Gun_Name_01

第二步:配件信息

canUse 相应的系列下增加一把枪械 Gun_Name_01,假如这把枪是 .45 子弹的,那么就这么写:

canUse = {
	[".45"] = {
		{ "UMP45", 0 }, -- 基础镜 + 扩容,Bizon (基础镜即可),Vector (补偿 + 基础镜 + 扩容) | Reddot + Mag,Bizon (Reddot),Vector (Komp + Reddot + Mag)
		{ "Tommy Gun", 0 }, -- 扩容 | Mag
		{ "Gun_Name_01", 1 }, -- 在这里写下枪械需要的配件
	},
	["9mm"] = {
		{ "Vector", 0 }, -- 基础镜 + 扩容 | Reddot + Mag
		{ "Micro UZI", 0 }, -- 扩容 | Mag
	},
	["5.56"] = {
		{ "M416", 0 }, -- 补偿 + 基础镜 + 直角 + 枪托 + 扩容 | Komp + Reddot + Triangular grip + Gunstock + Mag
		{ "SCAR-L", 0 }, -- 补偿 + 基础镜 + 直角 + 扩容 | Komp + Reddot + Triangular grip + Mag
		{ "QBZ", 0 }, -- 补偿 + 基础镜 + 直角 + 扩容 | Komp + Reddot + Triangular grip + Mag
		{ "G36C", 0 }, -- 补偿 + 基础镜 + 直角 + 扩容 | Komp + Reddot + Triangular grip + Mag
		{ "M16A4", 0 }, -- 补偿 + 基础镜 + 枪托 + 扩容 | Komp + Reddot + Gunstock + Mag
	},
	["7.62"] = {
		{ "AKM", 0 }, -- 补偿 + 基础镜 + 扩容 | Komp + Reddot + Mag
		{ "Beryl M762", 0 }, -- 补偿 + 基础镜 + 直角 + 扩容 | Komp + Reddot + Triangular grip + Mag
		{ "DP-28", 0 }, -- 基础镜 | Reddot
	},
},

记住将其他枪设置为 0 ,因为你接下来马上就要进入训练场去调试了。

第三步:设置子弹上限

进入训练场,找到枪械和配件,上好子弹,注意一下一个弹夹子弹的数量,假设是 40 发子弹。
再回看刚刚增加的 pubg["Gun_Name_01"] 函数,下面有一项 ballistic

ballistic = {
	{1, 0},
	{5, 70},
	{10, 95},
	{15, 96},
	{35, 103},
}

把它改成

ballistic = {
	{1, 0},
	{40, 103},
}

这么做的原因是告诉脚本,一共有40发子弹,当到达最大上限的时候就自动停止压枪。
如何知道是否停止?建议开启自动连发,自动连发状态下,如果剩余子弹数为 0 ,那么就会发出“咔咔咔”的声音,可以借此来判断。
并且第一发子弹是不需要压的,所以下压设置为0,这应该不需要我解释了。
既然讲到了这里,就顺便先说一下这里的数据是如何调整的吧!
相信很多人在使用 Soldier76.lua 之前,还用过许多别的宏,那些宏的弹道数据都是这么写的:

recoil_table["ump9"] = {
    basic={18,19,18,19,18,19,19,21,23,24,23,24,23,24,23,24,23,24,23,24,23,24,24,25,24,25,24,25,24,25,24,25,25,26,25,26,25,26,25,26,25,26,25,26,25,26},
    quadruple={83.3,83.3,83.3,83.3,83.3,83.3,83.3,116.7,116.7,116.7,116.7,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3,93.3},
    speed = 92
}

emmmm...
看起来是不是很头疼?从哪里开始改还要一个一个数过去?但是 Soldier76.lua 不一样,它有自己独创的结构:

{
	{1, 0},
	{a, b},
	{c, d}
}

-- 从2到a颗子弹,每颗子弹需要下压b距离
-- 从a+1到c颗子弹,每颗子弹需要下压d距离
-- 以此类推
-- 因为第一枪是不需要压的,所以数据都是以 `{1, 0}` 开头

仔细阅读两遍注释部分内容,然后再观察一下代码中的枪械数据模块,是不是有种豁然开朗的感觉?是不是有种很惊喜的感觉?

第四步:设置子弹间隔

现在你已经知道了怎么修改弹道数据了,但是现在依然不能够直接就开始修改,因为你并不知道枪械的开火间隔,所以枪械数据里的每一发子弹数据并不能确定是否和实际上的每一发相对应。
所以你要调整 interval 值,每个枪械数据模块都有一个 interval 用来表示枪械的子弹频率,需要找到合适的值的方法也很简单:

进入游戏,开火模式切换为单发,然后脚本连发功能必须是启用的,接着尝试打光一个弹夹。

  • 如果压枪自动停止了,且弹夹内有剩余子弹,则加大 interval
  • 如果弹夹子弹剩余为 0 ,但是压枪没有自动停止,且发出“咔咔咔”的声音,则减小 interval

填装子弹后,重复上面的操作,直至结果接近弹夹打空后立刻停止压枪,即不会听到“咔咔咔”声,可能没有那么刚好完美,只要最接近就行了。

然后假设最后得出的结果是 90 ,那么,现在代码新增的枪械数据模块应该变成了这个样子:

pubg["Gun_Name_01"] = function ()

	return pubg.execOptions({
		ratio = 1,
		interval = 90,
		ballistic = {
			{1, 0},
			{40, 103},
		}
	})

end

第五步:反复调试弹道数据

这一步就是最枯燥,最漫长的一步了。
上面提到了修改 ballistic 数据,就是这一步该做的事情。
但是在此之前,需要先开启 开发者调试模式 ,这对你调试弹道将会非常有帮助!默认的开启键是 ScrollLock 键。
改模式的作用这里不再复述,还不知道的话请看首页文档。

观察每一颗子弹的落点位置,假设从第5颗子弹开始,子弹开始向下偏,说明子弹压过头了,那么就需要减小下压力度:

pubg["Gun_Name_01"] = function ()

	return pubg.execOptions({
		ratio = 1,
		interval = 90,
		ballistic = {
			{1, 0},
			{5, 103},
			{40, 95},
		}
	})

end

这样改了之后,第 1 颗子弹保持不变,从第 2~5 颗子弹保持之前的 103 力度下压,然后第 6~40 颗子弹下拉力度降到 95
之后做的事情就是反复观察弹道,然后视情况增加数据节点。
当最终弹道变成一条水平线时,弹道数据就完美了。
关闭开发者调试模式,然后试着打一梭子,你会惊喜的发现,后坐力全部控制住了~

第六步:增加指令

如果你希望直接一个G键对应一把枪械,那么你还需要增加一个指令才行。

function pubg.runCmd (cmd)
	if cmd == "" then cmd = "none" end
	local switch = {
		["none"] = function () end,
		[".45"] = pubg.setBulletType,
		["9mm"] = pubg.setBulletType,
		["5.56"] = pubg.setBulletType,
		["7.62"] = pubg.setBulletType,
		["scopeX1"] = pubg.setScope,
		["scopeX2"] = pubg.setScope,
		["scopeX3"] = pubg.setScope,
		["scopeX4"] = pubg.setScope,
		["scopeX6"] = pubg.setScope,
		["UMP45"] = pubg.setGun,
		["Tommy Gun"] = pubg.setGun,
		["Vector"] = pubg.setGun,
		["Micro UZI"] = pubg.setGun,
		["M416"] = pubg.setGun,
		["SCAR-L"] = pubg.setGun,
		["QBZ"] = pubg.setGun,
		["G36C"] = pubg.setGun,
		["M16A4"] = pubg.setGun,
		["AKM"] = pubg.setGun,
		["Beryl M762"] = pubg.setGun,
		["DP-28"] = pubg.setGun,
		["Gun_Name_01"] = pubg.setGun, -- 复制一个 pubg.setGun 方法,然后改为你增加的枪械名字,名字必须完全相同
		["first"] = pubg.findInSeries,
		["next"] = pubg.findInSeries,
		["last"] = pubg.findInSeries,
		["first_in_canUse"] = pubg.findInCanUse,
		["next_in_canUse"] = pubg.findInCanUse,
		["last_in_canUse"] = pubg.findInCanUse,
		["off"] = function ()
			pubg.isStart = false
		end,
	}

	if pubg.ok then switch[cmd](cmd) end
end

最后也别忘了在 G_bind 里面绑定这把枪,这把枪的名字就是指令。例如:

["G5"] = "Gun_Name_01",

大功告成!

别忘了把 canUse 中你需要的枪械设置回 1
现在你已经准备就绪了!开始游戏尝试一下实战吧!

若有疏漏之处,欢迎指出~

@kiccer kiccer added the 扩展开发教程🌟 Teach you how to change scripts by yourself label Jul 16, 2019
Repository owner locked and limited conversation to collaborators Jul 24, 2019
Repository owner deleted a comment from godsano Jul 24, 2019
@kiccer kiccer added this to To do in Soldier76 - v4.0 Jul 24, 2019
@kiccer kiccer removed this from To do in Soldier76 - v4.0 Jul 24, 2019
@kiccer kiccer added this to In progress in Soldier76 - v4.0 Jul 24, 2019
kiccer referenced this issue Sep 6, 2019
1. 取消结果取整
2. startControl = "G_bind" 时,使用设备背景色判断启动状态(测试中)
3. 使用 pubg.changeIsStart 方法统一处理 isStart 状态
@kiccer kiccer pinned this issue Sep 24, 2019
@kiccer kiccer closed this as completed Sep 24, 2019
@kiccer kiccer converted this issue into discussion #146 Mar 25, 2022
@kiccer kiccer unpinned this issue Mar 25, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
扩展开发教程🌟 Teach you how to change scripts by yourself
Projects
None yet
Development

No branches or pull requests

1 participant