This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Topics - AGD
Pages: [1 ]
1
« on: November 08, 2016, 08:04:14 AM »
Category: ExecutionLanguage: vJASS, ZINC
True and False BooleanExpressions
Credits goes to Vexorian for the first idea.
Vjass version library BoolexprUtils
globals
boolexpr BOOLEXPR_TRUE
boolexpr BOOLEXPR_FALSE
endglobals
private module Init
private static method filterTrue takes nothing returns boolean
return true
endmethod
private static method filterFalse takes nothing returns boolean
return false
endmethod
private static method onInit takes nothing returns nothing
set BOOLEXPR_TRUE =
Filter (
function thistype .filterTrue)
set BOOLEXPR_TRUE =
Filter (
function thistype .filterFalse)
endmethod
endmodule
private struct S extends array
implement Init
endstruct
endlibrary
Zinc version //! zinc
library BoolexprUtils {
public boolexpr BOOLEXPR_TRUE, BOOLEXPR_FALSE;
module Init {
static method onInit () {
BOOLEXPR_TRUE =
Filter (
function () ->
boolean {
return true ;});
BOOLEXPR_FALSE =
Filter (
function () ->
boolean {
return false ;});
}
}
struct S extends array {module Init;}
}
//! endzinc
Rating
Average Score
« Created: November 08, 2016, 08:54:43 AM by moyack »
2
« on: November 02, 2016, 03:36:36 AM »
Category: UnitsLanguage: vJASS
Related Topics or Resources
A useful library which allows you to recycle units (even dead ones, but they must leave a corpse), avoiding yet another permanent 0.04kb memory leak for each future CreateUnit() call.
Script library UnitRecycler /* v1.3b
|=============|
| Author: AGD |
|=============|
*/ requires /*
*/ ReviveUnit /* http://wc3jass.com/4469/snippet-reviveunit/
*/ UnitDex /* http://www.hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/
*/ optional Table /* http://wc3jass.com/4611/snippet-new-table/
*/ optional TimerUtils /* http://wc3jass.com/5352/hibrid-timerutils/
*/ optional RegisterPlayerUnitEvent /* http://wc3jass.com/4907/snippet-registerplayerunitevent/
This system is important because CreateUnit() is one of the most processor-intensive function in
the game and there are reports that even after they are removed, they still leave some bit of memory
consumption (0.04 KB) on the RAM. Therefore it would be very helpful if you can minimize unit
creation or so. This system also allows you to recycle dead units to avoid permanent 0.04 KB memory
leak for each future CreateUnit() call. */
//! novjass
[Credits]
Aniki - For suggesting ideas on further improvements
|-----|
| API |
|-----|
function GetRecycledUnit takes player owner, integer rawCode, real x, real y, real facing returns unit /*
- Returns unit of specified ID from the stock of recycled units. If there's none in the stock that
matched the specified unit's rawcode, it will create a new unit instead
- Returns null if the rawcode's unit-type is a hero or non-existent
*/ function GetRecycledUnitEx takes player owner, integer rawCode, real x, real y, real facing returns unit /*
- Works similar to GetRecycledUnit() except that if the input rawcode's unit-type is a hero, it will
be created via CreateUnit() instead
- You can use this as an alternative to CreateUnit()
*/ function RecycleUnit takes unit u returns boolean /*
- Recycles the specified unit and returns a boolean value depending on the success of the operation
- Does nothing to hero units
*/ function RecycleUnitEx takes unit u returns boolean /*
- Works similar to RecycleUnit() except that if <u> is not recyclable, it will be removed via
RemoveUnit() instead
- You can use this as an alternative to RemoveUnit()
*/ function RecycleUnitDelayed takes unit u, real delay returns nothing /*
- Recycles the specified unit after <delay> seconds
*/ function RecycleUnitDelayedEx takes unit u, real delay returns nothing /*
- Works similar to RecycleUnitDelayed() except that it calls RecycleUnitEx() instead of RecycleUnit()
*/ function UnitAddToStock takes integer rawCode returns boolean /*
- Creates a unit of type ID and adds it to the stock of recycled units then returns a boolean value
depending on the success of the operation
*/ //! endnovjass
//CONFIGURATION SECTION
globals
/* The owner of the stocked/recycled units
*/ private constant player OWNER =
Player (15)
/* Determines if dead units will be automatically recycled
after a delay designated by the <constant function
DeathTime below>
*/ private constant boolean AUTO_RECYCLE_DEAD = true
/* Error debug message prefix
*/ private constant string ERROR_PREFIX = "|CFFFF0000Operation Failed: "
endglobals
/* The delay before dead units will be recycled in case AUTO_RECYCLE_DEAD == true */
static if AUTO_RECYCLE_DEAD then
private constant function DeathTime takes unit u returns real
/*if <condition> then
return someValue
elseif <condition> then
return someValue
endif */
return 8.00
endfunction
endif
/* When recycling a unit back to the stock, these resets will be applied to the
unit. You can add more actions to this or you can delete this textmacro if you
don't need it. */
//! textmacro_once UNIT_RECYCLER_RESET
//! endtextmacro
//END OF CONFIGURATION
/*==== Do not do changes below this line if you're not so sure on what you're doing ====*/
native UnitAlive takes unit u returns boolean
globals
private keyword S
private integer count = 0
private real unitCampX
private real unitCampY
private integer array stack
private boolean array stacked
endglobals
private function GetIndex takes integer rawCode returns integer
static if LIBRARY_Table then
local integer i = S.table.integer [rawCode]
if i == 0 then
set count = count + 1
set S.table.integer [rawCode] = count
set i = count
endif
else
if i == 0 then
set count = count + 1
set i = count
endif
endif
return i
endfunction
static if DEBUG_MODE then
private function Debug takes string msg returns nothing
endfunction
endif
function GetRecycledUnit takes player owner, integer rawCode, real x, real y, real facing returns unit
local integer i
set i = GetIndex(rawCode)
if stack[i] == 0 then
set bj_lastCreatedUnit =
CreateUnit (owner, rawCode, x, y, facing)
debug call Debug(
GetUnitName (bj_lastCreatedUnit) +
" stock is empty, creating new " +
GetUnitName (bj_lastCreatedUnit))
else
static if LIBRARY_Table then
set bj_lastCreatedUnit = S.hash[i].unit [stack[i]]
else
endif
set stacked[GetUnitId(bj_lastCreatedUnit)] = false
set stack[i] = stack[i] - 1
debug call Debug(
"Retrieving " +
GetUnitName (bj_lastCreatedUnit) +
" from stock" )
endif
debug if bj_lastCreatedUnit == null then
debug call Debug(ERROR_PREFIX + "Specified unit-type does not exist" )
debug endif
else
debug call Debug(ERROR_PREFIX + "Attemp to retrieve a hero unit" )
return null
endif
return bj_lastCreatedUnit
endfunction
function GetRecycledUnitEx takes player owner, integer rawCode, real x, real y, real facing returns unit
return GetRecycledUnit(owner, rawCode, x, y, facing)
endif
debug call Debug("Cannot retrieve a hero unit, creating new unit" )
endfunction
function RecycleUnit takes unit u returns boolean
local integer uDex = GetUnitId(u)
local integer i
if not IsHeroUnitId (rawCode)
and not stacked[uDex]
and u !=
null then set i = GetIndex(rawCode)
if not UnitAlive(u) and not ReviveUnit(u) then
debug call Debug(ERROR_PREFIX + "Unable to recycle unit: Unable to revive dead unit" )
return false
endif
set stacked[uDex] = true
//! runtextmacro optional UNIT_RECYCLER_RESET()
set stack[i] = stack[i] + 1
static if LIBRARY_Table then
set S.hash[i].unit [stack[i]] = u
else
endif
debug call Debug(
"Successfully recycled " +
GetUnitName (u))
return true
debug else
debug if stacked[uDex] then
debug call Debug(ERROR_PREFIX + "Attempt to recycle an already recycled unit" )
debug elseif u == null then
debug call Debug(ERROR_PREFIX + "Attempt to recycle a null unit" )
debug else
debug call Debug(ERROR_PREFIX + "Attempt to recycle a hero unit" )
debug endif
endif
return false
endfunction
function RecycleUnitEx takes unit u returns boolean
if not RecycleUnit(u) then
debug call Debug("Cannot recycle the specified unit, removing unit" )
return false
endif
return true
endfunction
//! textmacro DELAYED_RECYCLE_TYPE takes EX
private function RecycleTimer$EX$ takes nothing returns nothing
static if LIBRARY_TimerUtils then
call RecycleUnit$EX$(GetUnitById(GetTimerData(t)))
call ReleaseTimer(t)
else
static if LIBRARY_Table then
call RecycleUnit$EX$(S.hash[0].unit [key ])
call S.hash[0].remove(key )
else
endif
endif
set t = null
endfunction
function RecycleUnitDelayed$EX$ takes unit u, real delay returns nothing
static if LIBRARY_TimerUtils then
call TimerStart (NewTimerEx(GetUnitId(u)), delay,
false ,
function RecycleTimer$EX$)
else
static if LIBRARY_Table then
else
endif
call TimerStart (t, delay,
false ,
function RecycleTimer$EX$)
set t = null
endif
endfunction
//! endtextmacro
//! runtextmacro DELAYED_RECYCLE_TYPE("")
//! runtextmacro DELAYED_RECYCLE_TYPE("Ex")
function UnitAddToStock takes integer rawCode returns boolean
local unit u
local integer i
set u =
CreateUnit (OWNER, rawCode, unitCampX, unitCampY, 270)
if u != null then
set i = GetIndex(rawCode)
set stacked[GetUnitId(u)] = true
set stack[i] = stack[i] + 1
static if LIBRARY_Table then
set S.hash[i].unit [stack[i]] = u
else
endif
debug call Debug(
"Adding " +
GetUnitName (u) +
" to stock" )
return true
debug else
debug call Debug(ERROR_PREFIX + "Attemp to stock a null unit" )
endif
set u = null
debug else
debug call Debug(ERROR_PREFIX + "Attemp to stock a hero unit" )
endif
return false
endfunction
static if AUTO_RECYCLE_DEAD then
private function OnDeath takes nothing returns nothing
call RecycleUnitDelayed(u, DeathTime(u))
endif
set u = null
endfunction
endif
private module Init
static if LIBRARY_Table then
static TableArray hash
static Table table
else
endif
private static method onInit takes nothing returns nothing
static if AUTO_RECYCLE_DEAD then
static if LIBRARY_RegisterPlayerUnitEvent then
static if RPUE_VERSION_NEW then
call RegisterAnyPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function OnDeath)
else
call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_DEATH, function OnDeath)
endif
else
local code c = function OnDeath
local integer i = 16
loop
set i = i - 1
exitwhen i == 0
endloop
endif
endif
static if LIBRARY_Table then
set hash = TableArray[0x2000]
set table = Table.create ()
endif
// Hides recycled units at the top of the map beyond reach of the camera
set unitCampX = 0.00
set bounds = null
endmethod
endmodule
private struct S extends array
implement Init
endstruct
endlibrary
Rating
Average Score
« Created: June 30, 2017, 12:03:32 PM by moyack »
3
« on: September 04, 2016, 09:16:22 AM »
Category: ExecutionLanguage: vJASS
This snippet is a replacement to the BJ function
GetRandomSubGroup with the advantage of being able to directly enumerate random number of units in a group instead of creating another subgroup of an already existing group. Notice that this is not the same as
GroupEnumUnitsInRangeCounted in which case the enumerated units are not random but is based on which units are picked first.
library RandomIteration
globals
private integer unitCount
endglobals
private function EnumUnits takes nothing returns boolean
set unitCount = unitCount + 1
return false
endfunction
function EnumRandomUnitsInRangeCounted takes group g, real x, real y, real radius, integer limit returns nothing
local real chance
local unit u
set chance =
I2R (limit)/
I2R (unitCount)
loop
exitwhen u == null or limit == 0
set limit = limit - 1
endif
endloop
set u = null
endfunction
function EnumRandomUnitsInRectCounted takes group g, rect r, integer limit returns nothing
local real chance
local unit u
set chance =
I2R (limit)/
I2R (unitCount)
loop
exitwhen u == null or limit == 0
set limit = limit - 1
endif
endloop
set u = null
endfunction
endlibrary
Rating
Average Score
« Created: February 28, 2018, 12:59:36 PM by moyack »
4
« on: September 04, 2016, 12:09:44 AM »
Category: UnitsLanguage: vJASS
A simple snippet used to check if a unit is invulnerable. False positives from mana shields are also accounted for.
library InvulnerabilityChecker
function CheckInvulnerability takes unit u returns boolean
local boolean check
call UnitDamageTarget (u, u, 0.01,
true ,
false , ATTACK_TYPE_NORMAL, DAMAGE_TYPE_UNIVERSAL,
null )
return check
endfunction
endlibrary
5
« on: September 03, 2016, 10:49:40 PM »
Category: Execution, SystemLanguage: vJASS
Useful system especially in making an MUI spell which uses timers. Instead of saving the spell data in a hashtable with the handleid of the timer as the parent key, you can just use normal arrays with the timerid as the index. This also allows you to pass custom data (integer) to timers.
System Features:
Indexed timers (Array safe, 1-8190 but can also be customized to be 8190+) NEW Timer custom data (integer) attachment [NEW] Timer double free protection Automatic timer replacement (Useful safety feature which automatically replaces timers belonging to this system with a timer of the same timerid and handleid when destroyed) Timer Indexer v1.2 library TimerIndexer //v1.2
//! novjass
________________
| |
| Written by AGD |
|________________|
|=====|
| API |
|=====|
function GetTimer takes nothing returns timer /*
- Allocates a new usable timer from the stock
*/ function GetTimerEx takes integer i returns timer /*
- Retrieves a new usable timer from the stock and initializes
its custom integer data to <i>
*/ function GetTimerById takes integer i returns timer /*
- Retrieves a timer of ID <i> from the stock but returns
null if that timer is not free
*/ function FreeTimer takes timer t returns nothing /*
- Releases the timer back to the stock
*/ function GetTimerId takes timer t returns integer /*
- Returns the index of the timer
*/ function GetTimerData takes timer t returns integer /*
- Returns the custom integer data attached to the timer
*/ function SetTimerData takes timer t, integer i returns nothing /*
- Attaches a custom integer data to the timer
*/ function IsTimerStocked takes timer t returns boolean /*
- Checks if the timer is free
*/ function GetTimerFlag takes timer t returns boolean /*
- Checks if the timer is included in this system's timer stock
*/ //! endnovjass
globals
/*
Determines the total number of timers on the stock */
private constant integer TIMER_STOCK_SIZE = 8190
/* Determines the delay of timer replacement in case a
timer belonging to the stock is accidentally destroyed
Note that this value should be greater than the time
delay of the handleId recycling which is approximately
0.0050000 ( It's not advised to change this anyway ) */
private constant real REPLACE_DELAY = 0.0050001
endglobals
//================================================================
globals
private timer array T[TIMER_STOCK_SIZE]
private timer tempTimer
private integer START_HANDLE
private integer destroyed
private integer current
private integer pitStop
private integer this
private integer array recycler[TIMER_STOCK_SIZE]
private integer array data[TIMER_STOCK_SIZE]
private boolean dont = false
private boolean array isTimerStocked[TIMER_STOCK_SIZE]
endglobals
static if DEBUG_MODE then
private function Debug takes string msg returns nothing
endfunction
endif
function GetTimerId takes timer t returns integer
endfunction
function GetTimerData takes timer t returns integer
return data[GetTimerId(t)]
endfunction
function SetTimerData takes timer t, integer i returns nothing
set data[GetTimerId(t)] = i
endfunction
function IsTimerStocked takes timer t returns boolean
return isTimerStocked[GetTimerId(t)]
endfunction
function GetTimerFlag takes timer t returns boolean
return GetTimerId(t) > 0 and GetTimerId(t) <= TIMER_STOCK_SIZE
endfunction
function GetTimer takes nothing returns timer
set this = recycler[0]
set recycler[0] = recycler[this ]
if isTimerStocked[this ] then
set isTimerStocked[this ] = false
debug call Debug(
"Retrieving Timer [" +
I2S (
this ) +
"] from stock" )
return T[this ]
endif
debug call Debug("ERROR: No free timers available, creating a temporary timer." )
endfunction
function GetTimerById takes integer i returns timer
if isTimerStocked[i] then
debug call Debug(
"Retrieving Timer [" +
I2S (i) +
"] from stock" )
return T[i]
endif
debug if i < 1 or i > TIMER_STOCK_SIZE then
debug call Debug("ERROR: Specified timer ID is out of bounds" )
debug else
debug call Debug(
"ERROR: Timer [" +
I2S (i) +
"] is not free" )
debug endif
return null
endfunction
function GetTimerEx takes integer i returns timer
set tempTimer = GetTimer()
set data[GetTimerId(tempTimer)] = i
return tempTimer
endfunction
function FreeTimer takes timer t returns nothing
local integer i = GetTimerId(t)
if not isTimerStocked[i] and GetTimerFlag(t) then
set isTimerStocked[i] = true
set data[i] = 0
set recycler[i] = recycler[0]
set recycler[0] = i
debug call Debug(
"Releasing Timer [" +
I2S (i) +
"] back to the stock" )
elseif not GetTimerFlag(t) then
debug call Debug("ERROR: Freed timer does not belong to the stack, destroying timer" )
debug else
debug call Debug(
"ERROR: Attempt to double-free Timer [" +
I2S (i) +
"]" )
endif
endfunction
private function Replace takes nothing returns nothing
local integer i = destroyed
if GetTimerId(T[i]) == i then
set isTimerStocked[i] = true
debug call Debug(
"Timer [" +
I2S (GetTimerId(T[i])) +
"] was replaced" )
else
debug call Debug(
"ERROR: Unable to replace Timer [" +
I2S (i) +
"]" )
set dont = true
set dont = false
set T[i] = null
endif
endfunction
private function OnDestroy takes timer t returns nothing
local integer i = GetTimerId(t)
local trigger trig
if not dont and GetTimerFlag(t) then
set T[i] = null
set isTimerStocked[i] = false
set destroyed = i
call TimerStart (GetTimer(), REPLACE_DELAY,
false ,
function Replace)
debug call Debug(
"WARNING: Timer [" +
I2S (i) +
"] got destroyed!" )
set trig = null
endif
endfunction
private function Delegate takes nothing returns nothing
local integer i = current
loop
set i = i + 1
set isTimerStocked[i] = true
set recycler[i] = i + 1
if i == TIMER_STOCK_SIZE then
debug call Debug(
"Total number of timers created: " +
I2S (i))
debug call Debug("Timer stock count is complete" )
return
endif
exitwhen i == current + pitStop
endloop
set current = i
call Delegate.evaluate ()
endfunction
private module M
private static method onInit takes nothing returns nothing
local integer i = 1
if TIMER_STOCK_SIZE <= 8190 then
set pitStop = TIMER_STOCK_SIZE
else
set pitStop = 1000
endif
set recycler[TIMER_STOCK_SIZE] = 0
set recycler[0] = 1
set recycler[1] = 2
set isTimerStocked[i] = true
loop
set i = i + 1
set isTimerStocked[i] = true
set recycler[i] = i + 1
exitwhen i == pitStop
endloop
set current = i
if TIMER_STOCK_SIZE > current then
call Delegate.evaluate ()
debug else
debug call Debug(
"Total number of timers created: " +
I2S (i))
debug call Debug("Timer stock count is complete" )
endif
endmethod
endmodule
private struct S extends array
implement M
endstruct
endlibrary
Changelogs
6
« on: September 03, 2016, 10:32:39 PM »
Category: ExecutionLanguage: vJASS
Related Topics or Resources
Useful snippet for preloading your map resources and avoiding duplicates in preloading.
library ResourcePreloader /*v1.4
*/ uses /*
*/ BJObjectId /* http://wc3jass.com/5038/bjobjectid/
*/ optional Table /* http://wc3jass.com/4611/snippet-new-table/
*/ optional UnitRecycler /* http://wc3jass.com/5426/unitrecycler/
*/ //! novjass
|================|
| Written by AGD |
|================|
[CREDITS]
/* IcemanBo - for suggesting further improvements
Silvenon - for the sound preloading method */
|-----|
| API |
|-----|
function PreloadUnit takes integer rawcode returns nothing /*
- Assigns a certain type of unit to be preloaded
*/ function PreloadItem takes integer rawcode returns nothing /*
- Assigns a certain type of item to be preloaded
*/ function PreloadAbility takes integer rawcode returns nothing /*
- Assigns a certain type of ability to be preloaded
*/ function PreloadEffect takes string modelPath returns nothing /*
- Assigns a certain type of effect to be preloaded
*/ function PreloadSound takes string soundPath returns nothing /*
- Assigns a certain type of sound to be preloaded
*/ function PreloadUnitEx takes integer start, integer end returns nothing /*
- Assigns a range of unit rawcodes to be preloaded
*/ function PreloadItemEx takes integer start, integer end returns nothing /*
- Assigns a range of item rawcodes to be preloaded
*/ function PreloadAbilityEx takes integer start, integer end returns nothing /*
- Assigns a range of ability rawcodes to be preloaded
*/ //! endnovjass
//========================================================================================================//
/* Do not try to change below this line if you're not so sure on what you're doing. Unless you want to
change, check, or study the core of the system, it is not advised that you scroll any further. */
//========================================================================================================//
private keyword S
static if DEBUG_MODE then
private function Debug takes string msg returns nothing
endfunction
endif
//============================================== TextMacros ==============================================//
//! textmacro ASSIGN takes NAME, ARG, TYPE, INDEX, I
function Preload $NAME$
takes $ARG$ what
returns nothing static if LIBRARY_Table then
if not S.tb[$I$].boolean [$INDEX$] then
set S.tb[$I$].boolean [$INDEX$] = true
call Do$NAME$Preload(what)
debug else
debug call Debug("|CFFFF0000Operation Cancelled :|R Entered $TYPE$ data was already preloaded" )
endif
else
call Do$NAME$Preload(what)
debug else
debug call Debug("|CFFFF0000Operation Cancelled :|R Entered $TYPE$ data was already preloaded" )
endif
endif
endfunction
//! endtextmacro
//! textmacro ASSIGNWITHRANGE takes NAME
function Preload $NAME$Ex
takes integer start,
integer end
returns nothing local BJObjectId this = BJObjectId(start)
local BJObjectId last = BJObjectId(end)
loop
exitwhen this == last
if this > last then
set this = this .minus_1()
else
set this = this .plus_1()
endif
endloop
endfunction
//! endtextmacro
//========================================================================================================//
private function DoUnitPreload takes integer id returns nothing
static if LIBRARY_UnitRecycler then
else
endif
endfunction
private function DoItemPreload takes integer id returns nothing
endfunction
private function DoAbilityPreload takes integer id returns nothing
endif
endfunction
private function DoEffectPreload takes string path returns nothing
endfunction
private function DoSoundPreload takes string path returns nothing
local sound s =
CreateSound (path,
false ,
false ,
false , 10, 10,
"" )
set s = null
endfunction
//! runtextmacro ASSIGN("Unit", "integer", "unit", "what", "0")
//! runtextmacro ASSIGN("Item", "integer", "item", "what", "1")
//! runtextmacro ASSIGN("Ability", "integer", "ability", "what", "2")
//! runtextmacro ASSIGN("Effect", "string", "effect", "StringHash(what)", "3")
//! runtextmacro ASSIGN("Sound", "string", "sound", "StringHash(what)", "4")
//! runtextmacro ASSIGNWITHRANGE("Unit")
//! runtextmacro ASSIGNWITHRANGE("Item")
//! runtextmacro ASSIGNWITHRANGE("Ability")
//========================================================================================================//
private module Init
private static method onInit takes nothing returns nothing
static if LIBRARY_Table then
set tb = TableArray[5]
endif
set bounds = null
endmethod
endmodule
private struct S extends array
static if LIBRARY_Table then
static TableArray tb
else
endif
static unit dummy
implement Init
endstruct
endlibrary
7
« on: August 27, 2016, 10:29:10 PM »
Category: VariablesLanguage: vJASS
This simple snippet allows you to check for the walkability of the terrain between two points.
library IsLineWalkable /*
*/ uses /*
*/ TerrainPathability /*
- http://www.wc3c.net/showthread.php?t=103862 */
//! novjass
________________
| |
| Written by AGD |
|________________|
|=====|
| API |
|=====|
function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean /*
- Checks if the line between points P1(x1, y1) and P2(x2, y2) does not contain any
any unwalkable coordinates including some doodads, cliffs, mapboundary, and other similar stuffs
*/ function GetLastWalkableX takes nothing returns real /*
- Returns the value of the x-coordinate of the last walkable terrain when using IsLineWalkable
*/ function GetLastWalkableY takes nothing returns real /*
- Returns the value of the y-coordinate of the last walkable terrain when using IsLineWalkable
*/ //! endnovjass
globals
///////////////////////////////////////////
// The path walkability check distance //
// interval. Lower value increases //
// precision but may cost performance. //
// Suggested value limit (10.00 - 25.00) //
///////////////////////////////////////////
private constant real checkInterval = 20.00
endglobals
//==============================================================================
globals
private real X
private real Y
endglobals
function IsLineWalkable takes real x1, real y1, real x2, real y2 returns boolean
local real dx = x2 - x1
local real dy = y2 - y1
local real angle
local real x
local real y
if dx*dx + dy*dy < checkInterval*checkInterval then
if not IsTerrainWalkable(x2, y2) then
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return false
endif
else
set angle =
Atan2 (dy, dx)
set x = checkInterval*
Cos (angle)
set y = checkInterval*
Sin (angle)
loop
set x1 = x1 + x
set y1 = y1 + y
exitwhen x1 > x2 or y1 > y2
if not IsTerrainWalkable(x1, y1) then
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return false
endif
endloop
endif
set X = TerrainPathability_X
set Y = TerrainPathability_Y
return true
endfunction
function GetLastWalkableX takes nothing returns real
return X
endfunction
function GetLastWalkableY takes nothing returns real
return Y
endfunction
endlibrary
Rating
Average Score
« Created: February 01, 2018, 10:22:12 PM by moyack »
8
« on: August 27, 2016, 10:51:21 AM »
Category: Execution, SystemLanguage: vJASS
LoopCode v1.3 This system allows you to register a code that will run every specified timeout. Note that this system only uses one timer for all registered codes. Therefore, codes with periods indivisible by 0.03125 doesn't run with a constant time interval. Although the difference will not exceed 0.03125, you probably don't want it to be that way. But this will not be much of a problem for codes with low frequency period such as those with timeouts greater than 2 seconds since the difference wouldn't be so noticeable.
In short, this works best for codes with timeout divisible by 0.03125 seconds.
Main Script library LoopCode
//! novjass
________________
| |
| Written by AGD |
|________________|
|=====|
| API |
|=====|
function interface LoopCode takes nothing returns nothing /*
- Interface of functions to be registered in the loop
*/ function RegisterLoopCode takes LoopCode c, real timeout returns boolean /*
- Registers a code to run every <timeout> seconds and returns a boolean value depending
on the success of the operation
*/ function RemoveLoopCode takes LoopCode c returns boolean /*
- Unregisters a code from the loop and returns a boolean value depending
on the success of the operation
*/ function SetCodeTimeout takes LoopCode c, real timeout returns boolean /*
- Sets a new loop timeout for a code
*/ //! endnovjass
//======================================================================================
globals
private constant real TIMEOUT = 0.03125
private constant boolean AUTO_ADJUST = true
endglobals
//======================================================================================
globals
private LoopCode array codes
private integer id = 0
private integer count = 0
private real array codeTimeout
private real array elapsed
private integer array index
private boolean array check
endglobals
//======================================================================================
function interface LoopCode takes nothing returns nothing
static if DEBUG_MODE then
private function Debug takes string msg returns nothing
endfunction
endif
private function RunLoop takes nothing returns nothing
set id = 0
loop
set id = id + 1
set elapsed[id] = elapsed[id] + TIMEOUT
if elapsed[id] >= codeTimeout[id] then
call codes[id].evaluate ()
set elapsed[id] = elapsed[id] - codeTimeout[id]
endif
exitwhen id == count
endloop
endfunction
function RegisterLoopCode takes LoopCode c, real timeout returns boolean
static if AUTO_ADJUST then
if timeout < TIMEOUT then
set timeout = TIMEOUT
debug call Debug(
"Entered code execution timeout is less than the minimum value (" +
R2S (TIMEOUT) +
"), auto-adjusting timeout to (" +
R2S (TIMEOUT) +
")" )
endif
else
if timeout < TIMEOUT then
debug call Debug(
"ERROR: Entered code execution timeout is less than the minimum value (" +
R2S (TIMEOUT) +
")" )
return false
endif
endif
if not check[c] then
debug if timeout - (timeout/TIMEOUT)*TIMEOUT > 0.00 then
debug call Debug(
"WARNING: Entered code timeout is not divisible by " +
R2S (TIMEOUT) +
", this code's execution interval will not be even" )
debug endif
set count = count + 1
set elapsed[count] = 0.00
set codeTimeout[count] = timeout
set codes[count] = c
set index[c] = count
set check[c] = true
if count == 1 then
call TimerStart (Timer, TIMEOUT,
true ,
function RunLoop)
debug call Debug("There is one code instance registered, starting to run timer" )
endif
return true
endif
debug call Debug("ERROR: Attempt to double register a code" )
return false
endfunction
function RemoveLoopCode takes LoopCode c returns boolean
local integer i = index[c]
if check[c] then
debug call Debug("Removing a code from the loop" )
set check[c] = false
set index[codes[count]] = i
set codes[i] = codes[count]
set codeTimeout[i] = codeTimeout[count]
if id >= i then
set id = id - 1
endif
set count = count - 1
if count == 0 then
debug call Debug("There are no code instances running, stopping timer" )
endif
return true
endif
debug call Debug("ERROR: Attempt to remove a null or an already removed code" )
return false
endfunction
function SetCodeTimeout takes LoopCode c, real timeout returns boolean
local integer i = index[c]
if check[c] then
static if AUTO_ADJUST then
if codeTimeout[i] >= TIMEOUT then
set codeTimeout[i] = timeout
else
set codeTimeout[i] = TIMEOUT
debug call Debug(
"Entered code execution timeout is less than the minimum value (" +
R2S (TIMEOUT) +
"), auto-adjusting timeout to (" +
R2S (TIMEOUT) +
")" )
endif
return true
else
if codeTimeout[i] >= TIMEOUT then
set codeTimeout[i] = timeout
return true
endif
debug call Debug(
"ERROR: Entered code execution timeout is less than the minimum value (" +
R2S (TIMEOUT) +
")" )
return false
endif
endif
debug call Debug("ERROR: Specified code is not registered" )
return false
endfunction
endlibrary
Sample Script
scope MySpell initializer Init
globals
private constant real TIMEOUT = 0.03125
private integer maxIndex = 0
private real array elapsed
endglobals
private function Loop takes nothing returns nothing
local integer index = 0
loop
set index = index + 1
if elapsed < 10 then
set elapsed[index] = elapsed[index] + TIMEOUT
else
set elapsed[index] = elapsed[maxIndex]
set maxIndex = maxIndex - 1
set index = index - 1
if maxIndex == 0 then
call RemoveLoopCode(LoopCode.Loop)
endif
endif
exitwhen index == maxIndex
endloop
endfunction
private function OnCast takes nothing returns boolean
// Setup spell data and oncast effects
set maxIndex = maxIndex + 1
set elapsed[maxIndex] = 0.00
call RegisterLoopCode(LoopCode.Loop, TIMEOUT)
return false
endfunction
private function Init takes nothing returns nothing
endfunction
endscope
Changelogs Feedback will be appreciated.
9
« on: August 22, 2016, 02:06:44 AM »
Categories: System, GUI, vJASS
Rating:
5
« Created: June 03, 2017, 11:20:28 PM by moyack »
Related Topics or Resources
ILLUSION EDITOR This system provides users with helpful utilities with regards to creation of illusions as well as the manipulation of many of their aspects.
With this system, you can now create illusions of any type as easily as creating units. This even allows you to create permanent illusions.
Read the script header for more details.
Please give credits to the following people if you use this resource in your map.
Credits:
- AGD (Author)
- TriggerHappy (UnitDex)
- Looking_For_Help (PDDS)
- Bribe (table)
- Magtheridon96 (RegisterPlayerUnitEvent)
- Vexorian (TimerUtils)
- Rising_Dusk (GroupUtils)
- Alain.Mark (PlayerUtils)
Main Script library IllusionEditor /*
*/ requires /*
*/ UnitDex /*
http://www.hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/
*/ DamageEvent /*
http://www.hiveworkshop.com/threads/system-physical-damage-detection.228456/
*/ Table /*
http://www.hiveworkshop.com/threads/snippet-new-table.188084/
*/ optional RegisterPlayerUnitEvent /*
http://www.hiveworkshop.com/threads/snippet-registerplayerunitevent.203338/
*/ optional TimerUtils /*
http://www.wc3c.net/showthread.php?p=1020244
*/ optional GroupUtils /*
http://www.wc3c.net/showthread.php?t=104464
*/ optional PlayerUtils /*
http://www.hiveworkshop.com/threads/snippet-playerutils.213620/
*/ //! novjass
_______________________
| |
| Illusion Editor v1.3 |
| Written by AGD |
|_______________________|
/* This system gives you freedom and ease in creating illusions. With this, you
can now create illusions of any type as easily as creating units or make an
illusion copy from an already existing unit, with the ability to change many
of their aspects (such as duration, damage dealt, damage recieved, deathSFX,
and hero level) dynamically.
Hint:
- Use zero or any negative value for duration to make a permanent illusion
- Setting a hero illusion's level might cause a change to its proper name
To Import:
- Copy all the neccessary Object Editor data or alternatively use the object merger
- Copy this trigger/trigger category together with the requirements
- Configure the configurable object rawcodes
*/
|=======|
| API |
|=======|
function CreateIllusion takes player whichPlayer, integer ID, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit /*
- Creates an illusion of type <ID>
*/ function CopyUnit takes player whichPlayer, unit u, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit /*
- Creates an illusion copy of a unit which possesses the same abilities and items as the original unit
*/ function SetIllusionLevel takes unit u, integer level, boolean showEyeCandy returns boolean /*
- Sets the level of the illusion to a desired value and returns boolean value depending on the success of the operation
(Only works if the illusion is a hero and if it was created using this system)
*/ function SetIllusionDuration takes unit u, real time returns boolean /*
- Sets the duration of the illusion and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function AddIllusionDuration takes unit u, real extraTime returns boolean /*
- Adds an extra duration to an illusion's timed life and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function SetIllusionDamageFactor takes unit u, real factor returns boolean /*
- Sets the damagedealt factor of the illusion and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function SetIllusionReceiveFactor takes unit u, real factor returns boolean /*
- Sets the damagereceivefactor of the illusion and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function ShowIllusionDeathEffect takes unit u, boolean flag returns boolean /*
- Sets the illusion's death animation ON/OFF and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function SetIllusionDeathEffect takes unit u, string model returns boolean /*
- Sets the death animation of the illusion and returns a boolean value depending on the success of the operation
(This only works for illusions created by this system)
*/ function GetIllusionElapsedTime takes unit u returns real /*
- Returns the elapsed time of the illusion
(This will return 0 for illusions not created by this system)
*/ function GetIllusionRemainingDuration takes unit u returns real /*
- Returns the remaining duration of the illusion
(This will return 0 for illusions not created by this system)
*/ function GetIllusionTotalDuration takes unit u returns real /*
- Returns the duration of the illusion
(This will return 0 for illusions not created by this system)
*/ function GetIllusionDamageFactor takes unit u returns real /*
- Returns the damagedealt factor of the illusion
(This will return 0 for illusions not created by this system)
*/ function GetIllusionReceiveFactor takes unit u returns real /*
- Returns the damagereceive factor of the illusion
(This will return 0 for illusions not created by this system)
*/ function GetLastIllusion takes nothing returns unit /*
- Returns the last illusion created using this system
*/ function GetIllusionFlag takes unit u returns boolean /*
- Checks if the illusion is created by this system or not
*/ function IllusionDeathEvent takes code c returns nothing /*
- Adds a code to run when an illusion created from this system dies
*/ //! endnovjass
globals
///////////////////////////
// Configuration Section //
///////////////////////////
/////////////////////////////////////////////////////
// Rawcode of the item used for creating illusions //
/////////////////////////////////////////////////////
private constant integer ITEM_ID = 'I000'
/////////////////////////////////////////////////////
// Rawcode of the dummy caster //
/////////////////////////////////////////////////////
private constant integer DUMMY_ID = 'i001'
/////////////////////////////////////////////////////
// Illusion timed life check interval //
/////////////////////////////////////////////////////
private constant real LOOP_INTERVAL = 0.03125
/////////////////////////////////////////////////////
// Synchronize this value with the duration of //
// illusions produced by the the item in the //
// object editor so that this system will be able //
// to make the neccessary adjustments. //
// It would be better to set this value to 3600 //
// which is the maximum duration you can put in //
// the object editor. But always be reminded that //
// everytime you change this value, change also //
// that of the object editor's! //
/////////////////////////////////////////////////////
private constant real ITEM_DUR_LIMIT = 5.00
/////////////////////////////////////////////////////
// The remaining time of the illusion before it //
// would be replaced with another one in case the //
// desired duration of the illusion is greater //
// than what the item could provide //
/////////////////////////////////////////////////////
private constant real REPLACE_TIME_ALLOWANCE = 0.10
/////////////////////////////////////////////////////
// The default death animation of the illusions //
/////////////////////////////////////////////////////
private constant string DEFAULT_DEATH_SFX = "Abilities\\ Spells\\ Orc\\ MirrorImage\\ MirrorImageDeathCaster.mdl"
/////////////////////////////////////////////////////
// The owning player of the dummy unit //
/////////////////////////////////////////////////////
private constant player DUMMY_OWNER =
Player (15)
/////////////////////////////////////////////////////
// The prefix of the operation error message when //
// debug mode is enabled //
/////////////////////////////////////////////////////
private constant string ERROR_PREFIX = "Operation Failed: "
//////////////////////////
// End of Configuration //
//////////////////////////
endglobals
//===== Do not change anything below this line if you're not so sure on what you're doing =====//
native UnitAlive takes unit u returns boolean
private keyword S
globals
private HashTable hash
private trigger illuDeathTrig = null
private integer index = 0
private integer tempInt = 0
private integer usedDeathEvent = 0
private real illusionDeathEvent = 0.00
private unit illusion
private unit U
private unit dummyCaster
private item casterItem
private player localPlayer
private filterfunc deathHandler
private code durationUpdater
// These variables are used to store unit specific data for each illusion created using this system
private integer array maxTargeterCount
private integer array order
private integer array orderType
private boolean array flag
private boolean array check
private boolean array showDeath
private real array targPointX
private real array targPointY
private unit array orderTarget
private real array elapsed
private real array duration
private real array damageFactor
private real array receiveFactor
private real array X
private real array Y
private real array facing
private player array owner
private string array deathSFX
endglobals
static if DEBUG_MODE then
private function Debug takes string msg returns nothing
endfunction
endif
///////////////////////////////////////////////////
// These three functions caches the order of the //
// expiring illusion units to be passed to their //
// replacements. Similarly when the expiring //
// illusion is targeted with an order, the order //
// will be redirected to its replacement as well.//
///////////////////////////////////////////////////
private function CacheTargetOrder takes nothing returns nothing
local integer i = GetUnitId( u )
local integer tDex = GetUnitId( t )
if check[i] then
set orderType[i] = 1
set orderTarget[i] = t
endif
if check[tDex] then
if not flag[i] then
loop
set maxTargeterCount[tDex] = maxTargeterCount[tDex] + 1
if hash[tDex].unit [maxTargeterCount[tDex]] == null then
set hash[tDex].unit [maxTargeterCount[tDex]] = u
set flag[i] = true
break
endif
endloop
endif
endif
set u = null
set t = null
endfunction
private function CachePointOrder takes nothing returns nothing
set flag[i] = false
if check[i] then
set orderType[i] = 2
endif
endfunction
private function CacheOrder takes nothing returns nothing
set flag[i] = false
if check[i] then
set orderType[i] = 3
endif
endfunction
///////////////
// On Summon //
///////////////
private function OnSummon takes nothing returns nothing
local timer t
local integer i
local integer uDex
set i = GetUnitId( dummyCaster )
set uDex = GetUnitId( U )
set check[uDex] = true
set showDeath[uDex] = true
set duration[uDex] = duration[i]
set damageFactor[uDex] = damageFactor[i]
set receiveFactor[uDex] = receiveFactor[i]
set owner[uDex] = owner[i]
set deathSFX[uDex] = DEFAULT_DEATH_SFX
set elapsed[uDex] = 0
set maxTargeterCount[uDex] = 0
static if LIBRARY_TimerUtils then
set t = NewTimer()
else
endif
call TimerStart ( t, LOOP_INTERVAL,
true , durationUpdater )
else
endif
set t = null
endif
endfunction
//! textmacro CREATOR takes FUNC, TAKE, X, TARGET
private function $FUNC$ takes player whichPlayer, $TAKE$, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
local integer i = GetUnitId( dummyCaster )
$X$local
unit tempUnit =
CreateUnit ( DUMMY_OWNER, ID, x, y, angle )
if dur < 0 then
set dur = 0
endif
if damageDealt < 0 then
set damageDealt = 0
endif
if damageReceived < 0 then
set damageReceived = 0
endif
set X[i] = x
set Y[i] = y
set duration[i] = dur
set damageFactor[i] = damageDealt
set receiveFactor[i] = damageReceived
set facing[i] = angle
set owner[i] = whichPlayer
$X$set tempUnit = null
return U
endfunction
//! endtextmacro
//! runtextmacro CREATOR( "Create", "integer ID", "", "tempUnit" )
//! runtextmacro CREATOR( "Copy", "unit u", "//", "u" )
/////////////////////////////////////////////////
// This function controls the duration of the //
// illusions as well as replacing them in case //
// their hardcoded lifetime expires before //
// meeting the duration desired for them //
/////////////////////////////////////////////////
private function AdjustTimedLife takes nothing returns nothing
local integer i = GetUnitId( u )
local integer lastOrder
local unit new
local real toAdd
if UnitAlive( u ) and u != null then
set elapsed[i] = elapsed[i] + LOOP_INTERVAL
if duration[i] < ITEM_DUR_LIMIT and ( ( duration[i] > 0 and elapsed[i] >= duration[i] ) or duration[i] < 0.00 ) then
static if LIBRARY_TimerUtils then
call ReleaseTimer( t )
else
endif
elseif elapsed[i] >= ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE then
set toAdd = duration[i] - ( ITEM_DUR_LIMIT - REPLACE_TIME_ALLOWANCE )
if toAdd < 0 then
set toAdd = 0
endif
//! textmacro REDIRECTDATA takes KEY, NEWLIFE, NEWMANA
set index = 0
loop
set index = index + 1
set U = hash[$KEY$].unit [index]
set tempInt = GetUnitId( U )
if U != null and flag[tempInt] then
set flag[tempInt] = false
endif
exitwhen index > maxTargeterCount[i]
endloop
if orderType[i] == 1 then
elseif orderType[i] == 2 then
elseif orderType[i] == 3 then
endif
endif
set maxTargeterCount[i] = 0
set index = GetUnitId( new )
set deathSFX[index] = deathSFX[i]
set showDeath[index] = showDeath[i]
//! endtextmacro
//! runtextmacro REDIRECTDATA( "i", "GetWidgetLife( u )", "GetUnitState( u, UNIT_STATE_MANA )" )
set showDeath[i] = false
static if LIBRARY_TimerUtils then
call ReleaseTimer( t )
else
endif
if u == illusion then
set illusion = new
endif
set new = null
endif
endif
set t = null
set u = null
endfunction
/////////////////////////////////
// Public APIs //
/////////////////////////////////
function CreateIllusion takes player whichPlayer, integer ID, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
set illusion = Create( whichPlayer, ID, dur, damageDealt, damageReceived, x, y, angle )
return illusion
endfunction
function CopyUnit takes player whichPlayer, unit u, real dur, real damageDealt, real damageReceived, real x, real y, real angle returns unit
set illusion = Copy( whichPlayer, u, dur, damageDealt, damageReceived, x, y, angle )
return illusion
endfunction
function SetIllusionLevel takes unit u, integer level, boolean showEyeCandy returns boolean
local integer i = GetUnitId( u )
local integer lastOrder
local unit tempUnit
local unit new
local real x
local real y
local boolean success = false
if check[i] then
set new = Copy( owner[i], tempUnit, duration[i], damageFactor[i], receiveFactor[i], x, y,
GetUnitFacing ( u ) )
set index = 0
loop
set index = index + 1
exitwhen index == 6
endloop
//! runtextmacro REDIRECTDATA( "GetUnitId( u )", "GetWidgetLife( u )*GetWidgetLife( new )/GetUnitState( u, UNIT_STATE_MAX_LIFE )", "GetUnitState( u, UNIT_STATE_MANA )*GetUnitState( new, UNIT_STATE_MANA )/GetUnitState( u, UNIT_STATE_MAX_MANA )" )
if showEyeCandy then
endif
set success = true
set tempUnit = null
set new = null
debug else
debug call Debug( ERROR_PREFIX + "Specified illusion is not a hero" )
endif
debug else
debug call Debug( ERROR_PREFIX + "Specified unit is not an illusion created by the system" )
endif
return success
endfunction
//! textmacro DEBUG takes RETURN
if not check[i] then
debug call Debug( ERROR_PREFIX + "Specified unit is not an illusion created by the system" )
$RETURN$
endif
//! endtextmacro
function SetIllusionDuration takes unit u, real time returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set duration[i] = time
return true
endfunction
function AddIllusionDuration takes unit u, real extraTime returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set duration[i] = duration[i] + extraTime
return true
endfunction
function SetIllusionDamageFactor takes unit u, real factor returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set damageFactor[i] = factor
return true
endfunction
function SetIllusionReceiveFactor takes unit u, real factor returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set receiveFactor[i] = factor
return true
endfunction
function ShowIllusionDeathEffect takes unit u, boolean flag returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set showDeath[i] = flag
return true
endfunction
function SetIllusionDeathEffect takes unit u, string model returns boolean
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "return false" )
set deathSFX[i] = model
return true
endfunction
function GetIllusionElapsedTime takes unit u returns real
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "" )
return elapsed[i]
endfunction
function GetIllusionRemainingDuration takes unit u returns real
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "" )
return duration[i] - elapsed[i]
endfunction
function GetIllusionTotalDuration takes unit u returns real
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "" )
return duration[i]
endfunction
function GetIllusionDamageFactor takes unit u returns real
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "" )
return damageFactor[i]
endfunction
function GetIllusionReceiveFactor takes unit u returns real
local integer i = GetUnitId( u )
//! runtextmacro DEBUG( "" )
return receiveFactor[i]
endfunction
function GetLastIllusion takes nothing returns unit
return illusion
endfunction
function GetIllusionFlag takes unit u returns boolean
return check[GetUnitId( u )]
endfunction
function IllusionDeathEvent takes code c returns nothing
if illuDeathTrig == null then
endif
endfunction
////////////////////////////////////////////////
// This function adjusts the damage dealt and //
// taken by the illusions //
////////////////////////////////////////////////
private function DamageAdjustment takes nothing returns nothing
local integer uDex = GetUnitId( PDDS.source )
local integer tDex = GetUnitId( PDDS.target )
if check[uDex] and check[tDex] then
set PDDS.amount = PDDS.amount*damageFactor[uDex]*receiveFactor[tDex]
elseif check[uDex] then
set PDDS.amount = PDDS.amount*damageFactor[uDex]
elseif check[tDex] then
set PDDS.amount = PDDS.amount*receiveFactor[tDex]
endif
endfunction
////////////////////////////////////////////////
// Registers an illusion death event //
////////////////////////////////////////////////
private function RefreshDeathTrigger takes nothing returns nothing
local unit u
static if LIBRARY_GroupUtils then
loop
exitwhen u == null
if check[GetUnitId( u )] then
endif
endloop
else
loop
exitwhen u == null
if check[GetUnitId( u )] then
endif
endloop
endif
endfunction
////////////////////////////////////////////////
// This function is responsible for hiding or //
// showing the illusion's death SFX //
////////////////////////////////////////////////
private function OnDeath takes nothing returns nothing
local integer i = GetUnitId( u )
set illusionDeathEvent = 0
set illusionDeathEvent = 1
set illusionDeathEvent = 0
if showDeath[i] then
endif
set usedDeathEvent = usedDeathEvent + 1
if usedDeathEvent == 30 then
set usedDeathEvent = 0
call RefreshDeathTrigger()
endif
set u = null
endfunction
///////////////////////////////////////////////
// Initialization //
///////////////////////////////////////////////
private module M
static method onInit takes nothing returns nothing
local code c = function OnDeath
static if LIBRARY_RegisterPlayerUnitEvent then
call RegisterPlayerUnitEventForPlayer( EVENT_PLAYER_UNIT_SUMMON, function OnSummon, DUMMY_OWNER )
call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, function CacheTargetOrder )
call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, function CachePointOrder )
call RegisterPlayerUnitEvent( EVENT_PLAYER_UNIT_ISSUED_ORDER, function CacheOrder )
else
local code c1 = function OnSummon
local code c2 = function CacheTargetOrder
local code c3 = function CachePointOrder
local code c4 = function CacheOrder
set index = 16
loop
set index = index - 1
static if LIBRARY_PlayerUtils then
else
endif
exitwhen index == 0
endloop
endif
set deathHandler =
Filter ( c )
call AddDamageHandler( function DamageAdjustment )
set durationUpdater = function AdjustTimedLife
set hash = HashTable.create ()
set dummyCaster =
CreateUnit ( DUMMY_OWNER, DUMMY_ID, 0, 0, 0 )
endmethod
endmodule
private struct S extends array
static if not LIBRARY_GroupUtils then
endif
implement M
endstruct
endlibrary
Illusion Editor ObjectMerger ILLUSION EDITOR OBJECT MERGER
//!| [ ILLUSION EDITOR OBJECT MERGER ] |
/*
Paste this script to your map and it save it. Close your map, open it again and disable/delete this script.
Now you have the all the object data needed for the Illusion Editor in your map.
*/
//! external ObjectMerger w3u nzin i001 anam "Dummy" ansf "(Illusion Editor)" uabi "Ainv, Aloc" ucbs 0 ushr 0 umdl "dummy.mdl" upat "" unbm 0 usid 1000000000 usin 1000000000
//! external ObjectMerger w3a Alil I002 anam "illu" atat "" lild 1 1 lilw 1 1 aare 1 0 aran 1 99999 ahdu 1 5 adur 1 5 atar 1 "air,alive,allies,ancient,bridge,dead,debris,decoration,enemies,friend,ground,hero,invulnerable,item,mechanical,neutral,nonancient,nonhero,nonsapper,notself,organic,player,self,structure,sapper,terrain,tree,vulnerable,wall,ward"
//! external ObjectMerger w3t will I000 anam "" iabi "illu" icla "Permanent" igol 0 iuse 0
GUI Support library IllusionEditorGUISupport uses IllusionEditor
private function Operate takes nothing returns nothing
if udg_IE_Operation == 0 then
set udg_IE_Illusion = GetLastIllusion()
return
elseif udg_IE_Operation == udg_IE_CreateIllusion then
set udg_IE_Illusion = CreateIllusion( udg_IE_Owner, udg_IE_UnitType, udg_IE_Duration, udg_IE_DamageDealtFactor, udg_IE_DamageReceiveFactor,
GetLocationX ( udg_IE_Position ),
GetLocationY ( udg_IE_Position ), udg_IE_Facing )
set udg_IE_Operation = 0
set udg_IE_Owner = null
set udg_IE_UnitType = 0
set udg_IE_Duration = 0.00
set udg_IE_DamageDealtFactor = 0.00
set udg_IE_DamageReceiveFactor = 0.00
set udg_IE_Facing = 0.00
return
elseif udg_IE_Operation == udg_IE_CopyUnit then
set udg_IE_Illusion = CopyUnit( udg_IE_Owner, udg_IE_BaseUnit, udg_IE_Duration, udg_IE_DamageDealtFactor, udg_IE_DamageReceiveFactor,
GetLocationX ( udg_IE_Position ),
GetLocationY ( udg_IE_Position ), udg_IE_Facing )
set udg_IE_Operation = 0
set udg_IE_Owner = null
set udg_IE_BaseUnit = null
set udg_IE_Duration = 0.00
set udg_IE_DamageDealtFactor = 0.00
set udg_IE_DamageReceiveFactor = 0.00
set udg_IE_Facing = 0.00
return
elseif udg_IE_Operation == udg_IE_SetLevel then
set udg_IE_Flag = SetIllusionLevel( udg_IE_Illusion, udg_IE_NewLevel, udg_IE_Flag )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_SetDuration then
set udg_IE_Flag = SetIllusionDuration( udg_IE_Illusion, udg_IE_Duration )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_AddDuration then
set udg_IE_Flag = AddIllusionDuration( udg_IE_Illusion, udg_IE_Duration )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_SetDamageFactor then
set udg_IE_Flag = SetIllusionDamageFactor( udg_IE_Illusion, udg_IE_DamageDealtFactor )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_SetReceiveFactor then
set udg_IE_Flag = SetIllusionReceiveFactor( udg_IE_Illusion, udg_IE_DamageReceiveFactor )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_ShowDeathEffect then
set udg_IE_Flag = ShowIllusionDeathEffect( udg_IE_Illusion, udg_IE_Flag )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_SetDeathEffect then
set udg_IE_Flag = SetIllusionDeathEffect( udg_IE_Illusion, udg_IE_DeathEffect )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_GetRemainingDuration then
set udg_IE_Duration = GetIllusionRemainingDuration( udg_IE_Illusion )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_GetTotalDuration then
set udg_IE_Duration = GetIllusionTotalDuration( udg_IE_Illusion )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_GetDamageFactor then
set udg_IE_DamageDealtFactor = GetIllusionDamageFactor( udg_IE_Illusion )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_GetReceiveFactor then
set udg_IE_DamageReceiveFactor = GetIllusionReceiveFactor( udg_IE_Illusion )
set udg_IE_Operation = 0
return
elseif udg_IE_Operation == udg_IE_GetFlag then
set udg_IE_Flag = GetIllusionFlag( udg_IE_Illusion )
set udg_IE_Operation = 0
return
endif
endfunction
endlibrary
function InitTrig_GUI_Support takes nothing returns nothing
/* We use an InitTrig function instead of a scope/library
initializer to initialize the values of our variables to
make sure that InitGlobals() runs first so that the values
of our variables would not be reset. */
call Trig_GUI_IllusionEditor_Documentation_Actions.execute ()
endfunction
GUI Support Documentation Trigger: Test 1385267532
GUI IllusionEditor Documentation Events Conditions Actions -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||| GUI ILLUSION EDITOR GUIDE |||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- First you need to choose what operation you want to do using the system. Like this: -------- Set IE_Operation = IE_CreateIllusion -------- It can be any from the list below: -------- -------- -------- -------- 1. CreateIllusion - creates an illusion of a certain unit-type. -------- -------- 2. CopyUnit - creates a mirror image of a unit which possesses the same items and abilities -------- -------- as the original unit. -------- -------- 3. SetLevel - sets the level of a hero type illusion to a desired value. -------- -------- 4. SetDuration - sets the total duration of an illusion to a desired value, if the given amount -------- -------- is less than the elapsed time of the illusion, it will be destroyed. -------- -------- 5. AddDuration - adds an extra time to an illusion's duration. -------- -------- 6. SetDamageFactor - sets the damage dealt factor of an illusion. -------- -------- 7. SetReceiveFactor - sets the damage receive factor of an illusion -------- -------- 8. ShowDeathEffect - shows/hides the death effect of an illusion. -------- -------- 9. SetDeathEffect - sets a new special effect to replace the default death effect of an -------- -------- illusion. -------- -------- 10. GetRemainingDuration - gets the remaining duration of an illusion. -------- -------- 11. GetTotalDuration - gets the total duration of an illusion. -------- -------- 12. GetDamageFactor - gets the damage dealt factor of an illusion. -------- -------- 13. GetReceiveFactor - gets the damage receive factor of an illusion. -------- -------- 14. GetFlag - checks if the illusion was created using this system or not. -------- -------- -------- -------- Next, you have to setup all the data necessary for the operation you chose. Below are the -------- -------- list of data needed for each operation (Note that all these have an IE_ prefix): -------- -------- -------- -------- 1. - Owner -------- -------- - UnitType -------- -------- - Duration -------- -------- - DamageDealtFactor -------- -------- - DamageReceiveFactor -------- -------- - Position -------- -------- - Facing -------- -------- -------- -------- 2. - Owner -------- -------- - BaseUnit -------- -------- - Duration -------- -------- - DamageDealtFactor -------- -------- - DamageReceiveFactor -------- -------- - Position -------- -------- - Facing -------- -------- -------- -------- 3. - Illusion -------- -------- - NewLevel -------- -------- - Flag -------- -------- -------- -------- 4, 5. - Illusion -------- -------- - Duration -------- -------- -------- -------- 6. - Illusion -------- -------- - DamageDealtFactor -------- -------- -------- -------- 7. - Illusion -------- -------- - DamageReceiveFactor -------- -------- -------- -------- 8. - Illusion -------- -------- - Flag -------- -------- -------- -------- 9. - Illusion -------- -------- - DeathEffect -------- -------- -------- -------- 10, 11, 12, 13, 14. - Illusion -------- -------- -------- -------- The example we chose is CreateIllusion operation. So as you can see in number 1, we -------- -------- need to setup those variables so now we do: -------- Set IE_Owner = Player 1 (Red) Set IE_UnitType = Mortar Team Set IE_Duration = 5.00 Set IE_DamageDealtFactor = 0.35 Set IE_DamageReceiveFactor = 4.00 Set IE_Position = (Center of (Playable map area)) Set IE_Facing = Default building facing -------- -------- -------- And finally, what we have to do is execute the operation which in this case is very simple. -------- -------- To execute the opertation we have to use this: -------- Do nothing -------- Easy right? Plus we are also able to add a new functionality to the previously useless -------- -------- <Do nothing> function. ^-^ -------- -------- -------- -------- -------- -------- ======================================================================= -------- -------- -------- -------- -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||| CONSTANTS SETTING ||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- Set IE_CreateIllusion = 1 Set IE_CopyUnit = 2 Set IE_SetLevel = 3 Set IE_SetDuration = 4 Set IE_AddDuration = 5 Set IE_SetDamageFactor = 6 Set IE_SetReceiveFactor = 7 Set IE_ShowDeathEffect = 8 Set IE_SetDeathEffect = 9 Set IE_GetRemainingDuration = 10 Set IE_GetTotalDuration = 11 Set IE_GetDamageFactor = 12 Set IE_GetReceiveFactor = 13 Set IE_GetFlag = 14 -------- -------- -------- -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- -------- Do not enable the following line. However, they are variable creators so do not delete them. -------- -------- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| -------- Set IE_Operation = 0 Set IE_NewLevel = 0 Set IE_DamageDealtFactor = 0.00 Set IE_DamageReceiveFactor = 0.00 Set IE_Duration = 0.00 Set IE_Facing = 0.00 Set IE_Illusion = No unit Set IE_Owner = Player 1 (Red) Set IE_UnitType = No unit-type Set IE_BaseUnit = No unit Set IE_Position = IE_Position Set IE_Flag = False Set IE_DeathEffect = -------- ======================================================================= --------
Rating
Average Score
« Created: May 23, 2017, 12:34:50 PM by moyack »
Show previous
Average Score
« Created: February 01, 2017, 06:46:10 PM by AGD »
Pages: [1 ]