ertaboy356b
Old School Gamer
- Reaction score
- 86
JASS:
library unitpath uses KT, ExplodeString, RealXY
struct Path
//! runtextmacro PUI()
string pathway // the pathway.. works in this format = "1%2%3%4" where % is a seperator that will be used for Exploding the string later in the script.
integer currentpath
integer numofstr
unit target
endstruct
private function CheckPath takes nothing returns boolean
local Path wp = Path(KT_GetData())
local ExpString a
set a = ExplodeString(wp.pathway,"%",wp.numofstr) // Explodes the string.. gets a[0] = "1", a[1] = "2" etc.
// Check Distance
if DistanceBetweenXY(GetUnitX(wp.target),GetUnitY(wp.target),PointsX[S2I(a[wp.currentpath])],PointsY[S2I(a[wp.currentpath])]) <= 100 then // checks if unit is near the destination..
set wp.currentpath = wp.currentpath+1 // If it is, then set the next path
endif
if IsUnitUncommandable(wp.target) == true then // The conditions are incomplete yet.. This checks if unit is Uncommandable by player.. If it does, the unit will be issued an order.
call IssuePointOrder(wp.target,"attack",PointsX[S2I(a[wp.currentpath])],PointsY[S2I(a[wp.currentpath])]) // Order unit to move to destination...
call PingMinimap(PointsX[S2I(a[wp.currentpath])],PointsY[S2I(a[wp.currentpath])],5) // This is for debugging purposes.. use to determine the current path the unit is issued upon
endif
call a.destroy()
if GetUnitState(wp.target,UNIT_STATE_LIFE) <= 0 then // Check if unit is dead.. If it is, end this function
return true
else
return false
endif
endfunction
function AttachPath takes unit u, integer w returns nothing
local Path wp = Path<u>
local ExpString a
if wp == 0 then
set wp = Path.create()
set Path<u> = wp
endif
set wp.pathway = Waypoints[w]
set wp.currentpath = 0
set wp.target = u
set wp.numofstr = NumberOfWays[w]
set a = ExplodeString(wp.pathway,"%",wp.numofstr)
call IssuePointOrder(wp.target,"attack",PointsX[S2I(a[wp.currentpath])],PointsY[S2I(a[wp.currentpath])]) // Move target to the first point of the path
call a.destroy()
call KT_Add(function CheckPath, wp, 1) // Timer system..
endfunction
endlibrary</u></u>
I have this library.. I tested it with one unit.. and it works!!
I want to know if this system will lag with 100 units at least..
This unit is a waypoint system designed for my map..
I added some comments in the script just in case.. If you want, I can upload the map..
Please let me know if you can't understand the comments..