cs插件吧 关注:8,215贴子:88,144
  • 23回复贴,共1

令NPC攻击其他实体/ NPC [徴求其他写法]

只看楼主收藏回复


我正在写避难所模式,最近已完成建造系统。

可是npc部分一直出现问题,把进度一直往后拖(2015-03-05入坑)....
入正题
我的写法(能运作):
public FindClosesEnemy(entid)
{
new Float:Dist
new Float:maxdistance=1200.0
new indexid=0
new i = -1
while((i = find_ent_by_class(i, "player")))
{
if(is_user_alive(i) && is_valid_ent(i) && can_see_fm(entid, i))
{
Dist = entity_range(entid, i)
if(Dist <= maxdistance)
{
maxdistance=Dist
indexid=i
}
}
}
while((i = find_ent_by_class(i, "materials")))
{
if(0.0 < pev(i, pev_health) && is_valid_ent(i) && can_see_fm(entid, i))
{
Dist = entity_range(entid, i)
if(Dist <= maxdistance)
{
maxdistance=Dist
indexid=i
}
}
}
return (indexid) ? indexid : 0
}
public bool:can_see_fm(entindex1, entindex2)
{
if (!entindex1 || !entindex2)
return false
if (pev_valid(entindex1) && pev_valid(entindex1))
{
new flags = pev(entindex1, pev_flags)
if (flags & EF_NODRAW || flags & FL_NOTARGET)
{
return false
}
new Float:lookerOrig[3]
new Float:targetBaseOrig[3]
new Float:targetOrig[3]
new Float:temp[3]
pev(entindex1, pev_origin, lookerOrig)
pev(entindex1, pev_view_ofs, temp)
lookerOrig[0] += temp[0]
lookerOrig[1] += temp[1]
lookerOrig[2] += temp[2]
pev(entindex2, pev_origin, targetBaseOrig)
pev(entindex2, pev_view_ofs, temp)
targetOrig[0] = targetBaseOrig [0] + temp[0]
targetOrig[1] = targetBaseOrig [1] + temp[1]
targetOrig[2] = targetBaseOrig [2] + temp[2]
engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the had of seen player
if (get_tr2(0, TraceResult:TR_InOpen) && get_tr2(0, TraceResult:TR_InWater))
{
return false
}
else
{
new Float:flFraction
get_tr2(0, TraceResult:TR_flFraction, flFraction)
if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2))
{
return true
}
else
{
targetOrig[0] = targetBaseOrig [0]
targetOrig[1] = targetBaseOrig [1]
targetOrig[2] = targetBaseOrig [2]
engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the body of seen player
get_tr2(0, TraceResult:TR_flFraction, flFraction)
if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2))
{
return true
}
else
{
targetOrig[0] = targetBaseOrig [0]
targetOrig[1] = targetBaseOrig [1]
targetOrig[2] = targetBaseOrig [2] - 17.0
engfunc(EngFunc_TraceLine, lookerOrig, targetOrig, 0, entindex1, 0) // checks the legs of seen player
get_tr2(0, TraceResult:TR_flFraction, flFraction)
if (flFraction == 1.0 || (get_tr2(0, TraceResult:TR_pHit) == entindex2))
{
return true
}
}
}
}
}
return false
}
徴求其他写法


IP属地:中国香港1楼2016-05-28 18:13回复

    要避难所模型的话告诉我


    IP属地:中国香港2楼2016-05-28 18:19
    收起回复
      跪拜大神


      IP属地:立陶宛来自Android客户端3楼2016-05-28 19:25
      收起回复
        这么久都完成不了还是爬出来吧 我这有个跟npc有关的模式 快跟我来搅


        IP属地:广东来自Android客户端4楼2016-05-29 10:00
        回复
          楼主是大神


          IP属地:广东5楼2016-05-29 10:17
          回复
            顶!


            IP属地:河南来自Android客户端6楼2016-05-29 12:19
            回复
              最大的问题:NPC不會跑到最近的Waypoint,只會顺次序跑。
              例如Waypoint次序是
              1→2→3→4→5
              当npc跑过点2,正跑向点3时被玩家引开,但在警车处跟丢了
              那npc就继续会跑向点3,而不是就近的点4,结果就会被大楼卡住


              IP属地:中国香港7楼2016-05-29 17:54
              收起回复
                求模型


                IP属地:广东来自Android客户端8楼2016-05-29 19:08
                收起回复
                  Use SyPbNPc, and got all you need:
                  http://tieba.baidu.com/f?ie=utf-8&kw=SyPB


                  9楼2016-05-30 23:01
                  回复
                    qq多少?请教


                    IP属地:内蒙古10楼2016-06-01 22:40
                    收起回复
                      另外,NPC尸群不会包围玩家
                      只有带头的NPC才能摸到人,走在后头的會被挡住。


                      IP属地:中国香港11楼2016-06-02 16:28
                      回复
                        曾经看到你的一贴,关于stock anim(ent, sequence),代码写的很好,我请教一个问题,关于npc不攻击T,我写了判断,但是加在zombie_attack(ent),是不攻击了,但是npc随着t移动追踪,EngFunc_WalkMove,这里怎么改?


                        IP属地:内蒙古12楼2016-06-03 08:13
                        收起回复
                          跪了


                          IP属地:广东来自Android客户端13楼2016-06-07 23:32
                          回复
                            能把建造系统和那些采集系统发过来吗 我试试 qq3140369322


                            IP属地:河南14楼2017-01-18 12:09
                            回复