• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Gost's Jass Questions - Continualy Updated

Status
Not open for further replies.
Level 10
Joined
Jan 21, 2007
Messages
576
Alright I learned a little bit of jass about 4 months ago and then I dropped off the wc3 radar for a bit, and now I'm back. I am using JNGP to grow my vJass knowledge. I am pretty competent in making spells, they are usualy pretty straight-forward but right now I am trying to create the trigger that does everything I need to be done at map init. Here is what I have so far:

JASS:
scope Init initializer Init
    private function spawnCreeps takes nothing returns nothing
        call CreateNUnitsAtLoc(5, 'nban', Player(11), TLWS, 90)
        call CreateNUnitsAtLoc(5, 'nban', Player(11), BLWS, 90)
        call CreateNUnitsAtLoc(5, 'nban', Player(11), MLWS, 90)
        call CreateNUnitsAtLoc(5, 'nban', Player(11), TRWS, 90)
        call CreateNUnitsAtLoc(5, 'nban', Player(11), BRWS, 90)
        call CreateNUnitsAtLoc(5, 'nban', Player(11), MRWS, 90)
        call BJDebugMsg("Units should have spawned if so, hurray! If not, bug the forums")
    endfunction
    
    private function Actions takes nothing returns nothing
        local timer creepwave = CreateTimer()
        call ModifyGateBJ( bj_GATEOPERATION_OPEN, gg_dest_B000_0298 )
        call ModifyGateBJ( bj_GATEOPERATION_OPEN, gg_dest_B000_4544 )
        call SetDestructableInvulnerableBJ( gg_dest_DTg6_1783, true )
        call PolledWait(120.00)
        call TimerStart(creepwave, 35, true, spawnCreeps)
        call BJDebugMsg("Actions Completed, timer should have started..")
    endfunction
    
//===========================================================================

    function Init takes nothing returns nothing
        local trigger InitTrg = CreateTrigger()
        call TriggerAddAction( InitTrg, function Actions )
        globals
            location TLWS = Location(-8315.1,1944.3)
            location BLWS = Location(-8344.3,-891.7)
            location MLWS = Location(-7231.6,556.9)
            location TRWS = Location(8219.5,1978.9)
            location BRWS = Location(8256.9,-847)
            location MRWS = Location(7277.7,556.3)
        endglobals
    endfunction
endscope

I looked for natives to replace the BJ's, but I couldn't find any so I assume that is the best way to go about those? As for that timer, I am not very sure of my timer knowledge, but I think I did that correctly as well. But the compiler seems to be having trouble with his line:
JASS:
call TimerStart(creepwave, 35, true, spawnCreeps)
Throwing the error: Cannot convert integer to code. Does anyone know whats wrong with that?

Edit: When I try and tack on "constant" before those location variables it throws all sorts of various errors, why cant I make those constant?

