вот впринципе изначальный
scope Bow initializer Init
private struct Bow
unit u
real count = 0
real max
integer level
real cos
real sin
endstruct
globals
//Configuration
private constant integer ID = 'A000'
private constant integer DummyID = 'h000'
private constant string Stampede = "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl"
private constant real Interval = 0.05//This is the interval of the spell. Try to find a balance between accuracy and efficiency.
private constant real Speed = 700
private constant real Distance = Speed * Interval//This is the the distance the Bow moves per interval.
private constant attacktype AT = ATTACK_TYPE_NORMAL
private constant damagetype DT = DAMAGE_TYPE_FIRE
private constant weapontype WT = WEAPON_TYPE_WHOKNOWS
private constant real TravelDistance=2000
//Don't touch this stuff unless you know what you're doing
private boolexpr filter
private group Group = CreateGroup()
private timer Tim = CreateTimer()
private Bow array queue
private integer total = 0
private player BowOwner
endglobals
private constant function Damage takes integer level returns real
return level * 60. + 100.
endfunction
private function Bow_Timer takes nothing returns nothing
local integer i = 0
local Bow data
local unit f
local real damage
local boolean shoot=true
loop
exitwhen i >= total
set data = queue[i]
set data.count =data.count+1
call SetUnitX(data.u, GetUnitX(data.u) + data.cos)
call SetUnitY(data.u, GetUnitY(data.u) + data.sin)
set BowOwner = GetOwningPlayer(data.u)
call GroupClear(Group)
call GroupEnumUnitsInRange(Group, GetUnitX(data.u), GetUnitY(data.u), 100, filter)
if FirstOfGroup(Group) != null or data.count>=data.max then
call DestroyEffect(AddSpecialEffect(Stampede, GetUnitX(data.u), GetUnitY(data.u)))
call KillUnit(data.u)
set damage = Damage(data.level)
loop
set f = FirstOfGroup(Group)
exitwhen shoot==false
call UnitDamageTarget(data.u, f, damage, true, false, AT, DT, WT)
call GroupRemoveUnit(Group, f)
set shoot=false
endloop
call data.destroy()
set total = total - 1
set queue[i] = queue[total]
set i = i - 1
endif
set i = i + 1
endloop
if total == 0 then
call PauseTimer(Tim)
endif
set f = null
endfunction
private function Bow_Conditions takes nothing returns boolean
return GetSpellAbilityId() == ID
endfunction
private function Bow_Filter takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0. and IsUnitEnemy(GetFilterUnit(), BowOwner) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)//Makes it only work on units (not structures) and living units.
endfunction
private function Bow_Actions takes nothing returns nothing
local Bow data = Bow.create()
local unit u = GetTriggerUnit()//Stores the caster in a variable.
local location l = GetSpellTargetLoc()//Stores the target location of the spell.
local real x = GetUnitX(u)//Stores the x of the caster.
local real y = GetUnitY(u)//Stores the y of the caster.
local real dx = GetLocationX(l) - x
local real dy = GetLocationY(l) - y
local real atan2 = Atan2(dy, dx)
set data.level = GetUnitAbilityLevel(u, ID)//Stores the level of the ability in a struct.
set data.max = TravelDistance/Distance//Calculates the number of executions required by the timer.
set data.u = CreateUnit(GetOwningPlayer(u), DummyID, x, y, atan2*bj_RADTODEG)//Stores the Bow in a struct.
set data.cos = Distance * Cos(atan2)
set data.sin = Distance * Sin(atan2)
call SetUnitPathing(data.u, false)//Sets the Bow's pathing to none.
call PauseUnit(data.u, true)
call RemoveLocation(l)//Prevents the location from leaking.
if total == 0 then
call TimerStart(Tim, Interval, true, function Bow_Timer)
endif
set queue[total] = data
set total = total + 1
set u = null//local
set l = null//variables
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()//Creates the trigger.
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EFFECT)//Adds the event.
call TriggerAddCondition(t, Condition(function Bow_Conditions))//Adds the condition.
call TriggerAddAction(t, function Bow_Actions)//Adds the action.
call Preload(Stampede)//Preloads the effect, preventing it from lagging the first time it's cast.
set filter = Filter(function Bow_Filter)//Stores a global boolexp. Much faster than creating and destroying one all the time.
endfunction
endscope
хочу теперь узнать, почему в данном коде local moving data работает без инициализации? Я однозначно чего-то непонимаю..
Sres, я сегодня не могу, зайду завтра))
как с новым форматированием сделать нормальный код под катом?