Данная наработка может ответить на вопрос: "Как сделать чтоб цепь молнии наносила урон от интелекта"и в том духе. Все действия можно сделать ГУИ методом и довольно просто (на мой взгляд). Как пользоваться смотрим триггер "ReadMe" в ЭТОЙ НАРАБОТКЕ. Для интересующих кода
Код
library LIGHTNING
globals private hashtable H = InitHashtable() private unit RangeUnit = null endglobals
function Dist takes real x, real y, real x1, real y1 returns real return SquareRoot((x-x1)*(x-x1)+(y-y1)*(y-y1)) endfunction
function DistToUnit takes real x, real y, group g returns unit local unit e local real x1 local real y1 local real dist=0. set RangeUnit=null
loop set e=FirstOfGroup(g) set x1=GetWidgetX(e) set y1=GetWidgetY(e) exitwhen e==null if Dist(x,y,x1,y1)<dist or dist==0. then set dist=Dist(x,y,x1,y1) set RangeUnit=e endif call GroupRemoveUnit(g,e) endloop
set e=null if RangeUnit==null then return null endif return RangeUnit endfunction
function TimerLightning takes nothing returns nothing local timer t=GetExpiredTimer() local integer id=GetHandleId(t) local real a=LoadReal(H,id,2) local unit u1=LoadUnitHandle(H,id,3) local unit u2=LoadUnitHandle(H,id,4) if a > 0. then call SetLightningColor(LoadLightningHandle(H,id,1),1,1,1,a) call MoveLightningEx(LoadLightningHandle(H,id,1),true,GetWidgetX(u1),GetWidgetY(u1),GetUnitFlyHeight(u1)+20.,GetWidgetX(u2),GetWidgetY(u2),GetUni tFlyHeight(u2)+20.) call SaveReal(H,id,2,a-.05) else call DestroyLightning(LoadLightningHandle(H,id,1)) call PauseTimer(t) call DestroyTimer(t) call FlushChildHashtable(H,id) endif set t=null set u1=null set u2=null endfunction
function CreateLightning takes unit u1,unit u2,string typel returns nothing local timer t=CreateTimer() local integer id=GetHandleId(t) call SaveLightningHandle(H,id,1,AddLightningEx(typel,true,GetWidgetX(u1),GetWidgetY(u1),GetUnitFlyHeight(u1)+20.,GetWidgetX(u2),GetWidgetY(u2),Ge tUnitFlyHeight(u2)+20.)) call SetLightningColor(LoadLightningHandle(H,id,1),1,1,1,1.) call SaveReal(H,id,2,1.) call SaveUnitHandle(H,id,3,u1) call SaveUnitHandle(H,id,4,u2) call TimerStart(t,.04,true,function TimerLightning) set t=null endfunction
function NextTaretLightning takes nothing returns nothing local timer t=GetExpiredTimer() local integer id=GetHandleId(t) local unit u=LoadUnitHandle(H,id,1) local unit ut=LoadUnitHandle(H,id,2) local group g=LoadGroupHandle(H,id,3) local integer count=LoadInteger(H,id,4) local unit U=LoadUnitHandle(H,id,5) local integer massive=LoadInteger(H,id,8) local real x=GetWidgetX(ut) local real y=GetWidgetY(ut) local group G=CreateGroup() local group gr=null local unit e
call GroupEnumUnitsInRange(G,x,y,LoadReal(H,id,7),null) if g==null then set g=CreateGroup()
loop set e=FirstOfGroup(G) exitwhen e==null
if IsUnitAlly(e,GetOwningPlayer(U))==udg_FILTER_TARGET[1] and IsUnitType(e,UNIT_TYPE_MAGIC_IMMUNE)==udg_FILTER_TARGET[2] and IsUnitType(e,UNIT_TYPE_STRUCTURE)==udg_FILTER_TARGET[3] and IsUnitType(e,UNIT_TYPE_MECHANICAL)==udg_FILTER_TARGET[4] and IsUnitType(e,UNIT_TYPE_DEAD)==udg_FILTER_TARGET[5] and e!=ut then call GroupAddUnit(g,e) endif
call GroupRemoveUnit(G,e) endloop
set e=GroupPickRandomUnit(g) set bj_lastReplacedUnit=U set bj_lastHauntedGoldMine=e call TriggerExecute(LoadTriggerHandle(H,id,8)) call CreateLightning(ut,e,LoadStr(H,id,9))
if count>0 and e!=null then call TimerStart(t,LoadReal(H,id,6),false,function NextTaretLightning) call SaveUnitHandle(H,id,1,ut) call SaveUnitHandle(H,id,2,e) call SaveInteger(H,id,4,count-1) else call DestroyTimer(t) call FlushChildHashtable(H,id) endif call DestroyGroup(G) call DestroyGroup(g) else set gr=CreateGroup()
loop set e=FirstOfGroup(G) exitwhen e==null
if IsUnitAlly(e,GetOwningPlayer(U))==udg_FILTER_TARGET[1] and IsUnitType(e,UNIT_TYPE_MAGIC_IMMUNE)==udg_FILTER_TARGET[2] and IsUnitType(e,UNIT_TYPE_STRUCTURE)==udg_FILTER_TARGET[3] and IsUnitType(e,UNIT_TYPE_MECHANICAL)==udg_FILTER_TARGET[4] and IsUnitType(e,UNIT_TYPE_DEAD)==udg_FILTER_TARGET[5] and e!=ut and IsUnitInGroup(e,g)==false then call GroupAddUnit(gr,e) endif
call GroupRemoveUnit(G,e) endloop
set e=DistToUnit(x,y,gr) set bj_lastReplacedUnit=U set bj_lastHauntedGoldMine=e call TriggerExecute(LoadTriggerHandle(H,id,8)) call GroupAddUnit(g,e)
if e!=null then call CreateLightning(ut,e,LoadStr(H,id,9)) endif
if count>0 and e!=null then call TimerStart(t,LoadReal(H,id,6),false,function NextTaretLightning) call SaveUnitHandle(H,id,1,ut) call SaveUnitHandle(H,id,2,e) call SaveGroupHandle(H,id,3,g) call SaveInteger(H,id,4,count-1) else call DestroyGroup(g) call DestroyTimer(t) call FlushChildHashtable(H,id) endif
call DestroyGroup(G) call DestroyGroup(gr) endif set t=null set u=null set ut=null set g=null set U=null set G=null set gr=null set e=null endfunction
function addlightning takes unit u,unit ut,boolean b,integer counttarget,trigger Trig returns nothing local timer t=CreateTimer() local integer id=GetHandleId(t) local group g
call SaveUnitHandle(H,id,1,u) call SaveUnitHandle(H,id,2,ut) call SaveUnitHandle(H,id,5,u) call SaveReal(H,id,6,udg_PERIOD_NEXT_TARGET) call SaveReal(H,id,7,udg_RADIUS_NEXT_TARGET) call SaveTriggerHandle(H,id,8,Trig) call SaveStr(H,id,9,udg_TYPE_LIGHTNING) call CreateLightning(u,ut,udg_TYPE_LIGHTNING) set bj_lastHauntedGoldMine=ut set bj_lastReplacedUnit=u call TriggerExecute(Trig) if b==true then set g=CreateGroup() call SaveGroupHandle(H,id,3,g) call GroupAddUnit(g,ut) else call SaveGroupHandle(H,id,3,null) endif if counttarget>0 then call SaveInteger(H,id,4,counttarget-2) else call SaveInteger(H,id,4,0) endif