Moderator
M
Moderator
|
(1 ratings)
//------------------------------------------------------------------------------------------
// Check Walkability 1.08 (by ZibiTheWand3r3r)
// Thanks Almia, IcemanBo, Chaosy, BPower for help and tips.
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks walkability by: SetUnitPosition + Blink ability.
//
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in ()
// then modify in globals section.
//
// --API--
// function CheckPathing takes real x, real y, integer collisionSize returns boolean
// use argument collisionSize: COLLISION_SIZE_16 or COLLISION_SIZE_32 or COLLISION_SIZE_48
// function returns true if point (x, y) is walkable for given-size units
//------------------------------------------------------------------------------------------
library CheckWalkability initializer CheckWalkabilityInit
globals
// user configuration: use Ctrl-D in ObjectEditor to see id of ability:
// if Blink-PathChecker ability id diffrent then A000, then type here the actual value:
private constant integer ABILITY_ID = 'A000'
// if Dummy16(peon) unit id diffrent then o000, then type here the actual value:
private constant integer DUMMY_ID_16 = 'o000'
// if Dummy32(grunt) unit id diffrent then o001, then type here the actual value:
private constant integer DUMMY_ID_32 = 'o001'
// if Dummy48(tauren) unit id diffrent then o002, then type here the actual value:
private constant integer DUMMY_ID_48 = 'o002'
//----------------------- don't change anything below -------------------------------------------
constant integer COLLISION_SIZE_16 = 16
constant integer COLLISION_SIZE_32 = 32
constant integer COLLISION_SIZE_48 = 48
private unit array checker
endglobals
//---------------------- initialization function -----------------------------------------------------
function CheckWalkabilityInit takes nothing returns nothing
set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), DUMMY_ID_16, 0.00, 0.00, 0.00)
set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), DUMMY_ID_32, 0.00, 0.00, 0.00)
set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), DUMMY_ID_48, 0.00, 0.00, 0.00)
call UnitAddAbility(checker[COLLISION_SIZE_16], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_16], false)
call UnitAddAbility(checker[COLLISION_SIZE_32], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_32], false)
call UnitAddAbility(checker[COLLISION_SIZE_48], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_48], false)
endfunction
//------------------------ main function -------------------------------------------------
function CheckPathing takes real x, real y, integer collisionSize returns boolean
debug if checker[collisionSize] == null then
debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
debug return false
debug endif
call SetUnitPosition(checker[collisionSize], x, y)
if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
call SetUnitX(checker[collisionSize], 0.00)
call SetUnitY(checker[collisionSize], 0.00)
return IssuePointOrder(checker[collisionSize], "blink", x, y)
endif
endif
return false
endfunction
endlibrary
|
if IssuePointOrder(udg_PathChecker[1], "blink", GetUnitX(udg_PathChecker[1])+1, GetUnitY(udg_PathChecker[1])+1) then
return true
endif
return IssuePointOrder(udg_PathChecker[1], "blink", GetUnitX(udg_PathChecker[1])+1, GetUnitY(udg_PathChecker[1])+1)
Do you mean that native sometimes fails with checking path? Or what disadvantages you refer to?The idea of using SetUnitPosition is not new, however this native comes with some disadvantages (mainly unit enter region event).
For this reason using an item is better.
Almia, why? Is it not working?
//------------------------------------------------------------------------------------------
// Check Walkability 1.02 (by ZibiTheWand3r3r)
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks by: SetUnitPosition + Blink ability.
//
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in ()
// then modify in CheckWalkabilityInit function.
//
// --API--
// function CheckPathing16 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 16-size units (peon size)
// function CheckPathing32 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 32-size units (grunt size)
// function CheckPathing48 takes real x, real y returns boolean
// returns true if point (x, y) is walkable for 48-size units (tauren size)
//
// Use function CheckPathing48 to be sure that point (x, y) is walkable for all units
//------------------------------------------------------------------------------------------
library CheckWalkability initializer CheckWalkabilityInit
globals
integer BlinkPathCheckerAbility
unit udg_Dummy16
unit udg_Dummy32
unit udg_Dummy48
endglobals
//----------------
function CheckWalkabilityInit takes nothing returns nothing
//--------------------------------------------------------------------------------------------------
// use Ctrl-D in ObjectEditor to see number of ability:
// if Blink-PathChecker ability number diffrent then A000, then type here the actual value:
set BlinkPathCheckerAbility = 'A000' // Blink-PathChecker ability
// if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
set udg_Dummy16 = CreateUnit(Player(15), 'o000', 0.00, 0.00, 0.00) //Dummy16(peon)
// if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
set udg_Dummy32 = CreateUnit(Player(15), 'o001', 0.00, 0.00, 0.00) //Dummy32(grunt)
// if Dummy16(peon) unit number diffrent then o000, then type here the actual value:
set udg_Dummy48 = CreateUnit(Player(15), 'o002', 0.00, 0.00, 0.00) //Dummy48(tauren)
//---------------------------------------------------------------------------------------------------
call UnitAddAbility(udg_Dummy48, BlinkPathCheckerAbility) //blink ability
call UnitAddAbility(udg_Dummy48, 'Avul')
call ShowUnit(udg_Dummy48, false)
call UnitAddAbility(udg_Dummy32, BlinkPathCheckerAbility)
call UnitAddAbility(udg_Dummy32, 'Avul')
call ShowUnit(udg_Dummy32, false)
call UnitAddAbility(udg_Dummy16, BlinkPathCheckerAbility)
call UnitAddAbility(udg_Dummy16, 'Avul')
call ShowUnit(udg_Dummy16, false)
endfunction
function CheckPathing16 takes real x, real y returns boolean
call SetUnitPosition(udg_Dummy16, x, y)
if x == GetUnitX(udg_Dummy16) and y == GetUnitY(udg_Dummy16) then
return IssuePointOrder(udg_Dummy16, "blink", GetUnitX(udg_Dummy16)+1., GetUnitY(udg_Dummy16)+1.)
endif
return false
endfunction
function CheckPathing32 takes real x, real y returns boolean
call SetUnitPosition(udg_Dummy32, x, y)
if x == GetUnitX(udg_Dummy32) and y == GetUnitY(udg_Dummy32) then
return IssuePointOrder(udg_Dummy32, "blink", GetUnitX(udg_Dummy32)+1., GetUnitY(udg_Dummy32)+1.)
endif
return false
endfunction
function CheckPathing48 takes real x, real y returns boolean
call SetUnitPosition(udg_Dummy48, x, y)
if x == GetUnitX(udg_Dummy48) and y == GetUnitY(udg_Dummy48) then
return IssuePointOrder(udg_Dummy48, "blink", GetUnitX(udg_Dummy48)+1., GetUnitY(udg_Dummy48)+1.)
endif
return false
endfunction
endlibrary
. Got compile error. Used BJDebugMsg. Is this script ok:debug error: Invalid argument, allowed is 16, 32, 48
function CheckPathing takes real x, real y, integer size returns boolean
local integer s=48
if size==16 or size==32 or size==48 then
set s=size
else
call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48. Now script used 48 insted of " + I2S(size))
endif
call SetUnitPosition(udg_DummyPath[s], x, y)
if x == GetUnitX(udg_DummyPath[s]) and y == GetUnitY(udg_DummyPath[s]) then
return IssuePointOrder(udg_DummyPath[s], "blink", GetUnitX(udg_DummyPath[s])+1., GetUnitY(udg_DummyPath[s])+1.)
endif
return false
endfunction
public
keyword if you want.globals
constant integer COLLISION_SIZE_16 = 16
// 32, 48
private unit array checker// Create on init checker[16], checker[32], and checker[48]
endglobals
// Valid arguments for collisionSize are 16, 32, 48
// Define constants as they can be use, instead of magic numbers.
function CheckPathing takes real x, real y, integer collisionSize return boolean
debug if checker[collisionSize] == null then
debug call (ErrorMsg)// debug only prints error.
debug return false
debug endif
call SetUnitPosition(checker[collisionSize], x, y)
// continue your script as before.
endfunction
// Good and read-able
library x
globals
endglobals
function Ex takes nothing returns nothing
return
endfunction
endlibrary
// Shitty format, hard to read
// Conclusion: spacing is very important.
library x1
globals
endglobals
function ex takes nothing returns nothing
return
endfunction
endlibrary
What do you mean with it?I think you should use external object to create both units and ability.
function CheckWalkabilityInit takes nothing returns nothing
set checker[16] = CreateUnit(Player(15), dummy16Id, 0.00, 0.00, 0.00) //Dummy16(peon)
set checker[32] = CreateUnit(Player(15), dummy32Id, 0.00, 0.00, 0.00) //Dummy32(grunt)
set checker[48] = CreateUnit(Player(15), dummy48Id, 0.00, 0.00, 0.00) //Dummy48(tauren)
call UnitAddAbility(checker[16], blinkPathCheckerAbility)
call UnitAddAbility(checker[16], 'Avul')
call ShowUnit(checker[16], false)
call UnitAddAbility(checker[32], blinkPathCheckerAbility)
call UnitAddAbility(checker[32], 'Avul')
call ShowUnit(checker[32], false)
call UnitAddAbility(checker[48], blinkPathCheckerAbility)
call UnitAddAbility(checker[48], 'Avul')
call ShowUnit(checker[48], false)
endfunction
private function CheckWalkabilityInit takes nothing returns nothing
set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), dummy16Id, 0.00, 0.00, 0.00) //Dummy16(peon)
set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), dummy32Id, 0.00, 0.00, 0.00) //Dummy32(grunt)
set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), dummy48Id, 0.00, 0.00, 0.00) //Dummy48(tauren)
call UnitAddAbility(checker[COLLISION_SIZE_16], blinkPathCheckerAbility)
call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_16], false)
call UnitAddAbility(checker[COLLISION_SIZE_32], blinkPathCheckerAbility)
call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_32], false)
call UnitAddAbility(checker[COLLISION_SIZE_48], blinkPathCheckerAbility)
call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_48], false)
endfunction
ShowUnit
and 'avul'
?? call UnitAddAbility(checker[16], blinkPathCheckerAbility)
call UnitAddAbility(checker[16], 'Avul')
call ShowUnit(checker[16], false)
call UnitAddAbility(checker[32], blinkPathCheckerAbility)
call UnitAddAbility(checker[32], 'Avul')
call ShowUnit(checker[32], false)
call UnitAddAbility(checker[48], blinkPathCheckerAbility)
call UnitAddAbility(checker[48], 'Avul')
call ShowUnit(checker[48], false)
Blink cannot be executed to the same location where caster is. I set minimum range=0 for Blink ability in Object Editor, but target point must be shifted by any small value.Why does the blink location has to differ by an offset of 1 from the location in question? ( honest question )
Could you explain this to me?
ShowUnit+Avul works, locust don't.Also, locust will not work instead of ShowUnit and 'avul' ??
Unfortunately snippet can fire events like Unit enter/leaves regionJust for insurance, is it possible that unit enters region triggers when dummies enter them?
In conclusion your system is not accurate. Can't you shift that value by 0.0001 or something else really small?Blink cannot be executed to the same location where caster is. I set minimum range=0 for Blink ability in Object Editor, but target point must be shifted by any small value.
Made few tests and your idea works well, code will be a bit diffrent:may i ask why it should be really small? can't we just make a dummy on the edge of the map, have the Blink a global range and so on? How about SetUnitPosition?
function CheckPathing takes real x, real y, integer collisionSize returns boolean
debug if checker[collisionSize] == null then
debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
debug return false
debug elseif IsUnitPaused(checker[collisionSize]) then
debug call BJDebugMsg(" Error: path checker unit is paused.")
debug return false
debug endif
call SetUnitPosition(checker[collisionSize], x, y)
if x == GetUnitX(checker[collisionSize]) and y == GetUnitY(checker[collisionSize]) then
call SetUnitX(checker[collisionSize], 0.00)
call SetUnitY(checker[collisionSize], 0.00)
return IssuePointOrder(checker[collisionSize], "blink", x, y)
endif
return false
endfunction
RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02
if x == GetUnitX(checker[collisionSize]) then
I have a few questions towards how this system is working.
Why do we need the coimbination of SetUnitPosition and blink?
I'm aware of possible SetUnitPosition failures, but since the finally outcome
is based on the capability of blinking to x/y, why do we need SetUnitPosition in
the first place?
call SetUnitPosition(u, 2147483647, 2147483647)
Why do we need the coimbination of SetUnitPosition and blink?
I'm aware of possible SetUnitPosition failures, but since the finally outcome
is based on the capability of blinking to x/y, why do we need SetUnitPosition in
the first place?
call SetUnitPosition(checker[collisionSize], 0.00, 0.00)
call IssuePointOrder(checker[collisionSize], "blink", x, y)
if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
return true
endif
endif
return false
private
keyword should be used if the user doesn't need access to something.globals
constant integer blinkPathCheckerAbility = 'A000'
constant integer dummy16Id = 'o000'
constant integer dummy32Id = 'o001'
constant integer dummy48Id = 'o002'
constant integer COLLISION_SIZE_16 = 16
constant integer COLLISION_SIZE_32 = 32
constant integer COLLISION_SIZE_48 = 48
constant unit array checker
endglobals
globals
private constant integer ABILITY_ID = 'A000'// Capital letters, JPAG code convention.
private constant integer DUMMY_ID_16 = 'o000'
private constant integer DUMMY_ID_32 = 'o001'
private constant integer DUMMY_ID_48 = 'o002'
constant integer COLLISION_SIZE_16 = 16// public? See explanation below.
constant integer COLLISION_SIZE_32 = 32
constant integer COLLISION_SIZE_48 = 48
private unit array checker// Can not be constant, obviously
endglobals
public
keyword: public constant integer EXAMPLE = 1
// Use from somewhere:
checker[Library_EXAMPLE]// Variable added library prefix to be unique.
constant integer EXAMPLE = 1
// Use from somewhere
checker[EXAMPLE]// No prefix, may conflic with another global named EXMAPLE
public
keyword.constant integer LIBRARY_EXMAPLE = 1
to imitate what the public keyword does.constant integer COLLISION_SIZE_16
//------------------------------------------------------------------------------------------
// Check Walkability 1.08 (by ZibiTheWand3r3r)
// Thanks Almia, IcemanBo, Chaosy, BPower for help and tips.
//
// This snippet allows to check if given point is walkable for 48-size unit, 32-size unit and 16-size unit.
// It uses 3 dummy units + 1 custom ability. It checks walkability by: SetUnitPosition + Blink ability.
//
// How to import:
// 1. Copy this this trigger to your map.
// 2. From Object Editor copy custom ability named: Blink-PathChecker (A000) and
// three custom units: Dummy16 (o000), Dummy32 (o001) and Dummy48 (o002).
// 3. Use Ctrl+D to check copied units/ability numbers. If they differ from those given in ()
// then modify in globals section.
//
// --API--
// function CheckPathing takes real x, real y, integer collisionSize returns boolean
// use argument collisionSize: COLLISION_SIZE_16 or COLLISION_SIZE_32 or COLLISION_SIZE_48
// function returns true if point (x, y) is walkable for given-size units
//------------------------------------------------------------------------------------------
library CheckWalkability// initializer Init
globals
// user configuration: use Ctrl-D in ObjectEditor to see id of ability:
// if Blink-PathChecker ability id diffrent then A000, then type here the actual value:
private constant integer ABILITY_ID = 'A000'
// if Dummy16(peon) unit id diffrent then o000, then type here the actual value:
private constant integer DUMMY_ID = 'zsmc'//'o000'
// if Dummy32(grunt) unit id diffrent then o001, then type here the actual value:
//private constant integer DUMMY_ID_32 = 'o001'
// if Dummy48(tauren) unit id diffrent then o002, then type here the actual value:
//private constant integer DUMMY_ID_48 = 'o002'
//----------------------- don't change anything below -------------------------------------------
//constant integer COLLISION_SIZE_16 = 16
//constant integer COLLISION_SIZE_32 = 32
//constant integer COLLISION_SIZE_48 = 48
//private unit array checker
private unit u=null
endglobals
//------------------------ main function -------------------------------------------------
function IsPointWalkable/*CheckPathing*/ takes real x, real y/*, integer collisionSize*/ returns boolean
/*debug if checker[collisionSize] == null then
debug call BJDebugMsg(" Invalid argument, allowed is 16, 32, 48, use pre-defined keys to avoid malfunction")
debug return false
debug endif
call SetUnitPosition(checker[collisionSize], x, y)
if RAbsBJ(x-GetUnitX(checker[collisionSize])) <= 0.02 then
if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
call SetUnitX(checker[collisionSize], 0.00)
call SetUnitY(checker[collisionSize], 0.00)
return IssuePointOrder(checker[collisionSize], "blink", x, y)
endif
endif*/
call SetUnitPosition(u,x,y)
if(RAbsBJ(x-GetUnitX(u))<=.02 and RAbsBJ(y-GetUnitY(u))<=.02)then
//if RAbsBJ(y-GetUnitY(checker[collisionSize])) <= 0.02 then
call SetUnitX(u,0)
call SetUnitY(u,0)
return IssuePointOrderById(u,852525,x,y) and IssueImmediateOrderById(u,851973)//IssuePointOrder(u, "blink", x, y)
//endif
endif
return false
endfunction
//---------------------- initialization function -----------------------------------------------------
private module Init
static method onInit takes nothing returns nothing
/*set checker[COLLISION_SIZE_16] = CreateUnit(Player(15), DUMMY_ID_16, 0.00, 0.00, 0.00)
set checker[COLLISION_SIZE_32] = CreateUnit(Player(15), DUMMY_ID_32, 0.00, 0.00, 0.00)
set checker[COLLISION_SIZE_48] = CreateUnit(Player(15), DUMMY_ID_48, 0.00, 0.00, 0.00)
call UnitAddAbility(checker[COLLISION_SIZE_16], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_16], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_16], false)
call UnitAddAbility(checker[COLLISION_SIZE_32], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_32], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_32], false)
call UnitAddAbility(checker[COLLISION_SIZE_48], ABILITY_ID)
call UnitAddAbility(checker[COLLISION_SIZE_48], 'Avul')
call ShowUnit(checker[COLLISION_SIZE_48], false)*/
set u=CreateUnit(Player(15),DUMMY_ID,0,0,0)
call UnitAddAbility(u,ABILITY_ID)
call UnitAddAbility(u,'Avul')
call UnitRemoveAbility(u,'Aatk')
call ShowUnit(u,false)
endmethod
endmodule
private struct i extends array
implement Init
endstruct
endlibrary