(I realize some of this stuff is pretty annoyingly simple to answer but bear with me) I suppose the real question behind all of these ^ is, is this code written in the fastest/most efficient, and correct way? (I'm gonna take a shot in the dark and say no =p, thats why I am here though)

(I will keep using this thread to ask questions, that will vary a lot, but all be vJass related as oppose to flooding the whole forum with threads. So make sure to check back every now and then.)
 
Level 8
Joined
Feb 15, 2009
Messages
463
Do it like

JASS:
scope Init initializer Init

    private function spawnCreeps takes nothing returns nothing
        local integer a = 0

        loop
            set a = a+1
            exitwhen a > 5
                call CreateUnit( Player(11) , 'nban', -8315.1 , 1944.3 , 0. )
        endloop
// The location's value in coordinates are used here
    endfunction
    
    private function Actions takes nothing returns nothing
        local timer creepwave = CreateTimer()

        call SetDestructableAnimation(gg_dest_B000_0298 , "death alternate")
        call SetDestructableAnimation(gg_dest_B000_4544 , "death alternate")

        call SetDestructableInvulnerable( gg_dest_DTg6_1783 , true )

        call PolledWait(120.00)

        call TimerStart(creepwave, 35. , true, function spawnCreeps)

    endfunction
    
//===========================================================================

    function Init takes nothing returns nothing
        local trigger InitTrg = CreateTrigger()
        call TriggerRegisterTimerEvent( InitTrig , 0.01 , false  )
        call TriggerAddAction( InitTrg, function Actions )
    endfunction
endscope


If ypu want to see with what a BJ is replaced then go for CTRL + left mouseklick while coding on a BJ
 
1. You can't declare globals inside functions (I think). You must declare the globals at the beginning of the code.

2. That Actions function is never called. Either use TriggerRegisterTimerEvent or simply make the actions happen on init and abandon having a trigger.

3. You Init function should be private, since what happens if want init functions for other scopes/libraries?

4. call TimerStart(creepwave, 35, true, spawnCreeps) should be call TimerStart(creepwave, 35, true, function spawnCreeps). vJass gives the error about an integer because you can save functions as integer variables and do operations on them later.

5. SetDestructibleInvulnerableBJ should be just SetDestructableInvulnerable. The BJ just calls the native, so you don't need it.

6. You should replace ModifyGateBJ with:

JASS:
if (GetDestructableLife(<YourGate>) > 0) then
            call KillDestructable(<YourGate>)
        endif
        call SetDestructableAnimation(<YourGate>, "death alternate")
. This is taken from the certain section of the BJ concerned with opening gates. I suggest using a textmacro.

7. Since we now got rid of using a trigger, PolledWait no longer works. Replace it with a timer.

8. CreateNUnitsAtLoc is not good to use. It is quite inefficient since it handles bj_lastCreatedGroup as well as creating the units. Replace it with a loop.

9. You can't have constant handles. Locations are handles. I suggest replacing them with real coordinates for efficiency.

So the final, working code is:
JASS:
//! textmacro OpenGate takes GATE
if (GetDestructableLife($GATE$) > 0) then
    call KillDestructable($GATE$)
endif
call SetDestructableAnimation($GATE$, "death alternate")
//! endtextmacro

scope Init initializer Init
    globals
        constant real TLWS_X = -8315.1
        constant real TLWS_Y = 1944.3
        
        constant real BLWS_X = -8344.3
        constant real BLWS_Y = -891.7
        
        constant real MLWS_X = -7231.6
        constant real MLWS_Y = 556.9
        
        constant real TRWS_X = 8219.5
        constant real TRWS_Y = 1978.9
        
        constant real BRWS_X = 8256.9
        constant real BRWS_Y = -847
        
        constant real MRWS_X = 7277.7
        constant real MRWS_Y = 556.3
    endglobals
    
    private function spawnCreeps takes nothing returns nothing
        local integer i = 0
        loop
            exitwhen i >= 5
            call CreateUnit(Player(11), 'nban', TLWS_X, TLWS_Y, 90)
            call CreateUnit(Player(11), 'nban', BLWS_X, BLWS_Y, 90)
            call CreateUnit(Player(11), 'nban', MLWS_X, MLWS_Y, 90)
            call CreateUnit(Player(11), 'nban', TRWS_X, TRWS_Y, 90)
            call CreateUnit(Player(11), 'nban', BRWS_X, BRWS_Y, 90)
            call CreateUnit(Player(11), 'nban', MRWS_X, MRWS_Y, 90)
            set i = i + 1
        endloop
        call BJDebugMsg("Units should have spawned if so, hurray! If not, bug the forums")
    endfunction
    
    private function StartSpawning takes nothing returns nothing
        local timer creepwave = CreateTimer()
        call TimerStart(creepwave, 35, true, function spawnCreeps)
        call BJDebugMsg("Actions Completed, timer should have started..")
        call DestroyTimer(GetExpiredTimer())
        set creepwave = null
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        //! runtextmacro OpenGate("gg_dest_B000_0298")
        //! runtextmacro OpenGate("gg_dest_B000_4544")
        call SetDestructableInvulnerable( gg_dest_DTg6_1783, true )
        call TimerStart(t, 120.00, false, function StartSpawning)
        set t = null
    endfunction
endscope
 
Level 10
Joined
Jan 21, 2007
Messages
576
Why do you delay the trigger from firing till .01 seconds? Does it help performence?

EDIT: Bleh, looking over elements changes now =p
 
Level 10
Joined
Jan 21, 2007
Messages
576
JASS:
//! textmacro OpenGate takes GATE
if (GetDestructableLife($GATE$) > 0) then
    call KillDestructable($GATE$)
endif
call SetDestructableAnimation($GATE$, "death alternate")
//! endtextmacro

//! runtextmacro OpenGate("gg_dest_B000_0298")
//! runtextmacro OpenGate("gg_dest_B000_4544")

Alright I understand everything your jass code does except little bits of this. If the gates life is greater then 0, kill it? and then change its animation to death alternate. I understand the animation part, but would killing the gate.... kill it? Removing the pathing under the pillars, in addition to allowing you to walk through the center? Or is there something about gates that I don't know, or am I just not understanding the functions you are using =|?
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright I trust you =p, could I avoid the whole .01 timer deal by just getting rid of that, and the trigger creation etc. and placing the code within the map header? Rather, how would I go about getting something to run on map init?
 
Level 10
Joined
Jan 21, 2007
Messages
576
:O...... :S. I feel stupid hah, I glanced at the bottom of the wrong code and assumed. Is there a way to add movement orders to a units order queue, or something the like? Or am I going to have to use regions to get my spawned units to travel along a path? (I ctrl+f'd the tut section and didn't see anything on this, so I figured it would be quick to ask you then to go in search of a jass map with understandable coding of what I want to do)

EDIT: Out for the night, I guess tomorrow I will start going through maps seeing how they went about this if noone responds.
 
Level 10
Joined
Jan 21, 2007
Messages
576
There are 3 different points it has to go to though, I don't think you understand what I mean.

The units spawn at the red X, I need them to follow only the path, i.e. the orange dots, if I just order them to go to the last one from where they spawn they will cut through a forest.

Rofl, you understood anyways, but my image errored out and didn't attach, I didn't realize till now.
 

Attachments

  • Example.jpg
    Example.jpg
    13.9 KB · Views: 82
Level 10
Joined
Jan 21, 2007
Messages
576
And would I have to make a trigger for each region? The different events being unit enters X region, unit enters Y region, etc. etc.
 
Level 6
Joined
May 7, 2009
Messages
228
I have a question

Which events is it possible for observers to trigger, if any
I already know chat events don't work for them but I was wondering if there were any events at all so I could do a work around
 
Level 10
Joined
Jan 21, 2007
Messages
576
JASS:
//! textmacro OpenGate takes GATE
if (GetDestructableLife($GATE$) > 0) then
    call KillDestructable($GATE$)
endif
call SetDestructableAnimation($GATE$, "death alternate")
//! endtextmacro

scope Init initializer Init
    globals
        constant real TLWS_X = -8315.1
        constant real TLWS_Y = 1944.3

        constant real BLWS_X = -8344.3
        constant real BLWS_Y = -891.7

        constant real MLWS_X = -7231.6
        constant real MLWS_Y = 556.9

        constant real TRWS_X = 8219.5
        constant real TRWS_Y = 1978.9

        constant real BRWS_X = 8256.9
        constant real BRWS_Y = -847

        constant real MRWS_X = 7277.7
        constant real MRWS_Y = 556.3
    endglobals

    private function spawnCreeps takes nothing returns nothing
        local integer i = 0
        call BJDebugMsg("Spawn")
        loop
            exitwhen i >= 5
            call IssuePointOrder(CreateUnit(Player(11), 'nban', TLWS_X, TLWS_Y, 90), "attackmove", -8158.1, 6632.8)
            call IssuePointOrder(CreateUnit(Player(11), 'nban', BLWS_X, BLWS_Y, 90), "attackmove", -8030.5, -5530.2)
            call IssuePointOrder(CreateUnit(Player(11), 'nban', MLWS_X, MLWS_Y, 90), "attackmove", 8415.3, -511.6)
            call IssuePointOrder(CreateUnit(Player(11), 'nban', TRWS_X, TRWS_Y, 90), "attackmove", 7421.5, 7458.5)
            call IssuePointOrder(CreateUnit(Player(11), 'nban', BRWS_X, BRWS_Y, 90), "attackmove", 8321.5, -5444.4)            
            call IssuePointOrder(CreateUnit(Player(11), 'nban', MRWS_X, MRWS_Y, 90), "attackmove", -8365.7, 516.1)
            set i = i + 1
        endloop
    endfunction

    private function StartSpawning takes nothing returns nothing
        local timer creepwave = CreateTimer()
        call BJDebugMsg("First timer completed, second timer started")
        call TimerStart(creepwave, 10, true, function spawnCreeps)
        call DestroyTimer(GetExpiredTimer())
        set creepwave = null
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        //! runtextmacro OpenGate("gg_dest_B000_0298")
        //! runtextmacro OpenGate("gg_dest_B000_4544")
        call SetDestructableInvulnerable( gg_dest_DTg6_1783, true )
        call BJDebugMsg("First Timer Started")
        call TimerStart(t, 1.00, false, function StartSpawning)
        set t = null
    endfunction
endscope

The spawned units don't go anywhere =/

And yes this is a thread for all of my jass questions, not other peoples.
 
Level 10
Joined
Jan 21, 2007
Messages
576
EDIT: Changed it to this
JASS:
//! textmacro OpenGate takes GATE
if (GetDestructableLife($GATE$) > 0) then
    call KillDestructable($GATE$)
endif
call SetDestructableAnimation($GATE$, "death alternate")
//! endtextmacro

scope Init initializer Init
    globals
        constant real TLWS_X = -8315.1
        constant real TLWS_Y = 1944.3

        constant real BLWS_X = -8344.3
        constant real BLWS_Y = -891.7

        constant real MLWS_X = -7231.6
        constant real MLWS_Y = 556.9

        constant real TRWS_X = 8219.5
        constant real TRWS_Y = 1978.9

        constant real BRWS_X = 8256.9
        constant real BRWS_Y = -847

        constant real MRWS_X = 7277.7
        constant real MRWS_Y = 556.3
    endglobals

    private function spawnCreeps takes nothing returns nothing
        local integer i = 0
        local unit u
        call BJDebugMsg("Spawn")
        loop
            exitwhen i >= 5
            set u = CreateUnit(Player(11), 'nban', TLWS_X, TLWS_Y, 90)
            call SetUnitUserData( u, 1 )
            call IssuePointOrder(u, "attack", -8158.1, 6632.8)
            
            set u = CreateUnit(Player(11), 'nban', BLWS_X, BLWS_Y, 90)
            call SetUnitUserData( u, 2 )
            call IssuePointOrder(u, "attack", -8030.5, -5530.2)
            
            set u = CreateUnit(Player(11), 'nban', MLWS_X, MLWS_Y, 90)
            call IssuePointOrder(u, "attack", 8443.9, 492.3)
            
            set u = CreateUnit(Player(11), 'nban', TRWS_X, TRWS_Y, 90)
            call SetUnitUserData( u, 3 )
            call IssuePointOrder(u, "attack", 7421.5, 7458.5)
            
            set u = CreateUnit(Player(11), 'nban', BRWS_X, BRWS_Y, 90)
            call SetUnitUserData( u, 4 )
            call IssuePointOrder(u, "attack", 8321.5, -5444.4)  
            
            set u = CreateUnit(Player(11), 'nban', MRWS_X, MRWS_Y, 90)
            call IssuePointOrder(u, "attack", -8365.7, 516.1)
            set i = i + 1
        endloop
    endfunction

    private function StartSpawning takes nothing returns nothing
        local timer creepwave = CreateTimer()
        call BJDebugMsg("First timer completed, second timer started")
        call TimerStart(creepwave, 10, true, function spawnCreeps)
        call DestroyTimer(GetExpiredTimer())
        set creepwave = null
    endfunction

    private function Init takes nothing returns nothing
        local timer t = CreateTimer()
        //! runtextmacro OpenGate("gg_dest_B000_0298")
        //! runtextmacro OpenGate("gg_dest_B000_4544")
        call SetDestructableInvulnerable( gg_dest_DTg6_1783, true )
        call BJDebugMsg("First Timer Started")
        call TimerStart(t, 1.00, false, function StartSpawning)
        set t = null
    endfunction
endscope
And it works now, the move order is "attack" not "attackmove".

EDIT: Is there a boolean/condition that checks if a unit is doing something (attacking, or moving) or if the unit is idle (just standing in place not moving or doing anything.)? The reason I ask is because I am currently wrting out the waypoint code to get my units to move
JASS:
scope WaypointSystem initializer Init
    function Actions takes nothing returns nothing
        call PolledWait(.25)
    //================================Enter Bottom Left==========================
        if  (RectContainsLoc(gg_rct_WaypointBL, GetUnitLoc(GetTriggerUnit())) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 2) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 8208, -5264)
                call SetUnitUserData( GetTriggerUnit(), 6 )
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 8) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                        endif
            endif
        endif
    //================================Enter Bottom Right=========================   
        if  (RectContainsLoc(gg_rct_WaypointBR, GetUnitLoc(GetTriggerUnit())) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 4) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8112, -5392)
                call SetUnitUserData( GetTriggerUnit(), 8 ) 
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 6) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                        endif
            endif
        endif
    //================================Enter Top Right============================   
        if  (RectContainsLoc(gg_rct_WaypointTR, GetUnitLoc(GetTriggerUnit())) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 3) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8176, 6560)
                call SetUnitUserData( GetTriggerUnit(), 7 ) 
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 5) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                        endif
            endif
        endif
    //================================Enter Top Left=============================
        if  (RectContainsLoc(gg_rct_WaypointTL, GetUnitLoc(GetTriggerUnit())) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 1) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 7248, 7280)
                call SetUnitUserData( GetTriggerUnit(), 5 )
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 7) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                        endif
            endif
        endif
    //===========================================================================  
    endfunction
    
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger WaypointSystemTrg = CreateTrigger()
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBR)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTR)
        call TriggerAddCondition( WaypointSystemTrg, Condition( function Conditions ) )
        call TriggerAddAction( WaypointSystemTrg, function Actions )
    endfunction
