终于把闪避功能做出来了
饥荒mod制作吧
全部回复
仅看楼主
level 8
[酷]
2017年03月29日 15点03分 1
level 8
之前看到过有些比较大的mod上有闪避这种功能,觉得很炫酷。试着去学一下,却发现饥荒本身是完全没有闪避机制的。闪避不是说直接把伤害改成0就可以的,还要连僵直一起去掉才算是真的闪避。
2017年03月29日 15点03分 2
level 8
理论上来说,得改combat组件源码,不过仔细想了想,只要在mod里面,修改玩家的combat组件中被攻击的那个函数就可以了
2017年03月29日 15点03分 3
level 8
local function missfn(inst)
inst.components.combat.oldAttacked = inst.components.combat.GetAttacked
function inst.components.combat:GetAttacked( ... )
local miss_rate = 50
if math.random(1, 100) > miss_rate then
return inst.components.combat:oldAttacked(...)
end
end
endAddPlayerPostInit(function(inst)
missfn(inst)
end)
2017年03月29日 15点03分 4
level 8
闪避的逻辑应该是这样:
随机,判断是否闪避
若没有闪避,则执行被攻击
也就是说,需要在原本的代码前面加上闪避的判断
如果没有闪避掉,则按照以往的代码执行下去
2017年03月29日 15点03分 5
level 8
丑陋一点的写法就是把原本combat里面的代码全部抄一份,在前面加上闪避判断
然而我从千年狐mod那里学到了一招,先存下旧的函数,在覆盖它
2017年03月29日 15点03分 6
level 8
AddPlayerPostInit(function(inst)
missfn(inst)
end)
添加玩家初始化函数,调用missfn
2017年03月29日 15点03分 7
level 8
local function missfn(inst)
存下combat组件的GetAttacked函数,我这里取名叫oldAttacked
inst.components.combat.oldAttacked = inst.components.combat.GetAttacked
覆盖GetAttacked函数
function inst.components.combat:GetAttacked( ... )
定义闪避率为50,因为测试,所以简单弄了一下
local miss_rate = 50
随机1到100,如果随机出来的数字大于50
则调用oldAttacked
if math.random(1, 100) > miss_rate then
return inst.components.combat:oldAttacked(...)
end
end
end
2017年03月29日 15点03分 8
level 13
[滑稽]给大哥顶帖一波
2017年03月29日 16点03分 9
level 6
学习了,顶一个
2017年03月30日 05点03分 10
level 6
厉害👍
2017年03月31日 00点03分 11
level 13
突然想到崩坏3里的极限闪避~[滑稽][滑稽][滑稽]
2017年04月23日 23点04分 13
1