- Joined
- Aug 26, 2016
- Messages
- 139
After some time after using this code the game crashes.
JASS:
library SPASLib
native UnitAlive takes unit id returns boolean
function GetLocZSPAS takes real x, real y returns real
call MoveLocation( LFZ, x, y )
return GetLocationZ( LFZ )
endfunction
struct vectorSPAS
real x
real y
real z
method normalize takes nothing returns nothing
local real l = SquareRoot( x * x + y * y + z * z )
if l == 0.00 then
set l = 1.00
endif
set x = x * ( 1.00 / l )
set y = y * ( 1.00 / l )
set z = z * ( 1.00 / l )
endmethod
static method create takes real x, real y, real z returns thistype
local thistype this = thistype.allocate( )
set this.x = x
set this.y = y
set this.z = z
call this.normalize( )
return this
endmethod
endstruct
struct bulletSPAS
unit caster
unit dummy
player p
real x
real y
real z
real s // speed
real d // distance
real r // radius
vectorSPAS v
endstruct
function MoveSPAS takes nothing returns nothing
local bullet A = LoadInteger( H, GetHandleId( GetExpiredTimer( ) ), 0 )
local unit u
local string BloodEffect = "Objects/Spawnmodels/Undead/UndeadBlood/UndeadBloodAcolyte.mdl"
set A.x = A.x + A.s * A.v.x * Cos( A.v.z )
set A.y = A.y + A.s * A.v.y * Cos( A.v.z )
set A.z = A.z + A.s * A.v.z
set A.d = A.d - A.s
call SetUnitX( A.dummy, A.x )
call SetUnitY( A.dummy, A.y )
call SetUnitFlyHeight( A.dummy, A.z - GetLocZSPAS( A.x, A.y ), 0.00 )
call GroupEnumUnitsInRange( TempGroup, A.x, A.y, A.r, null )
loop
set u = FirstOfGroup( TempGroup )
exitwhen u == null
call GroupRemoveUnit( TempGroup, u )
if UnitAlive( u ) and IsUnitEnemy( u, A.p ) and RAbsBJ( GetUnitFlyHeight( u ) - GetUnitFlyHeight( A.dummy ) ) <= 100.00 then
call GroupClear( TempGroup )
call UnitDamageTarget( A.caster, u, 40.00, false, false, null, null, null )
call DestroyEffect( AddSpecialEffectTarget( BloodEffect, u, "origin" ) )
call RemoveUnit( A.dummy )
set BloodEffect = null
call DestroyTimer( GetExpiredTimer( ) )
call FlushChildHashtable( H, GetHandleId( GetExpiredTimer( ) ) )
call DestroyTimer( GetExpiredTimer( ) )
set A.dummy = null
set A.caster = null
call A.v.destroy( )
call A.destroy( )
endif
endloop
if A.d <= 0.00 or A.z - GetLocZSPAS( A.x, A.y ) <= 20.00 then
call PauseTimer( GetExpiredTimer( ) )
call FlushChildHashtable( H, GetHandleId( GetExpiredTimer( ) ) )
call DestroyTimer( GetExpiredTimer( ) )
call RemoveUnit( A.dummy )
set A.dummy = null
set A.caster = null
call A.v.destroy( )
call A.destroy( )
endif
endfunction
function Trig_ShootSPAS_Actions takes nothing returns nothing
local timer t = CreateTimer( )
local unit Target = udg_Camera[GetConvertedPlayerId(GetTriggerPlayer())]
local bullet A = bullet.create( )
local real x = GetUnitX(Target)
local real y = GetUnitY(Target)
local real z = GetLocZSPAS( x, y ) + 50.00
local string WeaponEffect = "RifleImpact.mdx"
local string WeaponEffect2 = "war3mapImported/RiflemanSpas.mdx"
local integer i = 10
call SetItemCharges( GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00K'), ( GetItemCharges(GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00K')) - 1 ) )
loop
set t = CreateTimer( )
set A = bullet.create( )
set A.caster = udg_MainHero_2[GetConvertedPlayerId(GetTriggerPlayer())]
set A.p = GetOwningPlayer( A.caster )
// for offset
set A.x = GetUnitX( A.caster )
set A.y = GetUnitY( A.caster )
set A.z = GetUnitFlyHeight( A.caster ) + GetLocZSPAS( A.x, A.y ) + 110.00
set A.v = vector.create( x - A.x, y - A.y, z - A.z )
set A.x = A.x + 76.00 * A.v.x * Cos( A.v.z )
set A.y = A.y + 76.00 * A.v.y * Cos( A.v.z )
set A.z = GetUnitFlyHeight( A.caster ) + GetLocZSPAS( A.x, A.y ) + 110.00
// for move
set A.v.x = x - A.x
set A.v.y = y - A.y
set A.v.z = z - A.z
call A.v.normalize( )
set A.v.x = A.v.x + GetRandomReal( -0.15, 0.15 )
set A.v.y = A.v.y + GetRandomReal( -0.15, 0.15 )
set A.v.z = A.v.z
set A.d = 5200.00
set A.s = 1500.00 * 0.03125
set A.r = 70.00
set A.dummy = CreateUnit( A.p, 'u000', A.x, A.y, Atan2( A.v.y, A.v.x ) * bj_RADTODEG )
call SetUnitPathing( A.dummy, false )
call UnitAddAbility( A.dummy, 'Arav' )
call SetUnitX( A.dummy, A.x )
call SetUnitY( A.dummy, A.y )
call SetUnitFlyHeight( A.dummy, A.z - GetLocZSPAS( A.x, A.y ), 0.00 )
call BlzStartUnitAbilityCooldown( udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'A01Z', 0.22 )
call SaveInteger( H, GetHandleId( t ), 0, A )
call TimerStart( t, 0.02, true, function MoveSPAS )
set i = i - 1
exitwhen i <= 0
endloop
call DestroyEffect( AddSpecialEffectTarget( WeaponEffect, A.caster, "weapon" ) )
call DestroyEffect( AddSpecialEffectTarget( WeaponEffect2, A.caster, "weapon" ) )
set t = null
set WeaponEffect = null
set WeaponEffect2 = null
set Target = null
call IssueImmediateOrderBJ( udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], "stop" )
endfunction
//===========================================================================
function ShootSPAS_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A01Z' ) ) then
return false
endif
if ( not ( GetItemCharges(GetItemOfTypeFromUnitBJ(udg_MainHero[GetConvertedPlayerId(GetTriggerPlayer())], 'I00K')) != 0 ) ) then
return false
endif
return true
endfunction
function InitTrig_ShootSPAS takes nothing returns nothing
local trigger t11 = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t11, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddCondition( t11, Condition( function ShootSPAS_Conditions ) )
call TriggerAddAction( t11, function Trig_ShootSPAS_Actions )
set t11 = null
endfunction
endlibrary