endscope

But every now and then when a unit runs into the back of another unit and has to 'stutterstep' while they are in/near the region, one of the units sometimes just stops and sits in that region not moving on, obeying its order >=/. Anyone know whatsup with that? Otherwise I am pretty proud of that code, wrote that one by myself lol =p

EDIT: The problem seemed to be merely the super-finicky way the wc3 engine handles unit move orders, I just moved the region over a bit etc. and now it works flawlessly without any clumps.. so far =p.
 
Last edited:
Level 10
Joined
Jan 21, 2007
Messages
576
Well I would like to improve this to perfection because it will be an a map I am making, but if someone posts the whole fixed code and I copy it I won't learn anything, rather pointers as to what to and if I am doing things right or wrong are a lot more helpful.

JASS:
scope WaypointSystem initializer Init
    function command takes nothing returns nothing
        //==========================Enter Bottom Left========================
        local location l = GetUnitLoc(GetTriggerUnit())
        if  (RectContainsLoc(gg_rct_WaypointBL, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 2) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 8208, -5264)
                call SetUnitUserData( GetTriggerUnit(), 6 )
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 8) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                        endif
            endif
        endif
        //==========================Enter Bottom Right=======================   
        if  (RectContainsLoc(gg_rct_WaypointBR, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 4) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8112, -5392)
                call SetUnitUserData( GetTriggerUnit(), 8 ) 
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 6) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                        endif
            endif
        endif
        //==========================Enter Top Right==========================   
        if  (RectContainsLoc(gg_rct_WaypointTR, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 3) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8176, 6560)
                call SetUnitUserData( GetTriggerUnit(), 7 ) 
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 5) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                        endif
            endif
        endif
        //==========================Enter Top Left===========================
        if  (RectContainsLoc(gg_rct_WaypointTL, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 1) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 7248, 7280)
                call SetUnitUserData( GetTriggerUnit(), 5 )
                    else
                        if (GetUnitUserData(GetTriggerUnit()) == 7) then
                            call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                        endif
            endif
        endif
        call RemoveLocation(l)
    endfunction
 //===========================================================================    
    function Actions takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, .25, false, function command)
    endfunction
