1. Are you planning to upload your awesome spell or system to Hive? Please review the rules here.
    Dismiss Notice
  2. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  3. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  4. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  5. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  6. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  7. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  8. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  9. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  10. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Arrow System v1.5

Submitted by maddeem
This bundle is marked as approved. It works and satisfies the submission rules.

Arrow System
Arrow system is for rpg maps that want to show how to get from one unit to another using a graphic. It is very simple to import and start using.
Arrow Model by hellblazer-14
New version does not contain the function ArrowUnit2Point
Code

Code (vJASS):
library ArrowSystem //By maddeem
    globals
        private integer   ID = 'B000' // Arrow Destructable ID
        private real      Timeout = 0.03125 //How often the timers fire
        private real      DestroyDistance = 200 //The distance from the target at which the arrow is destroyed
        private hashtable h = InitHashtable( )
    endglobals
    function DestroyArrow takes unit u1 returns nothing //This function will destroy any arrow on any unit at any time
        local integer i = GetHandleId( u1 )
        local timer   t = LoadTimerHandle( h, i, 0 )
        local integer ii = GetHandleId( t )
        call DestroyTimer( t )
        call RemoveDestructable( LoadDestructableHandle( h, ii, 4 ) )
        call FlushChildHashtable( h, i )
        call FlushChildHashtable( h, ii )
        set t = null
    endfunction
    private function SetArrowU2U takes nothing returns nothing
        local timer        t = GetExpiredTimer( )
        local integer      i = GetHandleId( t )
        local unit         u1 = LoadUnitHandle( h, i, 0 )
        local unit         u2 = LoadUnitHandle( h, i, 1 )
        local real         x1 = GetUnitX( u1 )
        local real         x2 = GetUnitX( u2 )
        local real         y1 = GetUnitY( u1 )
        local real         y2 = GetUnitY( u2 )
        local real         dx = x1 - x2
        local real         dy = y1 - y2
        local real         si = LoadReal( h, i, 2 )
        local real         he = LoadReal( h, i, 3 )
        local location     l = Location( x1, y1 )
        local destructable d
        call RemoveDestructable( LoadDestructableHandle( h, i, 4 ) )
        if SquareRoot( dx * dx + dy * dy ) < DestroyDistance then
            call DestroyTimer( t )
            call FlushChildHashtable( h, i )
            call FlushChildHashtable( h, GetHandleId( u1 ) )
        else
            set d = CreateDestructableZ( ID, x1, y1, he + GetUnitFlyHeight( u1 ) + GetLocationZ( l ), 90 + bj_RADTODEG * Atan2( y2 - y1, x2 - x1 ), si, 0 )
            call SaveDestructableHandle( h, i, 4, d )
            if IsUnitOwnedByPlayer( u1, GetLocalPlayer( ) ) then
                call ShowDestructable( d, true )
            else
                call ShowDestructable( d, false )
            endif
        endif
        call RemoveLocation( l )
        set l = null
        set u1 = null
        set u2 = null
        set t = null
        set d = null
    endfunction
    function ArrowUnit2Unit takes unit u1, unit u2, real size, real height returns nothing //Main function of the system
        local timer   t = CreateTimer( )
        local integer i = GetHandleId( t )
        call TimerStart( t, Timeout, true, function SetArrowU2U )
        call SaveUnitHandle( h, i, 0, u1 )
        call SaveUnitHandle( h, i, 1, u2 )
        call SaveReal( h, i, 2, size )
        call SaveReal( h, i, 3, height )
        call SaveTimerHandle( h, GetHandleId( u1 ), 0, t )
        set t = null
    endfunction
endlibrary


//Code indented using The_Witcher's Script language Aligner
//Download the newest version and report bugs at www.hiveworkshop.com


Give Credit if used! :D

Keywords:
Arrow, Pointer, Quest, Direction
Contents

Arrow System (Map)

