找回密码
 点一下
查看: 1357|回复: 1

求懂AI的大大帮我看下哪里有问题

[复制链接]
发表于 2012-11-18 17:30:57 | 显示全部楼层 |阅读模式
我把下面加到了一个人做的AI脚本里
脚本没意义其他问题
但是我加了我这段以后电脑运行这段AI就会出问题
只采矿其他什么事都没做
boolean                   huichen                  = false
group                      grp                     = CreateGroup()
    unit                        u                      = null
    real                        r1                     = 0
    real                        r2                     = 0
    integer                    index                   = 0
    integer                     i                      = 6


function UnitUseItemPointLoc takes unit whichUnit, item whichItem, location loc returns boolean
return UnitUseItemPoint(whichUnit, whichItem, GetLocationX(loc), GetLocationY(loc))
endfunction
function GetPlayerStartLocationLoc takes player whichPlayer returns location
return GetStartLocationLoc(GetPlayerStartLocation(whichPlayer))
endfunction
function tp takes nothing returns nothing
    call GroupEnumUnitsInRange(grp,0,0,999999,null)
    loop
  set u=FirstOfGroup(grp)
        exitwhen u==null
        if GetOwningPlayer(u)==ai_player and ((IsUnitType(u, UNIT_TYPE_HERO)) then
            set r1=GetUnitState(u,UNIT_STATE_LIFE)
            set r2=GetUnitState(u,UNIT_STATE_MAX_LIFE)
            if r1/r2<=0.2 and ((  CaptainInCombat(true) )or (not CaptainIsHome())) then
                loop
                    exitwhen index>=6
                    if ((GetItemTypeId(UnitItemInSlot(u , index)) == 'stwp')) then
                        set i=index
                    endif
                    set index=index+1
                endloop
                if i!=6 and huicheng==false then
                    call ClearCaptainTargets()
                    call CaptainGoHome()
                    set loc=GetPlayerStartLocationLoc(ai_player)
                    call UnitUseItemPointLoc( u, UnitItemInSlot(u,i),loc )
                    call RemoveLocation(loc)
     set huicheng = true
                endif
          set index=0
       set i=6
            endif
  endif
        call GroupRemoveUnit(grp,u)
    endloop
if huicheng==true then
  call Sleep(4)
  set huicheng=false
endif
endfunction
function nc takes nothing returns nothing
loop
     call tp()
     call  Sleep(0.3)
endloop  
endfunction

然后在主函数里 call StartThread( function nc ) 了
发表于 2013-1-14 11:29:05 | 显示全部楼层
楼上,你代码里面很多错误,当然ai脚本就不会执行了咯!
你定义的变量名是huichen 但是用的时候确实用 huicheng...
你下面的loc变量都没有local的,囧。
仔细看看代码吧!!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 点一下

本版积分规则

Archiver|移动端|小黑屋|地精研究院

GMT+8, 2024-4-27 22:39 , Processed in 0.186697 second(s), 27 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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