找回密码
 点一下
查看: 1663|回复: 3

请教疑问,ForGroup()为神马会使范围选取匹配单位函数无效。。。

[复制链接]
发表于 2013-7-21 21:31:50 | 显示全部楼层 |阅读模式
本帖最后由 Simonade 于 2013-7-21 23:07 编辑

                                                   在查看“jass已知的bug”中也没有看到类似的bug存在。。。
globals
    hashtable h=InitHashtable()
endglobals
//========================================================================
function Scale takes integer T returns nothing
    local unit dummy=LoadUnitHandle(h,0,0)
    call SetUnitScale(dummy,3.0+T*0.0075,3.0+T*0.0075,3.0+T*0.0075)
    set dummy=null
endfunction
//=========================================================================
function IsDrop takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(LoadUnitHandle(h,0,0))) and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD)   
endfunction
//=========================================================================
function Grow takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local location point=LoadLocationHandle(h,GetHandleId(t),0)
    local unit dummy=LoadUnitHandle(h,0,0)
    local integer T=LoadInteger(h,GetHandleId(t),10)
    local integer n=LoadInteger(h,GetHandleId(t),11)
    local group g=CreateGroup()
    local unit u
    local location loc
    local real dist
    local real ang
    set T=T+1
    call SaveInteger(h,GetHandleId(t),10,T)
    call Scale(T)
    call GroupEnumUnitsInRangeOfLoc(g,point,800.0+2.0*T+150.0*n,Condition(function IsDrop))//主要帮瞧瞧这个地方为啥会失效呢
    set n=0
    loop
        set u=FirstOfGroup(g)
    exitwhen u==null
        set loc=GetUnitLoc(u)
        set dist=SquareRoot(Pow(GetLocationX(point)-GetLocationX(loc),2.0)+Pow(GetLocationY(point)-GetLocationY(loc),2.0))
        set ang=Atan2(GetLocationY(point)-GetLocationY(loc),GetLocationX(point)-GetLocationX(loc))
        if dist>50 then
            call SetUnitX(u,GetLocationX(loc)+(5.0+0.0375*T+200.0/(dist+1.0))*Cos(ang+(80.0-T*0.125)*bj_DEGTORAD))//(15.0+n/1000.0)
            call SetUnitY(u,GetLocationY(loc)+(5.0+0.0375*T+200.0/(dist+1.0))*Sin(ang+(80.0-T*0.125)*bj_DEGTORAD))//(15.0+n/1000.0)
        else
            call SetUnitState(u,UNIT_STATE_LIFE,GetUnitState(u,UNIT_STATE_LIFE)*0.5)
            call SetUnitPosition(u,-22115.6,-23597.5)
        endif
        call RemoveLocation(loc)
        call GroupRemoveUnit(g,u)
        if GetUnitAbilityLevel(u,'B004')>0 then
            call UnitDamageTarget(dummy,u,0.5+n*0.5+500.0/(dist+0.01),false,false,ATTACK_TYPE_MELEE,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)//没有使用ForGroup的正常版
        endif
        set u=null
        set loc=null
        set n=n+1
    endloop
    call SaveInteger(h,GetHandleId(t),11,n)
    if T==400 then
        call PauseTimer(t)
        call DestroyTimer(t)
        call RemoveLocation(point)
        call DestroyEffect(LoadEffectHandle(h,GetHandleId(point),0))
        call FlushChildHashtable(h,GetHandleId(point))
        call FlushChildHashtable(h,GetHandleId(t))
        call RemoveUnit(dummy)          //LoadUnitHandle(h,0,0)
    endif
    call BJDebugMsg("单位组单位数量"+I2S(n))
    set t=null
    set point=null
    set dummy=null
    set g=null
endfunction
//=======================================================
function Start takes nothing returns nothing
    local timer t
    local location point
    local unit dummy
    local effect eff1              
    if GetSpellAbilityId()!='A006' then
        return
    endif
        set point=GetSpellTargetLoc()
        set eff1=AddSpecialEffect("war3mapImported\\Black.mdl",GetLocationX(point),GetLocationY(point))
        set dummy=CreateUnit(GetOwningPlayer(GetTriggerUnit()),'e002',GetLocationX(point),GetLocationY(point),0.0)
        call SaveEffectHandle(h,GetHandleId(point),0,eff1)      
        call SaveUnitHandle(h,0,0,dummy)
        set t=CreateTimer()
        call SaveLocationHandle(h,GetHandleId(t),0,point)
        call TimerStart(t,0.05,true,function Grow)
    set t=null
    set point=null
    set dummy=null
    set eff1=null     
endfunction
//===========================================================================
function InitTrig_blackhole takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Start)
    set t=null
endfunction
//====================================================超级分割线
//====================================================超级分割线                    上面的可以用;下面的不能用(进入游戏执行无效)
//====================================================超级分割线

globals
    hashtable h=InitHashtable()
endglobals
//========================================================================
function Ct takes nothing returns nothing
    local integer n=LoadInteger(h,0,1)
    set n=n+1
    call SaveInteger(h,0,1,n)
endfunction
//========================================================================
function Scale takes integer n returns nothing
    local unit dummy=LoadUnitHandle(h,0,0)
    call SetUnitScale(dummy,3.0+n*0.15,3.0+n*0.15,3.0+n*0.15)
    set dummy=null
endfunction
//=========================================================================
function IsDrop takes nothing returns boolean
    return IsUnitEnemy(GetFilterUnit(),GetOwningPlayer(LoadUnitHandle(h,0,0))) and not IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD)   