Reviews
Moderator
This system could be useful. Suggested changes Use coordinates instead of locations Use an integer instead of GroupCount founction and ForGroup Player variable does not need to be nulled You could pause/resume the timer instead of using a...
  1. Reviewed by Maker, Arrow System v1.1, 24th Apr 2012

    This system could be useful.
    Suggested changes
    • Use coordinates instead of locations
    • Use an integer instead of GroupCount founction and ForGroup
    • Player variable does not need to be nulled
    • You could pause/resume the timer instead of using a trigger
    Why does CreateArrow have destructable as function parameter, but it is not used?
     
  2. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    Questions anyone?
     
  3. -Kobas-

    -Kobas-

    Joined:
    Jan 17, 2010
    Messages:
    5,894
    Resources:
    28
    Icons:
    1
    Tools:
    2
    Maps:
    10
    Spells:
    4
    Template:
    5
    Tutorials:
    6
    Resources:
    28
    Try to use coordinates instead of locations.
    Also there is no need for BJ functions.

    Btw why you split those 2 scripts, if you use library then put merge them together.
     
  4. Existas

    Existas

    Joined:
    Jan 7, 2009
    Messages:
    39
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Your arrow system works, however there are few things that I dislike.

    1. Do not make your arrow destroy itself when the unit reaches its destination, rather make sure the unit follows the arrows guidance to perform an action which should destroy the arrow guiding (since he accomplished something already and doesn't need to be guided).
    2. You should consider including some eyecandy on arrow's disappearance. It looks very static right now. Do it with an effect or arrow animation (which you may now be short on).
    3. Reconsider using a unit instead of a destructable. This provides you with following capabilities: vertex coloring, animation time scaling, scaling and moving, Vexorian projectile dummy model usage (making your arrow system able to point at high point or low ground), but provides and few disadvantages: GetLocalPlayer() usage exacerbation (in this case you would need to use vertex coloring to hide the arrow from other players) and additional hard work.
    4. Your codding part is rather messy.

    Code (vJASS):

    private integer Arrow = 'B000'
    public real ArrowTimeOut = 0.03
    public real DestroyDistance = 200.
     

    Consider making these constant
    Changes:
    Code (vJASS):

    private constant integer Arrow = 'B000'
    public constant real ArrowTimeOut = 0.03
    public constant real DestroyDistance = 200.
     


    As -Kobas- mentioned you should merge your triggers into one.
    Consider changing these public members to private and provide the library with public functions to get those members in case of emergency (which I honestly hope wont happen in a lifetime)
    Code (vJASS):
    public hashtable ArrowHash = InitHashtable( )
    public group ArrowGroup = CreateGroup( )


    Help yourself - create a GetArrow function which takes a unit and returns a destructable (obviously get unit's arrow)

    Code (vJASS):
    if IsUnitGroupEmptyBJ( ArrowGroup ) == true then

    Can be changed to:
    Code (vJASS):
    if FirstOfGroup( ArrowGroup ) == null then

    Which is so much faster

    and

    Code (vJASS):
            call ShowDestructable( d, false )
            if GetLocalPlayer( ) == p then
                call ShowDestructable( d, true )
            endif

    Can be changed to (I know people can get messed up, but this is quite simple):
    Code (vJASS):
    call ShowDestructable( d, GetLocalPlayer( ) == p )


    On top of that: get used to using coordinates instead of locations (they can get really messy in a big project and leave a huge memory leak if you don't know what you're doing). Practicing coordinates now gives your further coding life an excellent contribution.

    If you just practice, it's good you're doing so, but if you need a good arrow system you should make my mentioned changes (2 and 3 parts are optional) or I can create such library for your use (no credits, just rep).

    Wish you best luck!
     
  5. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    I wanted to use locations to make this gui friendly, also I tried merging them... proved to be quite difficult
    Edit: Got rid of the BJs >;p
     
    Last edited: Apr 10, 2012
  6. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Use a timer instead of a timed trigger then; either way, the timer's expiration is linked with a function. :p
     
  7. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    I dunno how to use timers :S
     
  8. Existas

    Existas

    Joined:
    Jan 7, 2009
    Messages:
    39
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Then you got a long way to go.

    Timer usage:
    Code (vJASS):
    function TimerFunction takes nothing returns nothing
        call BJDebugMsg("timer function call")
        //TimerFunction actions here, depending on what you want to do
        //There are so many bonus posibilties what timers can do including but not limited to struct attachment.
    endfunction

    function InitTrig_Timer takes nothing returns nothing
        local timer t = CreateTimer()
        call TimerStart(t, 0.03, true, function TimerFunction)
    endfunction


    What timers do is absolutely simple, they call a function everytime their time run out (that's called a time out) and refreshes it or not based on the third parameter (which is true here and makes the timer keep going forever)

    And merging them isn't that difficult as you would have thought. Simple.

    Make your library an initializer:
    Code (vJASS):

    library ArrowSys initializer Startup

        private function Startup takes nothing returns nothing
            //Here goes the code for startup: timer definition and timer start
        endfunction
    endlibrary
     
     
  9. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    The Timer API is extremely simple.

    CreateTimer()

    DestroyTimer(timer)

    TimerStart(timer, timeout, isPeriodic, code)

    PauseTimer(timer)

    ResumeTimer(timer)

    TimerGetTimeout(timer)

    TimerGetElapsed(timer)

    TimerGetRemaining(timer)


    All you need here is CreateTimer, TimerStart and PauseTimer.

    Examples of usage:

    Code (vJASS):
    local timer t = CreateTimer()
    call TimerStart(t, 0.03125, true, function onRun)
    call PauseTimer(t)
     
  10. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    Blarg it is too troublesome to use timers >:S
     
  11. Existas

    Existas

    Joined:
    Jan 7, 2009
    Messages:
    39
    Resources:
    1
    Maps:
    1
    Resources:
    1
    I'm terribly sorry that I have to be this harsh but...
    This line is pointless if you won't update your system as friendly hive members offered you to.
    Well unless people use GUI and don't give a single fuck about it's performance.

    I can create such a system from scratch in around 10...20 minutes (including my level of experience) you should be able to do the same in about 5x more time, which has to be 50...100 minutes or harshly around an hour or two.

    Just to give you a push... I'll give +rep if you manage to update it into a perfect state.

    Do not get my post as a must do and do whatever you think is right.

    Happy coding!
     
  12. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    They're still way faster.
     
  13. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    I really did try to use them, it kept crashing my map, I cant even debug that crap. I'm not going to use timers.
     
  14. timothyhuth

    timothyhuth

    Joined:
    Feb 20, 2011
    Messages:
    50
    Resources:
    0
    Resources:
    0
    Bj functions. :)
     
  15. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    Wut? I removed those... o_O
     
  16. -Kobas-

    -Kobas-

    Joined:
    Jan 17, 2010
    Messages:
    5,894
    Resources:
    28
    Icons:
    1
    Tools:
    2
    Maps:
    10
    Spells:
    4
    Template:
    5
    Tutorials:
    6
    Resources:
    28
    May I suggest:
    Code (vJASS):

     private integer Arrow = 'B000'
            public real ArrowTimeOut = 0.03
            public real DestroyDistance = 200.
            //End Configurables
            public hashtable ArrowHash = InitHashtable( )
            public group ArrowGroup = CreateGroup( )
            private boolean boob
     

    to be changed into
    Code (vJASS):

        globals
            //Configurables
            private integer    ARROW_ID       = 'B000'
            private real       LOOP           = 0.03
            private real       MIN_DISTANCE   = 200.
            //End Configurables
           
            private hashtable  HASH          = InitHashtable( )
            private group      G             = CreateGroup( )
            private boolean    B             = false
            private trigger    T             = CreateTrigger()
        endglobals
     

    There is no need for long names in this small script.
    Also there is no need for public variables you can merge scripts.

    Also function names are horrible :D
    Even variables are bad:
    function ArrowU2U takes real size, real Height, unit AttachedUnit, unit TargetUnit returns nothing

    can be
    function ArrowU2U takes real size, real z, unit u, unit target returns nothing
     
  17. Pharaoh_

    Pharaoh_

    Joined:
    Nov 6, 2008
    Messages:
    8,127
    Resources:
    11
    Icons:
    3
    Skins:
    1
    Spells:
    6
    Tutorials:
    1
    Resources:
    11
    Mhm, so you tell everyone how dumb their coding is and you can't use timers.. Now that's something I did not expect.
    Anyway, apart from my poisonous comment, timers will save your life. You won't need to use a trigger, but a simple function!
     
  18. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,006
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    private boolean boob


    That's my favorite bit-sized data-type :ogre_hurrhurr:
     
  19. maddeem

    maddeem

    Joined:
    Jan 1, 2011
    Messages:
    1,260
    Resources:
    5
    Maps:
    2
    Spells:
    3
    Resources:
    5
    What?

    Kobas, most of those must be public, so I had to have realistic names.

    Jesus, this is my first vJass script or any scripting language at all. You have some high expectations.