• 🏆 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!

Target System v 0.1

Target System by neku99

This is a systems that let's you acquire location or unit targets, and then be used as targets for a spell. This system was meant to simulate the battle system used in Square Enix's Final Fantasy XII. . . Well at least the right arrow/marker part. Who knows I might make a battle system altogether.(might)

In this system acquiring targets is a simple right click on the ground or on a unit. But I put something in the documentation to show you how to use an ability instead of just right clicking.

You can also specify if it the arrow/marker follows unit targets or not.

This system Requires JassNewGen to be saved

Please check the header for more details on the system.


JASS:
//============================================================================================
// Target System v.0.1 
// By neku99
//============================================================================================
// What does this system do?
//==================================================
//
// - This system allows you to put a marker at a location or a unit. There after you can refer to this location or unit
// as the target of a spell or ability. This is very useful for simulating battle systems like the one in Fina Fantasy Games 
// or just do whatever you want with it, the possibilities are endless (I hope).
//
// - In this case I made the system to execute when you move to a location or when you right click on a unit but you can
// easily configure it for when an ability is casted (It will be convered on the Ability/Spell Configuration)
//
//==================================================
// Configurables
//==================================================
//
// - Determine if the system allows target following when you target a unit.
//
//==================================================
// Globals
//==================================================
//
// TARGET_ORDER_ID  = a constant string that determines what order the system will fire when the order is executed
// TARGET_ORDER_ID2 = same as the one on top for secondary orders
// TARGET_DUMMY     = a constant integer that determines the dummy unit used as a marker/arrow.
// TARGET_FOLLOW    = a boolean that determines if the system allows target following
//
// TARGET_ARRAY     = an integer array used for the indexing
// TOTAL            = an integer used for the indexing
// TARGET_ TIMER    = a timer used for the Loop
// TICK             = a constant real that determines the interval for the loop
//
//==================================================
// Parameters
//==================================================
// - You can simply use this system using one function call:
//
// call Marker.CheckMarker( Parameters )
//
// Here are the parameters arranged in order with description
//
// u  = the unit that executes the order/ability
// tx = the x coordinate of the target unit/location
// ty = the y coordinate of the target unit/location
// t  = the target unit if a unit is targeted
//
//==================================================
// Getting a Target
//==================================================
//
// - To get a target I made a method called GetMarker.
// 
// call Marker.GetMarker ( Insert Unit Here to Get its Marker )
// 
// - What it does is return the dummy unit/marker/arrow whatever for the unit you put on the parameters. Now you can refer to this unit and determine it's location by
// calling the functions GetUnitX() and GetUnitY().
//
// - For the target unit it is automatically set as data.t when TARGET_FOLLOW is true.  
// 
//
//==================================================
// Ability/Spell Configuration
//==================================================
//
// - In this system I configured it to run when you left click on a unit or location. Now I'll go through in explaining how to configure the system to 
// work when an ability is executed
//
// + First change "constant string TARGET_ORDER_ID" to "constant integer TARGET_ORDER_ID"
// + Next we need to set the raw code of the ability on the "constant string TARGET_ORDER_ID".
//   - To see the raw codes of the abilities in the Object Editor, you need to go to
//     View and check the "Disply Values As Raw Data" or simply enter CTRL + D
//     doing this will let you see the raw codes of everything from units to abilities
//   - Now that you've seen the raw codes of the dummy abilities it's just a case of copying it and setting in "constant string TARGET_ORDER_ID"
//     Example: "constant integer TARGET_ORDER_ID = 'rawcodehere' "
//   - YOu can also do this with TARGET_ORDER_ID2
// + Now we need to change the condition function.
//   - Change this part:
//     
//     return ( GetIssuedOrderId() == String2OrderIdBJ(TARGET_ORDER_ID) or GetIssuedOrderId() == String2OrderIdBJ(TARGET_ORDER_ID2) )
//
//   - to:
//
//      return (GetSpellAbilityId() == TARGET_ORDER_ID)
// + Lastly we need to edit the events.
//   - Change this:
//
//     call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
//     call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
//
//   - to:
//     
//     call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EVENT)
//   - Now we're done. It'll Look something like this:
//
//   On the TARGET_ORDER_ID:
//
//    constant string TARGET_ORDER_ID = 'RawCode'
//
//   On the condition function:
//
//    private function condition takes nothing returns boolean
//        return (GetSpellAbilityId() == TARGET_ORDER_ID)
//    endfunction
//
//   On the Trigger Register Event:
//
//    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_EVENT)
//
// + Well that's it enjoy the system.   
//
//==================================================
// Ending Comments
//==================================================
// - This will be the second Jass/vJass coded system/spell I will be submmiting
// - The setup on this test map will be similar to the battle system I'll be incorporating in my map project
// - If you find any bugs or you have any suggestions contact me. neku99
// - If you use this on any map of your's never forget to give credits :D
//
//==================================================
// Credits to
//==================================================
// Berb    - For teaching me JASS/vJASS
// Adiktuz - For doing the same and having patience for all my vJass Questions
//  
//END/////////////////////////////////////////////////////////////////////////////////////////

