• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Wall Spell

Status
Not open for further replies.
Level 5
Joined
Aug 15, 2007
Messages
145
Having trouble making units in a wall, this trigger bugs on the left side is made, is there a simpler way to make this? Please help me fix
JASS:
scope FIREWALL initializer Init 

globals
    private constant integer SPELL_ID = 'A044'
    private constant integer SPELLLEVEL = 'A031'
    private constant integer DUMMY = 'o001'
    private constant integer DUMMY2 = 'h00U'
    private constant integer DUMMY_SPELL = 'A03X'
    private constant integer DUMMY_SPELL2 = 'A00X'
endglobals

private function Conditions takes nothing returns boolean
    return GetSpellAbilityId() == SPELL_ID
endfunction

private function Actions takes nothing returns nothing
    local location t = GetSpellTargetLoc()
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real f = GetUnitFacing(u)
    local real dur = (4 * I2R(GetUnitAbilityLevel(u, SPELL_ID)))
    local real x = GetWidgetX( u )
    local real y = GetWidgetY( u )
    local unit d 
    local unit c
    local unit b
    local unit m
    local integer FirewallLeft 
    local integer FirewallRight 
    
    set d = CreateUnitAtLoc( p, DUMMY, t, f)
    call RemoveLocation( t)
    
    call SetUnitAbilityLevel(d, DUMMY_SPELL, SPELL_ID)
    call UnitApplyTimedLife( d, 'BTLF', dur )
    
    
    set FirewallRight = 1
    
    loop
        exitwhen FirewallRight > 3
        set t = GetSpellTargetLoc()
        set c= CreateUnitAtLoc( p, DUMMY, PolarProjectionBJ(t, ( I2R(FirewallRight) * 150.00 ),(f + 90  )), f)
        
        call RemoveLocation( t)
        call SetUnitAbilityLevel(c, DUMMY_SPELL, SPELL_ID)
        call UnitApplyTimedLife( c, 'BTLF', dur )
        set FirewallRight = FirewallRight+ 1
    endloop
    set FirewallLeft = 1
    loop
        exitwhen FirewallLeft > 3
        set t = GetSpellTargetLoc()
        set m= CreateUnitAtLoc( p, DUMMY, PolarProjectionBJ(t, ( I2R(FirewallRight) * 150.00 ),(f - 90  )), f)
        
        call RemoveLocation( t)
        call SetUnitAbilityLevel(m, DUMMY_SPELL, SPELL_ID)
        call UnitApplyTimedLife( m, 'BTLF', dur )
        
        set FirewallLeft = FirewallLeft + 1
        
        
    
    endloop
    
 if GetUnitAbilityLevel(u, SPELLLEVEL ) > 0 then
        set b = CreateUnit( p, DUMMY2, x, y, x)
        
        call SetUnitInvulnerable( b, true )
        call UnitAddAbility(b, DUMMY_SPELL2)
        call SetUnitAbilityLevel(b , DUMMY_SPELL2, SPELLLEVEL)
        call UnitApplyTimedLife( b, 'BTLF', dur )
        
        
endif
    set c= null
        set d= null
        set m= null 
        set p = null
   set b= null
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger t = CreateTrigger(  )
		local integer i = 0
		
		loop
			exitwhen i > 11
			call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
			set i = i + 1
		endloop

		call TriggerAddCondition( t, Condition( function Conditions ) )
		call TriggerAddAction( t, function Actions )
		
		set t = null
	endfunction
    
endscope
 
Level 7
Joined
Mar 8, 2009
Messages
360
Remove all
JASS:
set t = GetSpellTargetLoc()
they put the same location there anyway
And place the removeloc(t) at the end of the function. They always remove the same location anyway.

