Moderator
M
//============================================================================================
// 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