Написал я способность цепной молнии, и хочу узнать какие ошибки допустил.
Хотя их там много)
Вот карта - xgm.guru/files/100/338026/ChainLightning.w3x.
А также вопрос: можно ли в вопросах спрашивать вопросы данного типа?)
Код:
Хотя их там много)
Вот карта - xgm.guru/files/100/338026/ChainLightning.w3x.
А также вопрос: можно ли в вопросах спрашивать вопросы данного типа?)
Код:
scope ChainLightning initializer Init
globals
private constant integer SpellId = 'A000'
private constant real TimerTick = 0.005
private constant real Distance = 1000
private constant real Radius = 60
private constant real RadiusChain = 400
private timer TimerAct = CreateTimer( )
private group GroupAct = CreateGroup( )
private group GroupTemp = CreateGroup( )
endglobals
private function Conditions takes nothing returns boolean
return GetSpellAbilityId( ) == SpellId
endfunction
private function ActionsTimer takes nothing returns nothing
local integer id = GetHandleId( TimerAct )
local unit caster = LU( Hash, id, k_caster )
local real angle = LR( Hash, id, k_angle )
local real casterX = LR( Hash, id, k_casterX )
local real casterY = LR( Hash, id, k_casterY )
local real casterZ = LR( Hash, id, k_casterZ )
local real distance = LR( Hash, id, k_distance )
local real newX = GetPolarOffsetX( casterX, distance, angle )
local real newY = GetPolarOffsetY( casterY, distance, angle )
local real newZ = GetPositionZ( newX, newY )
local lightning light = LL( Hash, id, k_lightning )
local unit firstUnit = null
local unit pickedUnit = null
call GroupEnum( GroupAct, Radius, newX, newY, GetBaseSpellFilter( caster ) )
set firstUnit = FirstOfGroup( GroupAct )
set distance = distance + 50
if firstUnit == null then
if distance < Distance then
call MoveLightningEx( light, true, casterX, casterY, casterZ, newX, newY, newZ )
call SR( Hash, id, k_distance, distance )
else
call GroupEnum( GroupAct, RadiusChain, newX, newY, GetBaseSpellFilter( caster ) )
loop
set pickedUnit = GroupPickRandomUnit( GroupAct )
exitwhen pickedUnit == null
if not IsUnitInGroup( pickedUnit, GroupTemp ) then
call RemoveLightningTimed( AddLightningEx( "CLSB", true, newX, newY, newZ, GetUnitX( pickedUnit ), GetUnitY( pickedUnit ), GetUnitZ( pickedUnit ) ), 0.2 )
call DamageUnit( caster, pickedUnit, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
call GroupAddUnit( GroupTemp, pickedUnit )
endif
call GroupRemoveUnit( GroupAct, pickedUnit )
endloop
call GroupClear( GroupTemp )
call FlushChildHashtable( Hash, id )
call RemoveLightningTimed( light, 0.1 )
call PauseTimer( TimerAct )
endif
else
call MoveLightningEx( light, true, casterX, casterY, casterZ, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetUnitZ( firstUnit ) )
call PlayEffect( "Abilities\\Weapons\\Bolt\\BoltImpact.mdl", GetUnitX( firstUnit ), GetUnitY( firstUnit ) )
call DamageUnit( caster, firstUnit, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
call GroupAddUnit( GroupTemp, firstUnit )
call GroupEnum( GroupAct, RadiusChain, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetBaseSpellFilter( caster ) )
loop
set pickedUnit = GroupPickRandomUnit( GroupAct )
exitwhen pickedUnit == null
if not IsUnitInGroup( pickedUnit, GroupTemp ) then
call RemoveLightningTimed( AddLightningEx( "CLSB", true, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetUnitZ( firstUnit ), GetUnitX( pickedUnit ), GetUnitY( pickedUnit ), GetUnitZ( pickedUnit ) ), 0.2 )
set firstUnit = pickedUnit
call DamageUnit( caster, pickedUnit, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
call GroupAddUnit( GroupTemp, firstUnit )
endif
call GroupRemoveUnit( GroupAct, pickedUnit )
endloop
call GroupClear( GroupTemp )
call FlushChildHashtable( Hash, id )
call RemoveLightningTimed( light, 0.1 )
call PauseTimer( TimerAct )
endif
set caster = null
set light = null
set pickedUnit = null
endfunction
private function Actions takes nothing returns nothing
local unit caster = GetSpellAbilityUnit( )
local real castX = GetSpellTargetX( )
local real castY = GetSpellTargetY( )
local real angle = GetCastAngle( caster, castX, castY )
local real casterX = GetPolarOffsetX( GetUnitX( caster ), 25, angle )
local real casterY = GetPolarOffsetY( GetUnitY( caster ), 25, angle )
local real casterZ = GetUnitZ( caster )
local integer id = GetHandleId( TimerAct )
local lightning light = AddLightningEx( "CLPB", true, casterX, casterY, casterZ, casterX, casterY, casterZ )
call SU( Hash, id, k_caster, caster )
call SR( Hash, id, k_angle, angle )
call SR( Hash, id, k_casterX, casterX )
call SR( Hash, id, k_casterY, casterY )
call SR( Hash, id, k_casterZ, casterZ )
call SR( Hash, id, k_distance, 0 )
call SL( Hash, id, k_lightning, light )
call TimerStart( TimerAct, TimerTick, true, function ActionsTimer )
set caster = null
set light = null
endfunction
private function Init takes nothing returns nothing
call NewTriggerPlayerUnitEvent( EVENT_PLAYER_UNIT_SPELL_EFFECT, function Conditions, function Actions )
endfunction
endscope
Принятый ответ
LastUchiha, код нормальный, я бы только этот момент поправил
call GroupAddUnit( GroupTemp, firstUnit )
call GroupEnum( GroupAct, RadiusChain, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetBaseSpellFilter( caster ) )
loop
set pickedUnit = GroupPickRandomUnit( GroupAct )
exitwhen pickedUnit == null
if not IsUnitInGroup( pickedUnit, GroupTemp ) then
call RemoveLightningTimed( AddLightningEx( "CLSB", true, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetUnitZ( firstUnit ), GetUnitX( pickedUnit ), GetUnitY( pickedUnit ), GetUnitZ( pickedUnit ) ), 0.2 )
set firstUnit = pickedUnit
call DamageUnit( caster, pickedUnit, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
call GroupAddUnit( GroupTemp, firstUnit )
endif
call GroupRemoveUnit( GroupAct, pickedUnit )
endloop
--->
call GroupEnum( GroupAct, RadiusChain, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetBaseSpellFilter( caster ) )
call GroupRemoveUnit( GroupAct, firstUnit )
loop
set bj_groupRandomConsidered = 0
set bj_groupRandomCurrentPick = null
call ForGroup( GroupAct, function GroupPickRandomUnitEnum)
exitwhen bj_groupRandomCurrentPick == null
call GroupRemoveUnit( GroupAct, bj_groupRandomCurrentPick )
call RemoveLightningTimed( AddLightningEx( "CLSB", true, GetUnitX( firstUnit ), GetUnitY( firstUnit ), GetUnitZ( firstUnit ), GetUnitX( bj_groupRandomCurrentPick ), GetUnitY( bj_groupRandomCurrentPick ), GetUnitZ( bj_groupRandomCurrentPick ) ), 0.2 )
call DamageUnit( caster, bj_groupRandomCurrentPick, 100, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC )
set firstUnit = bj_groupRandomCurrentPick
endloop
ну и надеюсь у тебя включена оптимизация кода, иначе очень хреново, что ты юзаешь вспомогательные функции, по сути создал свой арсенал близзардовских бжшек
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Ред. quq_CCCP
Отдельный код должен двигать молнию, отдельный искать цели и добавлять между ними разряды молний.
Стандартная молния ищет ближайшего видимого противника, к слову были же системы движения молний на сайте? Не?
Ниже кусок кода продвинутой дотки 6.83, цепная молния 1 в 1 как дефолт:
Ред. LastUchiha
А плавное сгасание делать через понижение непрозрачности?
Ред. LastUchiha
Но спасибо за пример!
Ред. LastUchiha
И где их лучше так сказать объявлять? Ну то есть в шапке карты можно создавать вариации структур?
И да видел я тоже во что они превращаются, глобальные массивы, а если таких массивом много накопится?
Стоит ли вообще об этом переживать?