endfunction
//=========================================================================
function Grow takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local location point=LoadLocationHandle(h,GetHandleId(t),0)
    local unit dummy=LoadUnitHandle(h,0,0)
    local integer n
    local real dist
    local integer T=LoadInteger(h,GetHandleId(t),10)
    local group g=CreateGroup()
    local unit u
    local location loc
    local real ang
    set T=T+1
    call SaveInteger(h,GetHandleId(t),10,T)
    call BJDebugMsg("位置一一一一"+I2S(n))                  //使用ForGroup后只能显示这里的Debug信息了。。。后面的语句都直接返回了
    call GroupEnumUnitsInRange(g,GetLocationX(point),GetLocationY(point),800.0+50.0*n,Condition(function IsDrop))
    call BJDebugMsg("位置二二二二二二二二二二"+I2S(n))
    call ForGroup(g,function Ct)
    set n=LoadInteger(h,0,1)
    call BJDebugMsg("位置三三三三三三三三三三三三三三三三三三三三"+I2S(n))
    call Scale(n)

    loop
        set u=FirstOfGroup(g)
    exitwhen u==null
        set loc=GetUnitLoc(u)
        set dist=SquareRoot(Pow(GetLocationX(point)-GetLocationX(loc),2.0)+Pow(GetLocationY(point)-GetLocationY(loc),2.0))
        set ang=Atan2(GetLocationY(point)-GetLocationY(loc),GetLocationX(point)-GetLocationX(loc))
        call SetUnitX(u,GetLocationX(loc)+(8.0+n*2.0+600.0/(dist+1.0))*Cos(ang+1.0833-T*0.0025))//(15.0+n/1000.0)
        call SetUnitY(u,GetLocationY(loc)+(8.0+n*2.0+600.0/(dist+1.0))*Sin(ang+1.0833-T*0.0025))//(15.0+n/1000.0)
        call RemoveLocation(loc)
        call GroupRemoveUnit(g,u)
        if GetUnitAbilityLevel(u,'B004')>0 then
            call UnitDamageTarget(dummy,u,0.5+n*0.05+500.0/(dist+1.0),false,false,ATTACK_TYPE_MELEE,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
        endif
        set u=null
        set loc=null
    endloop
    call SaveInteger(h,0,1,0)
    if T==420 then
        call PauseTimer(t)
        call DestroyTimer(t)
        call RemoveLocation(point)
        call DestroyEffect(LoadEffectHandle(h,GetHandleId(point),0))//call DestroyEffect(LoadEffectHandle(h,GetHandleId(point),1))
        call FlushChildHashtable(h,GetHandleId(point))
        call FlushChildHashtable(h,GetHandleId(t))
        call RemoveUnit(dummy)         
    endif
    call BJDebugMsg("单位组单位数量"+I2S(n))
    set t=null
    set point=null
    set dummy=null
    set g=null
endfunction
//=======================================================
function Start takes nothing returns nothing
    local timer t
    local location point
    local unit dummy
    local effect eff1               
    if GetSpellAbilityId()!='A006' then
        return
    endif
        set point=GetSpellTargetLoc()
        set eff1=AddSpecialEffect("war3mapImported\\Black.mdl",GetLocationX(point),GetLocationY(point))
        set dummy=CreateUnit(GetOwningPlayer(GetTriggerUnit()),'e002',GetLocationX(point),GetLocationY(point),0.0)
        call SaveEffectHandle(h,GetHandleId(point),0,eff1)     
        call SaveUnitHandle(h,0,0,dummy)
        set t=CreateTimer()
        call SaveLocationHandle(h,GetHandleId(t),0,point)
        call TimerStart(t,0.05,true,function Grow)
    set t=null
    set point=null
    set dummy=null
    set eff1=null        
endfunction
//===========================================================================
function InitTrig_blackholeII takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddAction(t,function Start)
    set t=null
endfunction






发表于 2013-7-21 22:22:28 | 显示全部楼层
本帖最后由 chyj4747 于 2013-7-21 22:24 编辑

GroupEnumUnitsInRange里的n没有赋值

遇到此类情况先反反复复找代码哪里写错了,而不是直接质疑暴雪写的有bug
再说GroupEnumUnitsInRange和ForGroup之间不是有句BjDebugMsg吗……

点评

太感谢了,成功了。。。奇怪为神马偏偏这里n非要赋值呢。。。大概是我以前每次定义局部变量数的时候常常是从hashtable中读取的,初值为0了。。。  详情 回复 发表于 2013-7-21 23:06
谢谢,但是。。。n默认不是0吗。。。我每次使用局部的整数或者实数很少赋初值啊,以前都没出过问题。。。我再去试试。。。  详情 回复 发表于 2013-7-21 22:54
回复

使用道具 举报

 楼主| 发表于 2013-7-21 23:06:05 | 显示全部楼层
本帖最后由 Simonade 于 2013-7-21 23:16 编辑
chyj4747 发表于 2013-7-21 22:22
GroupEnumUnitsInRange里的n没有赋值

遇到此类情况先反反复复找代码哪里写错了,而不是直接质疑暴雪写的 ...

太感谢了,成功了。。。奇怪为神马偏偏这里n非要赋值呢。。。大概是我以前每次定义局部变量数的时候常常是从hashtable中读取的,初值为0了。。。晕,jass区没有已解决这个主题额。。。和前天那个计时器和范围选取单位的问题是同一个问题。。。原因也是这个n没赋值了。。。汗,我好想不从hashtable中读取整数不超过3次。。。额,以前没接触过触发T的用法,所以是纯jass的菜鸟。。。
回复

使用道具 举报

发表于 2013-7-26 08:39:54 | 显示全部楼层
n没赋值
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-20 00:54 , Processed in 0.148619 second(s), 24 queries .

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

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