library TargetSystem initializer init
    globals
        constant string  TARGET_ORDER_ID  = "smart"
        constant string  TARGET_ORDER_ID2 = "patrol"
        constant integer TARGET_DUMMY     = 'u002'
        
        private boolean TARGET_FOLLOW = true
        
        private integer array TARGET_ARRAY[8190]
        
        private integer TOTAL          = 0
        private timer TARGET_TIMER     = CreateTimer()
        
        private constant real TICK     = 0.01
    endglobals
    
    struct Marker
        
        private unit u
        private unit dummy
        private unit t
        private real tx
        private real ty
        private integer counter
        
        private static thistype data
        private static thistype datu
        
        //Get Marker - Used to get the marker of a unit          
        static method GetMarker takes unit u returns unit
            local integer i = 1
            local unit m
            loop
                exitwhen i > TOTAL
                set datu = TARGET_ARRAY[i]
                if datu.u == u then
                    set m = datu.dummy
                    set i = TOTAL + 1
                else
                    set i = i + 1
                    set m = null
                endif
            endloop          
          
        return m  
        endmethod

        //Loop - The loop
        private static method Loop takes nothing returns nothing
           local integer i = 1
           
           loop
               exitwhen i > TOTAL
               set data = TARGET_ARRAY[i]
               
               if data.dummy != null then
                  if TARGET_FOLLOW == true then
                     if data.t != null then
                        call SetUnitX(data.dummy, GetUnitX(data.t))
                        call SetUnitY(data.dummy, GetUnitY(data.t))
                     endif
                  endif
               else
                  set TARGET_ARRAY[i] = TARGET_ARRAY[TOTAL]
                  set TOTAL = TOTAL - 1
                  set i = i - 1
                  call data.destroy()
               endif
               
               if TOTAL == 0 then
                 call PauseTimer(TARGET_TIMER)
               endif
              
               set i = i + 1               
           endloop
        endmethod
        
        //Create - Creates an instance of an arrow for a unit 
        private static method create takes unit u, real x, real y, unit t returns thistype
            
            set data = allocate()
            
            set data.u  = u
            set data.tx = x
            set data.ty = y
            
            if TARGET_FOLLOW == true then
               set data.t  = t
            endif
            
            set data.dummy   = CreateUnit( GetOwningPlayer(data.u), TARGET_DUMMY, data.tx, data.ty, 270)
            
            set data.counter = 1
            
            set TARGET_ARRAY[TOTAL] = data
         
            if TOTAL == 1 then
              call TimerStart( TARGET_TIMER, TICK, true, function Marker.Loop)
            endif
            
        return data
        endmethod
        
        //Check Marker - Checks if unit has a marker. If it has a marker it will move the marker. If not create a marker.
        static method CheckMarker takes unit u, real x, real y, unit t returns thistype
            local integer i = 1
            
            set TOTAL = TOTAL + 1
            call ClearTextMessages()
            
            if t != null then
              set x = GetUnitX(t)
              set y = GetUnitY(t)
            endif
            
            loop
                exitwhen i > TOTAL
                set datu = TARGET_ARRAY[i]
                if datu.u == u then
                call BJDebugMsg("MOVE TARGET")
                    call SetUnitX(datu.dummy, x)
                    call SetUnitY(datu.dummy, y)
                    if TARGET_FOLLOW == true then
                       set datu.t = t
                    endif
                    set datu  = TARGET_ARRAY[TOTAL]
                    set TOTAL = TOTAL - 1
                    set i = TOTAL + 1
                else
                    set i = i + 1
                    if i > TOTAL then
                      call BJDebugMsg("NEW")
                      call Marker.create( u, x, y, t )
                    endif
                    set datu = 0
                endif
            endloop

           return datu
      endmethod
    endstruct
    
    //==============================================================================================================    
    
    private function condition takes nothing returns boolean
        return ( GetIssuedOrderId() == String2OrderIdBJ(TARGET_ORDER_ID) or GetIssuedOrderId() == String2OrderIdBJ(TARGET_ORDER_ID2) )
    endfunction
    
    private function action takes nothing returns nothing

        call Marker.CheckMarker( GetTriggerUnit(), GetOrderPointX(), GetOrderPointY(), GetOrderTargetUnit())
    
    endfunction
    
    private function init takes nothing returns nothing
    
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
        call TriggerAddCondition(t, Filter(function condition))
        call TriggerAddAction(t, function action)

    endfunction