//===========================================================================     
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger WaypointSystemTrg = CreateTrigger()
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBR)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTR)
        call TriggerAddCondition( WaypointSystemTrg, Condition( function Conditions ) )
        call TriggerAddAction( WaypointSystemTrg, function Actions )
    endfunction
endscope
I got rid of the location leak (should I set the location = null after I remove it or is that unnecessary? I am unsure of when to '= null' things. Would it be more effective / faster to put all of the region checking and order issuing part of the code in one big if then else?

EDIT: Fixed the syntex of the timer in the actiosn function. Put actions below commmand, so it would call correctly.
 
What you should really do is have those regions in a big array and loop through them. It makes your code much easier to read with many less lines. Also, learn to indent properly. Read this.

Two more things:
-You once again forgot to put the function in before the name of the function in TimerStart.
-GetTriggerUnit() won't work after the timer callback. You need to either attach the unit to the timer or just use PolledWait instead of the timer.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Yea I do that quite a bit =/, but I fixed it before I read your post =p.

As for the attaching a unit to the timer, how do I go about doing that o_O. Sounds like something a tutorial would be better then having you slave over explaining it to me. If you know a good tut link it otherwise I'm gonna go searching.

I am not sure how I am going to do what I did with a loop, but I while trial and error that after I read over that indenting tut. I was kinda just going off what I would do in actionscript for flash.
 
As for the attaching a unit to the timer, how do I go about doing that o_O. Sounds like something a tutorial would be better then having you slave over explaining it to me. If you know a good tut link it otherwise I'm gonna go searching.
Nah, I can't find a tut. Just use PolledWait for now.

I am not sure how I am going to do what I did with a loop, but I while trial and error that after I read over that indenting tut. I was kinda just going off what I would do in actionscript for flash.
I always use the same kind of indenting in ActionScript as I do in Jass. It's kinda standard for all languages. And about the loop, just make a local integer i, exitwhen i > <size of array>, set i = i + 1 each loop. Do actions on Waypoints in the loop.
 
Level 10
Joined
Jan 21, 2007
Messages
576
I understand loops and exiting them etc. etc. I just... bleh it's hard to explain, I am not picking all units in a region and moving them.

As of right now what I have is whenever a unit enters any of the 4 regions it triggers an action, that action checks what region contains that unit, then what the custom value is of the unit (tells where it should be going) and sends it on it's way. I don't see what I would do with a loop aside from loop through all the regions picking all units in the region and sending them to the next region, whenever a unit enters a region. That seems like it would make a lot of unnecessary orders. Do you understand why I think a loop wouldn't work/be necessary?

Or are you thinking of a different way entirely, sorry if that was hard to read it was kind of a hard thought to type out.

Here is the current code, with indenting fixed. Working on the polled wait now:
JASS:
scope WaypointSystem initializer Init
    function Actions takes nothing returns nothing
        local location l = GetUnitLoc(GetTriggerUnit())
        //  loop
        // local integer i = 1
        call PolledWait(.25)
        //==========================Enter Bottom Left========================
        
        if  (RectContainsLoc(gg_rct_WaypointBL, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 2) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 8208, -5264)
                call SetUnitUserData( GetTriggerUnit(), 6 )
            else
                if (GetUnitUserData(GetTriggerUnit()) == 8) then
                    call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                endif
            endif
        endif
        //==========================Enter Bottom Right=======================   
        if  (RectContainsLoc(gg_rct_WaypointBR, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 4) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8112, -5392)
                call SetUnitUserData( GetTriggerUnit(), 8 ) 
            else
                if (GetUnitUserData(GetTriggerUnit()) == 6) then
                    call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                endif
            endif
        endif
        //==========================Enter Top Right==========================   
        if  (RectContainsLoc(gg_rct_WaypointTR, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 3) then
                call IssuePointOrder(GetTriggerUnit(), "attack", -8176, 6560)
                call SetUnitUserData( GetTriggerUnit(), 7 ) 
            else
                if (GetUnitUserData(GetTriggerUnit()) == 5) then
                    call IssuePointOrder(GetTriggerUnit(), "attack", 8443.9, 492.3)
                endif
            endif
        endif
        //==========================Enter Top Left===========================
        if  (RectContainsLoc(gg_rct_WaypointTL, l) == true) then
            if (GetUnitUserData(GetTriggerUnit()) == 1) then
                call IssuePointOrder(GetTriggerUnit(), "attack", 7248, 7280)
                call SetUnitUserData( GetTriggerUnit(), 5 )
            else
                if (GetUnitUserData(GetTriggerUnit()) == 7) then
                    call IssuePointOrder(GetTriggerUnit(), "attack", -8365.7, 516.1)
                endif
            endif
        endif
        call RemoveLocation(l)
  endfunction
//===========================================================================     
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger WaypointSystemTrg = CreateTrigger()
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBR)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTR)
        call TriggerAddCondition( WaypointSystemTrg, Condition( function Conditions ) )
        call TriggerAddAction( WaypointSystemTrg, function Actions )
    endfunction
