NPC 问题: NPC攻击NPC侦测FUNCTION的问题

Home Home
引用 | 编辑 op47
2012-08-13 18:09
楼主
推文 x0
以下是我NPC 侦测 NPC 的 FUNCTION, 但一执行, 伺服器就当掉了:
复制程式
public FindClosesEnemy(entid)
{
    new Float:Dist
    new Float:maxdistance=5000.0
    new indexid=0
    new i;
    while ((is_valid_ent(i = find_ent_by_class (i, CLASSNAME))) || (is_valid_ent(i = find_ent_by_class (i, "player"))))
    //for(new i=1;i <= get_maxplayers();i++)
    {
     new Ptdclassname[32]
  pev(i, pev_classname, Ptdclassname, charsmax(Ptdclassname))
  if (equal(Ptdclassname, CLASSNAME) && i != entid)
  {
   if (is_valid_ent(i) && pev(i,pev_health) > 0.0)
   {
    Dist = entity_range(entid, i)
             if(Dist <= maxdistance)
             {
                 maxdistance=Dist
                 indexid=i
                }
            }
        }
        else if (equal(Ptdclassname, "player"))
        {
         if(is_user_alive(i) && is_valid_ent(i) && cs_get_user_team(i) == CS_TEAM_CT && is_user_connected(i))
         {
             Dist = entity_range(entid, i)
             if(Dist <= maxdistance)
             {
                 maxdistance=Dist
                 indexid=i
             }
         }
           
     }
    }
    return indexid
}

请问一下, CODE 在那里出了问题?

献花 x0
引用 | 编辑 tw2twtw
2012-08-13 20:11
1楼
  
你的while 没有设定如何停止,要是条件式一直都符合...
就变成无限执行了,然后当掉~

献花 x0
引用 | 编辑 op47
2012-08-13 20:22
2楼
  
那么我应在那里加一个 break ? 表情

献花 x0
引用 | 编辑 HsK
2012-08-14 01:25
3楼
  
下面是引用 tw2twtw 于 2012-08-13 20:11 发表的 : 到引言文
你的while 没有设定如何停止,要是条件式一直都符合...
就变成无限执行了,然后当掉~

只说 while 应该没问题
(is_valid_ent(i = find_ent_by_class (i, CLASSNAME)))

找不到 classname entity,
find_ent_by_class 会 -1/0

is_valid_ent 便可 block while

献花 x0
引用 | 编辑 op47
2012-08-14 08:44
4楼
  
WHILE 没有出问题, 那么是那里出了问题 表情

献花 x0