endlibrary


Keywords:
target, battle system, neku99, vjass, jass, system
Contents

Target System v0.01 (Map)

Reviews
20:00, 18th Dec 2010 The_Reborn_Devil: My review. Status: Approved Rating: Recommended
Level 5
Joined
Oct 24, 2007
Messages
90
I really like the system, it could prove useful and is a great idea that I have never seen made before. :)

However, why is it that, when I select the shop to buy stuff, Dust of Appearance (or any other random item) is bought automatically? You hear a lot of clicks and the message "You need more gold," and you can't buy anything else because of that.
 
Review

Review of version : 0.1
This Review is only for the system and not for the included spells!
Idea

I like your idea and i have only seen a few of these systems before so this is a quite good and useful thing to create

5/5
Coding

Your coding isn't bad but there are some things to improve:
1. Rename "untitled trigger 001"
2. remove the BJDebugMsg
3. you can start at 0 with your total varibale!
0 is a valid array index, too!
4.
JASS:
if data.dummy != null then
                  if TARGET_FOLLOW == true then
                     if data.t != null then
can be put together to
JASS:
if data.dummy != null and TARGET_FOLLOW and data.t != null then

note that these are not the only mistakes you made but that they are all not too bad ;)
practise a bit cause from this i can see that youre still learning vJass!
keep it up

3/5
Documentation

AWESOME!! everything explained and... wow :D

5/5
Result

Well you did a good job but even for the test map i think it would be better to make the arrow placeable by an ability or to make movement by arrow keys and then leave the marker on right click...
It's up to you ;)
nice idea and great documentation!
improve my points and your rating will go up ;)
+rep if you add something really special thats new with your system ;)
(i don't have anything in mind for that but something like "wow thats what this system is made for!!" ;D)

Overall: (5+3+5)/3 = 4.3 ==> 4
Vote for Approval: Yes
+rep: No
PM me when you want me to look over your ressource again
 
Level 10
Joined
Sep 3, 2009
Messages
458
Nice sistem, but maybe make arrow some smaller?

Thanks! Ok I'll do that and make it invisible so that you and your allies are then only one who can see it. :D

I really like the system, it could prove useful and is a great idea that I have never seen made before. :)