endscope

EDIT: Code reupdated
 
Level 11
Joined
Feb 22, 2006
Messages
752
A timer isn't really necessary here...Polled wait of 0.25 seconds may wait a little longer, depending on system (i don't trust TSA or PW to have accurate waits below 0.75 seconds), but it's not like this thing is extremely time-sensitive.

By the way, you really should save GetTriggerUnit() to a local so you don't have so many calls to it.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright was gone for a bit but I am back now:
JASS:
scope WaypointSystem initializer Init
    function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local location l = GetUnitLoc(u)
        call PolledWait(.25)
        //==========================Enter Bottom Left========================

        if  (RectContainsLoc(gg_rct_WaypointBL, l) == true) then
            if (GetUnitUserData(u) == 2) then
                call IssuePointOrder(u, "attack", 8208, -5264)
                call SetUnitUserData( u, 6 )
            else
                if (GetUnitUserData(u) == 8) then
                    call IssuePointOrder(u, "attack", -8365.7, 516.1)
                endif
            endif
        endif
        //==========================Enter Bottom Right=======================
        if  (RectContainsLoc(gg_rct_WaypointBR, l) == true) then
            if (GetUnitUserData(u) == 4) then
                call IssuePointOrder(u, "attack", -8112, -5392)
                call SetUnitUserData( u, 8 )
            else
                if (GetUnitUserData(u) == 6) then
                    call IssuePointOrder(u, "attack", 8443.9, 492.3)
                endif
            endif
        endif
        //==========================Enter Top Right==========================
        if  (RectContainsLoc(gg_rct_WaypointTR, l) == true) then
            if (GetUnitUserData(u) == 3) then
                call IssuePointOrder(u, "attack", -8176, 6560)
                call SetUnitUserData( u, 7 )
            else
                if (GetUnitUserData(u) == 5) then
                    call IssuePointOrder(u, "attack", 8443.9, 492.3)
                endif
            endif
        endif
        //==========================Enter Top Left===========================
        if  (RectContainsLoc(gg_rct_WaypointTL, l) == true) then
            if (GetUnitUserData(u) == 1) then
                call IssuePointOrder(u, "attack", 7248, 7280)
                call SetUnitUserData( u, 5 )
            else
                if (GetUnitUserData(u) == 7) then
                    call IssuePointOrder(u, "attack", -8365.7, 516.1)
                endif
            endif
        endif
        call RemoveLocation(l)
  endfunction
//===========================================================================
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger WaypointSystemTrg = CreateTrigger()
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBR)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointTR)
        call TriggerAddCondition( WaypointSystemTrg, Condition( function Conditions ) )
        call TriggerAddAction( WaypointSystemTrg, function Actions )
    endfunction
endscope
Is there anything else I can do to optimize this, or do all of this in a simpler and better way? Re-writing the whole thing wouldn't be that much of a big deal if it was quick/more efficient.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Updates, just showing the chunk that matters.
JASS:
                endif
            endif
        endif
        //==========================Enter Top Left===========================
        if  (RectContainsLoc(gg_rct_WaypointTL, l) == true) then
            if (GetUnitUserData(u) == 1) then
                call IssuePointOrder(u, "attack", 7248, 7280)
                call SetUnitUserData( u, 5 )
            else
                if (GetUnitUserData(u) == 7) then
                    call IssuePointOrder(u, "attack", -8365.7, 516.1)
                endif
            endif
        endif
        call RemoveLocation(l)
        set l = null
        set u = null
  endfunction