EDIT: I edited you function a bit but its possible that it doesn't do what you want, if it does what you want then use it because its much more efficient then you function.
JASS:
private function Actions takes nothing returns nothing
    local location t = GetSpellTargetLoc()
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local real f = GetUnitFacing(u)
    local real dur = (4 * I2R(GetUnitAbilityLevel(u, SPELL_ID)))
    local real x = GetWidgetX( u )
    local real y = GetWidgetY( u )
    local unit d
    local integer Firewall = -3

    loop
        exitwhen Firewall > 3
        set d = CreateUnitAtLoc(p, DUMMY, PolarProjectionBJ(t, ( I2R(Firewall) * 150.00 ),(f + 90 )), f)

        call SetUnitAbilityLevel(d, DUMMY_SPELL, SPELL_ID)
        call UnitApplyTimedLife(d, 'BTLF', dur)
        set Firewall = Firewall+ 1
    endloop

    if GetUnitAbilityLevel(u, SPELLLEVEL ) > 0 then
        set d = CreateUnit( p, DUMMY2, x, y, x)

        call SetUnitInvulnerable( d, true )
        call UnitAddAbility(d, DUMMY_SPELL2)
        call SetUnitAbilityLevel(d , DUMMY_SPELL2, SPELLLEVEL)
        call UnitApplyTimedLife(d, 'BTLF', dur)
    endif
    
    call RemoveLocation( t)
    set t = null
    set d = null
    set p = null
endfunction
There are still much location leaks in it.
 
Last edited:
Level 4
Joined
Nov 7, 2009
Messages
83
JASS:
    set FirewallLeft = 1
    loop
        exitwhen FirewallLeft > 3
        set t = GetSpellTargetLoc()
        set m= CreateUnitAtLoc( p, DUMMY, PolarProjectionBJ(t, ( I2R(FirewallRight) * 150.00 ),(f - 90 )), f)

        call RemoveLocation( t)
        call SetUnitAbilityLevel(m, DUMMY_SPELL, SPELL_ID)
        call UnitApplyTimedLife( m, 'BTLF', dur )

        set FirewallLeft = FirewallLeft + 1
You were working with firewall left and you have this part
JASS:
set m= CreateUnitAtLoc( p, DUMMY, PolarProjectionBJ(t, ( I2R(FirewallRight) * 150.00 ),(f - 90 )), f)
so, if you did the same in you function, I think that Firewall right in the Firewall left part may have coused your initial trouble
 
Level 11
Joined
Apr 6, 2008
Messages
760
Here is something i found on Wc3c

JASS:
scope Wall initializer Init

    globals
        private constant integer ABILITY_ID = 'AOsh'
        private constant integer UNIT_TYPE_ID = 'hpea'
    endglobals
    
    private constant function WallLength takes integer lvl returns real
        return 600.+lvl*100.
    endfunction
    
    private constant function NumberOfUnits takes integer lvl returns integer
        return 5+lvl
    endfunction
    
    //===========================================================================
    private function Conditions takes nothing returns boolean
        return GetSpellAbilityId() == ABILITY_ID
    endfunction

    private function Actions takes nothing returns nothing
        local location l = GetSpellTargetLoc()
        local unit u = GetSpellAbilityUnit()
        local player p = GetOwningPlayer(u)
        local integer i = 0
        local integer lvl = GetUnitAbilityLevel(u, ABILITY_ID)
        local integer n = NumberOfUnits(lvl)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real tx = GetLocationX(l)
        local real ty = GetLocationY(l)
        local real angle = Atan2(ty-y, tx-x)
        local real d = WallLength(lvl)
        set x = Cos(angle+bj_PI/2)*d
        set y = Sin(angle+bj_PI/2)*d
        set tx = tx+x/2
        set ty = ty+y/2
        set x = x/(n-1)
        set y = y/(n-1)
        
        loop
            exitwhen i >= n
            call CreateUnit(p, UNIT_TYPE_ID, tx, ty, angle*bj_RADTODEG)
            set tx = tx-x
            set ty = ty-y
            set i = i + 1
        endloop
        
        call RemoveLocation(l)
        set l = null
        set u = null
    endfunction

    //===========================================================================
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0

        loop
            call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
            set i = i+1
            exitwhen i > 15
        endloop

        call TriggerAddCondition(t, Condition(function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction

endscope
 
Status
Not open for further replies.
Top