However, why is it that, when I select the shop to buy stuff, Dust of Appearance (or any other random item) is bought automatically? You hear a lot of clicks and the message "You need more gold," and you can't buy anything else because of that.

Yay thanks for liking my system!

AS for the buying in the shop thing , actually I made that shop to summon enemies for testing but I already had a spawn creep so yeah I should remove that. But the issue about the a lot of clicks is that, on the abilities for heroes, I used a mana shield and immolation as a base spell. It's because they don't cancel an order when cast. I made a trigger "untitled trigger 001" to keep pressing their hotkeys them when they are used. I believe that the hot keys got mixed up when you clicked the shop so yeah I'll be removing that shop.


Review of version : 0.1
This Review is only for the system and not for the included spells!
Idea

I like your idea and i have only seen a few of these systems before so this is a quite good and useful thing to create

5/5
Coding

Your coding isn't bad but there are some things to improve:
1. Rename "untitled trigger 001"
2. remove the BJDebugMsg
3. you can start at 0 with your total varibale!
0 is a valid array index, too!
4.
JASS:
if data.dummy != null then
                  if TARGET_FOLLOW == true then
                     if data.t != null then
can be put together to
JASS:
if data.dummy != null and TARGET_FOLLOW and data.t != null then

note that these are not the only mistakes you made but that they are all not too bad ;)
practise a bit cause from this i can see that youre still learning vJass!
keep it up

3/5
Documentation

AWESOME!! everything explained and... wow :D

5/5
Result

Well you did a good job but even for the test map i think it would be better to make the arrow placeable by an ability or to make movement by arrow keys and then leave the marker on right click...
It's up to you ;)
nice idea and great documentation!
improve my points and your rating will go up ;)
+rep if you add something really special thats new with your system ;)
(i don't have anything in mind for that but something like "wow thats what this system is made for!!" ;D)

Overall: (5+3+5)/3 = 4.3 ==> 4
Vote for Approval: Yes
+rep: No
PM me when you want me to look over your ressource again

Wow didn't expect such rating but anyway.

Yes I'm still learning vJass apparently so I still have many things to learn. As for the things you mentioned I'll be improving my code and release a better version.

Thanks for the review I'll try and give that special something on the system but I think I need a lot of figuring out what that is XD
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
Moderator Review:

Nice and unique idea! The coding looks good as well, but O(n) searches can be inefficient. You should use hashtables instead for your "GetMarker" function. Everything else looks good, and it's very well documented. Keep up!
 
Level 10
Joined
Sep 3, 2009
Messages
458
It doesn't work with hotkeys, sucks.
It is a easy system, even for GUI, so why vJass.

firstly , doesn't work with hotkeys? what do you mean?

secondly I used vJass cause it's a lot easier to do in vJass, deal with it -_-

FYI: I made a GUI of this once


...And its the users choice to not use it.

Secondly, this could be done by editing Game Interface options.

Firstly, of course it's the users choice to use it or not, duh.

Secondly, show me how to do it in Game Interface then -_-
 
Level 1
Joined
Jun 11, 2011
Messages
2
As sry as I am, but I can´t get this system to save.... I got JNGP, etc. and all systems save out of this. I always get the error:

temp is no type allowed . syntax

or sth. like that when Jass Helper is compiling.... But out of this really great system.
 
Level 1
Joined
Jun 11, 2011
Messages
2
I recently downloaded the newest JNGP but nothing. I will try to download the newest Jass Helper again, thank you for the hint.



//edit


Yeah that was it :vw_death: Thank you for the help again


//edit again....


Still not working... It saved, but map couldnt be opened by WC3 anymore. I read a tutorial to update Jass Helper again, updated JH, but still not working, same error as before

Error:
Code:
Line 198: datu is not of a type that allows . syntax



//Last edit


Now working, although i dont know why, deinstalled everything and reinstalled, and now it works. Thank you for your help Adiktuz.
 
Last edited:
Top