//===========================================================================
    private function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger WaypointSystemTrg = CreateTrigger()
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBL)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_WaypointBR)
        call TriggerRegisterEnterRectSimple(WaypointSystemTrg, gg_rct_Wa
 
Last edited:
Right, I'm just going to rewrite the system for you to show you how the loop would work.

EDIT: I can't do it without knowing which order the units go through the regions in, and I can't suss that out through code. Please either show me a screenshot from above of your map with the regions marked on, or just do a paint drawing shwoing which order the units go through the regions in.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright uploaded it, blue and black are the paths, pink is where the regions are, red is the spawns. gg_rct_WaypointBL woud be the redion on the bottom left corner, gg_rct_WaypointTR would be the region in the top right, and I am getting my sheet with he custom values to show you where they.. point to? W/e you will understand when you see it.

EDIT: Alright let me run through a 2 quick examples, a creep-wave spawns at the left-bottom spawn (left bases bottom-lane spawn), all of the spawned units have there custom value set to 2 and are issued a move order toward a point that is inside the bottom left region. Once they get there it sees that there custom value is 2 (so it knows where they cam from) so it sets there custom value to 6 and sends them to a point inside of the bottom right region. Once they get there is sees that there custom value is 6 so it sends them to the right bases middle area, where the building/boss is.

Now if u spawned on the bottom right spawn, u would go down to the bottom right region, it would see your CV is 4 so it would change it to 8 and send you walking over to the bottom left region.... I think you get the picture lol =p
 

Attachments

  • Capture.JPG
    Capture.JPG
    313.3 KB · Views: 58
  • Pic.jpg
    Pic.jpg
    20 KB · Views: 64
Level 10
Joined
Jan 21, 2007
Messages
576
Thats true lol, but it would only remove the call that sets there custom value to a new one, I would still have all the ifs. Checking the owner, so it's not -all- that much more =p. Any luck on creating the thing with a loop?
 
Right then, I'm creating the thing with the loop to check for players.

EDIT:
Done. Should work, but I think you'll be able to make it work if it doesn't.
JASS:
scope WaypointSystem initializer Init
    
    globals
        rect array WaypointsRects
        region array WaypointsRegions
        
        constant player TEAM_1_AI = Player(5)
        constant player TEAM_2_AI = Player(11)
        
        constant real TARGET_TEAM_1_X = 8443.9
        constant real TARGET_TEAM_1_Y = 492.3
        
        constant real TARGET_TEAM_2_X = -8365.7
        constant real TARGET_TEAM_2_Y = 516.1
    endglobals

    function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local integer i = 0
        
        call PolledWait(.25)
        
        loop
            exitwhen i >= 4
            
            if IsPointInRegion(WaypointsRegions[i], x, y) then
                if p == TEAM_1_AI then
                    if i == 1 or i == 3 then
                        call IssuePointOrder(u, "attack", TARGET_TEAM_1_X, TARGET_TEAM_1_Y)
                    else
                        call IssuePointOrder(u, "attack", GetRectCenterX(WaypointsRects[i+1]), GetRectCenterY(WaypointsRects[i+1]))
                    endif
                elseif p == TEAM_2_AI then
                    if i == 0 or i == 2 then
                        call IssuePointOrder(u, "attack", TARGET_TEAM_2_X, TARGET_TEAM_2_Y)
                    else
                        call IssuePointOrder(u, "attack", GetRectCenterX(WaypointsRects[i-1]), GetRectCenterY(WaypointsRects[i-1]))
                    endif
                endif
            endif
            
            set i = i + 1
        endloop
        
        set u = null
        set p = null
  endfunction
//===========================================================================
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'nban')
    endfunction

//===========================================================================
    function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local integer i = 0
        
        set WaypointsRects[0] = gg_rct_WaypointBL
        set WaypointsRects[1] = gg_rct_WaypointBR
        set WaypointsRects[2] = gg_rct_WaypointTL
        set WaypointsRects[3] = gg_rct_WaypointTR

        loop
            exitwhen i >= 4
            
            set WaypointsRegions[i] = CreateRegion()
            call RegionAddRect(WaypointsRegions[i], WaypointsRects[i])
        
            call TriggerRegisterEnterRegion(t, WaypointsRegions[i], null)
            
            set i = i + 1
        endloop
        
        call TriggerAddCondition(t, Condition( function Conditions))
        call TriggerAddAction(t, function Actions)
    endfunction
endscope
Now do you see what I mean with the loop? Besides, now you can use custom values for other stuff if you need.
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright now I do understand, but you were right you're code didn't work at first. But I was changing it and it should work now, but I am getting errored out like a 13itch, and I don't know why.
JASS:
scope WaypointSystem initializer Init

    globals
        rect array WaypointsRects
        region array WaypointsRegions
        real array WAYPOINT_Y
        real array WAYPOINT_X
        
        constant player TEAM_1_AI = Player(11)
        constant player TEAM_2_AI = Player(5)

        set WAYPOINT_X[0] = GetRectCenterX(WaypointsRects[0])
        set WAYPOINT_X[1] = GetRectCenterX(WaypointsRects[1])
        set WAYPOINT_X[2] = GetRectCenterX(WaypointsRects[2])
        set WAYPOINT_X[3] = GetRectCenterX(WaypointsRects[3])
        
        set WAYPOINT_Y[0] = GetRectCenterY(WaypointsRects[0])
        set WAYPOINT_Y[1] = GetRectCenterY(WaypointsRects[1])
        set WAYPOINT_Y[2] = GetRectCenterY(WaypointsRects[2])
        set WAYPOINT_Y[3] = GetRectCenterY(WaypointsRects[3])
    endglobals

    function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local integer i = 0

        call PolledWait(.25)

        loop
            exitwhen i >= 3

            if IsPointInRegion(WaypointsRegions[i], x, y) then
                if (p == TEAM_1_AI) then
                    call IssuePointOrder(u, "attack", WAYPOINT_X[i], WAYPOINT_Y[i])
                elseif (p == TEAM_2_AI) then
                    if (i <= 1) then
                        call IssuePointOrder(u, "attack", -8365.7, 516.1)
                    else
                        call IssuePointOrder(u, "attack", 8443.9, 492.3)
                    endif
                endif
            endif

            set i = i + 1
        endloop

        set u = null
        set p = null
  endfunction
//===========================================================================
    function Conditions takes nothing returns boolean
        return (GetUnitTypeId(GetTriggerUnit()) == 'h006') or (GetUnitTypeId(GetTriggerUnit()) == 'h009') or (GetUnitTypeId(GetTriggerUnit()) == 'h008') or (GetUnitTypeId(GetTriggerUnit()) == 'h005')
    endfunction

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

        set WaypointsRects[0] = gg_rct_WaypointBL
        set WaypointsRects[1] = gg_rct_WaypointTL
        set WaypointsRects[2] = gg_rct_WaypointTR
        set WaypointsRects[3] = gg_rct_WaypointBR

        loop
            exitwhen i >= 3

            set WaypointsRegions[i] = CreateRegion()
            call RegionAddRect(WaypointsRegions[i], WaypointsRects[i])
            call TriggerRegisterEnterRegion(WaypointSystemTrg, WaypointsRegions[i], null)

            set i = i + 1
        endloop

        call TriggerAddCondition(WaypointSystemTrg, Condition( function Conditions))
        call TriggerAddAction(WaypointSystemTrg, function Actions)
    endfunction
