|
楼主 |
发表于 2008-1-28 21:22:04
|
显示全部楼层
谢谢 eff 和 zhuzeitou ^_^
照着eff的1 、2两条更改了代码。 代码如下:
[codes=jass]function U2I takes unit u returns integer
return u
return 0
endfunction
function I2U takes integer i returns unit
return i
return null
endfunction
function G2I takes group g returns integer
return g
return 0
endfunction
function B2I takes boolean b returns integer
return b
return 0
endfunction
//检测周围是否有可攻击的目标,检测到一个后就不再检测
function BeAttack_Condition takes nothing returns boolean
if(udg_BeAttackCond)then
if(IsUnitInGroup(GetFilterUnit(),udg_F_Group))then
set udg_BeAttackCond = FALSE
return TRUE
endif
endif
return FALSE
endfunction
//查看Unit周围是否有可攻击的目标 ,若有的话则攻击,没有的话则什么都不做
function Attack takes unit whichunit returns nothing
local boolean isnormal
local boolean outloop
local boolexpr cond
local real x
local real y
local unit beattacker
local integer attacker
local integer n = 0
local group beattack = CreateGroup()
set isnormal = GetStoredBoolean(udg_GC,I2S(U2I(whichunit)),"IsNormal")
set x = GetUnitX(whichunit)
set y = GetUnitY(whichunit)
set outloop = FALSE
set cond = Condition(function BeAttack_Condition)
set attacker = GetStoredInteger(udg_GC,I2S(U2I(whichunit)),"AttackByWho"+I2S(n))
if(isnormal) then
set udg_BeAttackCond = TRUE
call GroupEnumUnitsInRange(beattack,x,y,300.0,cond)
if(not(udg_BeAttackCond))then
call StoreBoolean(udg_GC,I2S(U2I(whichunit)),"IsNormal",FALSE)
set beattacker = FirstOfGroup(beattack)
call IssueTargetOrderById( whichunit, 851983,beattacker)
loop
set attacker = GetStoredInteger(udg_GC,I2S(U2I(beattacker)),"AttackByWho"+I2S(n))
if(attacker==0)then
call StoreInteger(udg_GC,I2S(U2I(beattacker)),"AttackByWho"+I2S(n),U2I(whichunit))
set outloop = TRUE
endif
exitwhen outloop
set n = n + 1
endloop
set n = 0
set attacker = 0
set outloop = FALSE
endif
endif
call DestroyGroup(beattack)
endfunction
//对那些正常状态的Unit发出移动到某某地方的命令
function Give_Normal_Unit_Order takes unit whichunit returns nothing
local boolean t
set t = GetStoredBoolean(udg_GC,I2S(U2I(whichunit)),"IsNormal")
if( not(IsUnitPaused(whichunit)) and t) then
call IssuePointOrderById( whichunit, 851986, GetRandomInt(-3000,3000), GetRandomInt(-3000,3000) )
endif
endfunction
//在随机的地点产生某一个单位组(可能是强盗组,也可能是农民组)的单位,并命令其移动到某个地点
function Created_Unit takes group whichgroup,integer N returns nothing
local unit Tunit
local integer TUnitId
set TUnitId = GetStoredInteger(udg_GC,"UnitType",I2S(G2I(whichgroup)))
loop
exitwhen N==0
set Tunit = CreateUnit(Player(0),TUnitId,GetRandomInt(-3000,3000),GetRandomInt(-3000,3000),bj_UNIT_FACING)
call GroupAddUnit(whichgroup,Tunit)
call StoreBoolean(udg_GC,I2S(U2I(Tunit)),"IsNormal",TRUE)
call StoreInteger(udg_GC,I2S(U2I(Tunit)),"AttackByWho",0)
call Give_Normal_Unit_Order(Tunit)
set Tunit = null
set N = N -1
endloop
endfunction
//检测单位是否已经死亡,如果死亡的话则清除该单位,让攻击他的单位的状态变为正常
function Unit_Status takes group whichgroup,unit whichunit returns nothing
local integer attacker
local boolean outloop
local integer n = 0
if ((IsUnitDeadBJ(whichunit)==true))then
loop
set attacker = GetStoredInteger(udg_GC,I2S(U2I(whichunit)),"AttackByWho"+I2S(n))
if(not(attacker==0))then
call StoreBoolean(udg_GC,I2S(attacker),"IsNormal",TRUE)
call Give_Normal_Unit_Order(I2U(attacker))
set n = n + 1
set outloop = FALSE
endif
if(attacker==0)then
set outloop = TRUE
endif
exitwhen outloop
endloop
call RemoveUnit(whichunit)
call GroupRemoveUnit(whichgroup,whichunit)
call FlushStoredMission(udg_GC,I2S(U2I(whichunit)))
call Created_Unit(whichgroup,1)
endif
endfunction
function Check_Unit_IsDied_Status_Q takes nothing returns nothing
call Unit_Status(udg_Q_Group,GetEnumUnit())
endfunction
function Check_Unit_IsDied_Status_F takes nothing returns nothing
call Unit_Status(udg_F_Group,GetEnumUnit())
endfunction
function Check_Unit_IsNormal_Status takes nothing returns nothing
call Give_Normal_Unit_Order(GetEnumUnit())
endfunction
function Check_Unit_Around_Status takes nothing returns nothing
call Attack(GetEnumUnit())
endfunction
function Check_IsNoraml_Status takes nothing returns nothing
call ForGroup(udg_F_Group,function Check_Unit_IsNormal_Status)
call ForGroup(udg_Q_Group,function Check_Unit_IsNormal_Status)
endfunction
function Check_IsDied_Status takes nothing returns nothing
call ForGroup(udg_F_Group,function Check_Unit_IsDied_Status_F)
endfunction
function Check_Around_Status takes nothing returns nothing
call ForGroup(udg_Q_Group,function Check_Unit_Around_Status)
endfunction
//=========================================================
//具体的调用函数如下,当输入debug则开始调用函数
//=========================================================
function Trig_DeBug_Actions takes nothing returns nothing
local timer tm1=CreateTimer()
local timer tm2=CreateTimer()
local timer tm3=CreateTimer()
local unit Tunit
call StoreInteger(udg_GC,"UnitType",I2S(G2I(udg_F_Group)),'hpea')
call StoreInteger(udg_GC,"UnitType",I2S(G2I(udg_Q_Group)),'njks')
call Created_Unit(udg_Q_Group,50)
call Created_Unit(udg_F_Group,50)
call TimerStart(tm1,10,true,function Check_IsNoraml_Status)
call TimerStart(tm2,2,true,function Check_IsDied_Status)
call TimerStart(tm3,2,true,function Check_Around_Status)
endfunction
//===========================================================================
function InitTrig_DeBug takes nothing returns nothing
set gg_trg_DeBug = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_DeBug, Player(0), "debug", true )
call TriggerAddAction( gg_trg_DeBug, function Trig_DeBug_Actions )
endfunction[/codes]
现在我知道的Bug是发生在Attack函数里面,我本初的想法是强盗Group(udg_Group_Q)在周围没有农民(udg_Group_F)的时候攻击周围的强盗。于是就用了两组 call GroupEnumUnitsInRange(beattack,x,y,300.0,cond) 只是更改了cond的条件,让找不到农民的时候,更改条件 来找
周围是否有没有强盗。不过我把两个Call放在同一个函数里面不管临时的Group是否都为beattack,总是会发生异常的。
希望大家再帮我看看 找找哪里还有毛病了 谢谢了 万分感激 o(∩_∩)o...
ps:zhuzeitou的那个ReturnBug问题我没改,因为要改的地方太多了。。懒得弄了 -.-||| |
|