endscope
put it in a trigger called WaypointSystem and compile it, you get like 25 errors, talking about UNDEFINEDTYPE: WAYPOINT_X, UNDEFINEDTYPE: GetRectCenterX..... and ugh. Just a bunch of errors I don't know how to respond to because for me it's like seeing local integer x = 1 and getting a syntex error, its like wtf do you do =/
 
Level 10
Joined
Jan 21, 2007
Messages
576
Anyone who can explain why wavemove isn't getting called gets hardcore rep, I have been staring for like 30 minutes and I can't figure it out lol :slp:.
JASS:
scope Infestion initializer Init
    
    globals
    group infestionwaves
    endglobals
    
    private function Conditions takes nothing returns boolean
        return (GetSpellAbilityId() == 'A000')
    endfunction
    
    private function wavemove takes nothing returns nothing
        
        local unit f = FirstOfGroup(infestionwaves)
        
        local real angle = GetUnitFacing(f)
        local group g = CreateGroup()
        local unit f2
        local real x = GetUnitX(f)
        local real y = GetUnitY(f)
        call BJDebugMsg("wavemove")
        call BJDebugMsg(GetUnitName(f))
        
        set angle = angle * bj_RADTODEG
        
        call SetUnitX(f, x + 15 * Cos(angle * bj_DEGTORAD))
        call SetUnitY(f, y + 15 * Sin(angle * bj_DEGTORAD))
        call GroupEnumUnitsInRangeOfLoc(g, Location(x,y), 300, null)
            set f2 = FirstOfGroup(g)
            if (GetUnitAbilityLevel(f2, 'B000') > 0) then
            else
                call CreateUnit(GetOwningPlayer(f), 'h001', x, y, 0)
                call UnitAddAbility(bj_lastCreatedUnit, 'A001')
                call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A001', GetUnitAbilityLevel(f, 'A002'))
                call IssueTargetOrder(bj_lastCreatedUnit, "unholyfrenzy", f2)
                call UnitApplyTimedLife(bj_lastCreatedUnit, 'A001', 2)
            endif
                
    endfunction
    
    private function Actions takes nothing returns nothing
        local unit   u = GetTriggerUnit()
        local player p = GetOwningPlayer(u)
        
        local real x = GetUnitX(u)
        local real y = GetUnitY(u)
        local real f = GetUnitFacing(u)
        
        local unit d = CreateUnit( p, 'h000', x, y, f)
        local timer t = CreateTimer()
        local real   angle
        
        call BJDebugMsg("Test")
        call TimerStart(t, .03, true, function wavemove)
        call CreateUnit(GetOwningPlayer(u), 'h001', x, y, 0)
        call UnitAddAbility(bj_lastCreatedUnit, 'A002')
        call SetUnitAbilityLevel(bj_lastCreatedUnit, 'A002', GetUnitAbilityLevel(u, 'A000'))
        call GroupAddUnit(infestionwaves, d)
        set angle = bj_RADTODEG * Atan2(GetLocationY(GetSpellTargetLoc()) - y, GetLocationX(GetSpellTargetLoc()) - x)
        call SetUnitFacing( bj_lastCreatedUnit, angle)
        call SetUnitX(bj_lastCreatedUnit, x + 15 * Cos(angle * bj_DEGTORAD))
        call SetUnitY(bj_lastCreatedUnit, y + 15 * Sin(angle * bj_DEGTORAD))
        call UnitApplyTimedLife(bj_lastCreatedUnit, 'A001', 4)
    endfunction

//===========================================================================
    private function Init takes nothing returns nothing
        local trigger InfestionTrg = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ( InfestionTrg, EVENT_PLAYER_UNIT_SPELL_EFFECT )
        call TriggerAddCondition( InfestionTrg, Condition( function Conditions ) )
        call TriggerAddAction( InfestionTrg, function Actions )
        
    endfunction
endscope
 
Last edited:
Level 10
Joined
Jan 21, 2007
Messages
576
Alright I will have a local unit and create it in that, but wavemove doesn't even run, I never see those debug msgs =/
 
Level 10
Joined
Jan 21, 2007
Messages
576
Alright on to something new =p, I am trying to make a dot system but I am having a bit of trouble. This is my code:
JASS:
library EasyDot initializer Init
/////////////////////////////////////////////////////////////////////////////////////
//                                   EasyDot                                       //
//                      By: Gost                                                   //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //      
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
//                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////

globals
    private Dot array DOTS
    private integer total = 0
    private group g = CreateGroup()
endglobals


private struct Dot
widget target
unit caster
real dpi
real interval
real dur
string SpecEfec
static timer tim = null

static method loop takes nothing returns nothing
    local integer i = 0
    local Dot dot
    local unit t = dot.target
    local unit c = dot.caster
    local real dpi = dot.dpi
    call BJDebugMsg("tick")
    set dot.dur = dot.dur - .25
    loop
        exitwhen i >= total
        set dot = DOTS[i]
        if dot.dur > .24 then
            call UnitDamageTarget(c,t,dpi,true,false,ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
        else
            call dot.destroy()
        endif
        set i = i + 1
    endloop
endmethod

endstruct

function test takes nothing returns nothing
endfunction

function CreateDot takes unit caster, unit target, real dpi, real interval, real dur, string SpecEfec returns nothing
        local Dot dot
        call BJDebugMsg("Dot Created")
        set dot = Dot.create()
        set dot.target = target
        set dot.caster = caster
        set dot.dpi = dpi
        set dot.interval = interval
        set dot.dur = dur
        set dot.SpecEfec = SpecEfec
        set DOTS[total] = dot
        set total = total + 1
        call TimerStart(Dot.tim, dur, true, function Dot.loop)
endfunction

function RemoveDot takes unit u returns nothing
    local integer i = 0
    local Dot dot
    loop
        exitwhen i >= total
        if DOTS[i].target == u then
            set dot = DOTS[i]
            set total = total - 1
            set DOTS[i] = DOTS[total]
            call dot.destroy()
        endif
        set i = i + 1
    endloop
endfunction

function Init takes nothing returns nothing
    set Dot.tim = CreateTimer()
endfunction

endlibrary
But I keep getting this error on the RemoveDot function:
JASS:
EasyDot___DOTS[i] is not of a type that allows . syntax



EDIT: Figured it out, I can't have my struct be private.
 
Last edited:
Level 10
Joined
Jan 21, 2007
Messages
576
Alright after I finished my dot system, I am now working on a different system, that creates a missile of your model specifications on creation. And moves it forward doing damage (or w/e you want) in a radius you specify. So anyways heres the code:
JASS:
library AMS initializer Init
/////////////////////////////////////////////////////////////////////////////////////
//                               Aoe Missile System                                //
//                                   By: Gost                                      //
//  //
//                                                       //
//                                                                                 //
//               //
//                                                                          //
//                                                                                 //
//   //
//  //
//                                        //
//                                                                                 //
//                                            //
//    //
//        //
//                                                                                 //
//    //      
//                                 //
//                                                                                 //
//                                                                     //
//                                                                                 //
//                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////
//==============================================================================================================================
globals
    private Wave array WAVES
    private integer    total      = 0
    private real       Interval   = .05 
endglobals
//==============================================================================================================================
struct Wave
unit         missile
unit         source
real         radius
real         x
real         y
real         distance
real         distcounter
real         dps
string       SpecEfec
group        g
static timer Tim         = null

static method Loop takes nothing returns nothing
    local Wave dat
    local integer i = 0
    loop
        exitwhen i >= total
        set dat = WAVES[i]
        call GroupClear(dat.g)
        if dat.distcounter <= dat.distance
            call GroupEnumUnitsInRangeOfLoc(dat.g, Location(x,y), radius, null)
            local integer int = 0
            loop
                exitwhen int >= total
                local f = FirstOfGroup(dat.g)
                if (GetUnitAbilityLevel(f, 'B000') > 0) then
                    local real angle = GetUnitFacing(dat.missile)
                    set angle = angle * bj_RADTODEG
                    call SetUnitX(dat.missile, dat.x + 15 * Cos(angle * bj_DEGTORAD))
                    call SetUnitY(dat.missile, dat.y + 15 * Sin(angle * bj_DEGTORAD))
                    call CreateDot(dat.source, GetTriggerUnit(), 10,5,10, "Abilities\\Spells\\Other\\AcidBomb\\BottleImpact.mdl", "chest", ATTACK_TYPE_NORMAL)
                    call GroupRemoveUnit(dat.g, f)
                    set dat.x = dat.missile, dat.x + 15 * Cos(angle * bj_DEGTORAD)
                    set dat.y = dat.missile, dat.y + 15 * Sin(angle * bj_DEGTORAD)
                endif
                int = int + 1
            endloop
        else
            set dat.missile     = null
            set dat.source      = null
            set dat.radius      = 0
            set dat.x           = 0
            set dat.y           = 0
            set dat.distance    = 0
            set dat.distcounter = 0
            set dat.dps         = 0
            set dat.SpecEfec    = ""
            call GroupClear(dat.g)
            call DestroyGroup(dat.g)
        endif
            set i = i + 1
    endloop
            
            if total == 0 then
                call PauseTimer(dat.Tim)
            endif
endmethod

endstruct
//==============================================================================================================================
function CreateWave takes unit source, unit missile, real radius, real x, real y, real distance, real distcounter, real dps, string SpecEfec, returns nothing
        local Wave dat
        set dat             = Wave.create()
        set dat.source      = Target
        set dat.missile      = Caster
        set dat.radius         = Dpi
        set dat.x    = Interval
        set dat.y         = Dur
        set dat.distance    = SpecEfec
        set dat.distcounter = AttachPoint
        set dat.dps = dps
        set dat.SpecEfec = SpecEfec
        set WAVES[total]     = dat
        if total == 0 then
            call TimerStart(Wave.Tim, Interval, true, function Wave.Loop)
        endif
        set total = total + 1
endfunction
//==============================================================================================================================
private function Init takes nothing returns nothing
    set Wave.Tim = CreateTimer()
endfunction
//==============================================================================================================================
endlibrary

But I keep getting a syntax error on this line
JASS:
if dat.distcounter <= dat.distance
=/, my untrained eye doesn't know whats wrong with that.
 
Last edited:
Level 10
Joined
Jan 21, 2007
Messages
576
Lol >.< uhghghg, that makes me want to rage lol. Thanks =p

EDIT: would this correctly move a unit forward toward it's facing?
JASS:
set angle = GetUnitFacing(dat.missile) * bj_RADTODEG
            call SetUnitX(dat.missile, dat.x + 15 * Cos(angle * bj_DEGTORAD))
            call SetUnitY(dat.missile, dat.y + 15 * Sin(angle * bj_DEGTORAD))
 
Last edited:
Level 21
Joined
Aug 21, 2005
Messages
3,699
set angle = GetUnitFacing(dat.missile) * bj_RADTODEG


Why would you convert an angle to degrees when you will then convert it back to radians? Just use this:

JASS:
set angle = GetUnitFacing(dat.missile)
            call SetUnitX(dat.missile, dat.x + 15 * Cos(angle))
            call SetUnitY(dat.missile, dat.y + 15 * Sin(angle))
 
Level 10
Joined
Jan 21, 2007
Messages
576
Idk, thought the function might only work because of that, I didn't write this I just copied and pasted (and then modified it) from some guys flash script lol.
 
Status
Not open for further replies.
Top