- Joined
- Jul 31, 2012
- Messages
- 2,217
:3 oh...kay 
Edit: PS: gone for a bath..
Edit: PS: gone for a bath..

*Ahem* Just like any other WEHZ group thread, KB3D got some off topic comments about japan, how the day was, and other things. So the number of comments don't really make it popular.The System has 180+ comments! within just 12 days!!
function GetNearestUnitInGroupFromXY takes real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2+y2*y2)
local real dist2
set bj_ghoul[0]=u // Replace with a global variable you defined
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2+y2*y2)
if (dist1>dist2) then
set dist1=dist2
set bj_ghoul[0]=u // Replace with a global variable you defined
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return bj_ghoul[0] // Replace with a global variable you defined
endfunction
function GetNearestUnitInGroupFromXY takes real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2 + y2*y2) // there should be a 'space' here to prevent the (x2*x2) to be added to y2 and then the sum will be multiplied by y2
local real dist2
local unit U=u
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2+y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
function GetNearestUnitInGroupFromXY takes unit U, real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2 + y2*y2)
local real dist2
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2+y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
function Call takes group g returns nothing
local unit U
local real x = 0
local real y = 0
local unit u = GetNearestUnitInGroupFromXY(U, x, y, g)
function Call takes group g returns nothing
local real x = 0
local real y = 0
local unit u = GetNearestUnitInGroupFromXY(u, x, y, g)
// First unit argument can be any null unit
// Final argument group (g) is the group where the function is called (something like this [the explanation]
function GetNearestUnitInGroupFromXY takes unit U, real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2 + y2*y2)
local real dist2
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2+y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
//Example Usage:
function Call takes group g returns nothing
local unit U
local real x = 0
local real y = 0
set U = GetNearestUnitInGroupFromXY(U,x,y,g)
endfunction
set dist2=SquareRoot(x2*x2 + y2*y2)
for the JPAG stuff. local real dist2
set U=FirstOfGroup(g)
call GroupRemoveUnit(g,u)
loop
set u=FirstOfGroup(g)
// First unit argument can be any null unit
// Final argument group (g) is the group where the function is called (something like this [the explanation]
function GetNearestUnitInGroupFromXY takes unit U, real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=9999999999
local real dist2
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2+y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
//Example Usage:
function Call takes group g returns nothing
local unit U
local real x = 0
local real y = 0
set U = GetNearestUnitInGroupFromXY(U,x,y,g)
endfunction
function GetNearestUnitInGroupFromXY takes unit U, real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2 + y2*y2)
local real dist2
set U=u
call GroupRemoveUnit(g,u)
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2 + y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
//Example Usage:
function Call takes group g returns nothing
local unit U
local real x = 0
local real y = 0
set U = GetNearestUnitInGroupFromXY(U,x,y,g)
endfunction
set U=FirstOfGroup(g)
call GroupRemoveUnit(g,U)//U not u
function GetNearestUnitInGroupFromXY takes unit U, real x1, real y1, group g returns unit
local unit u=FirstOfGroup(g)
local real x2=GetUnitX(u)-x1
local real y2=GetUnitY(u)-y1
local real dist1=SquareRoot(x2*x2 + y2*y2)
local real dist2
set U=u
call GroupRemoveUnit(g,u)
loop
set u=FirstOfGroup(g)
exitwhen u==null
set x2=GetUnitX(u)-x1
set y2=GetUnitY(u)-y1
set dist2=SquareRoot(x2*x2 + y2*y2)
if (dist1>dist2) then
set dist1=dist2
set U=u
endif
call GroupRemoveUnit(g,u)
endloop
set u=null
return U
endfunction
//Example Usage:
function Call takes group g returns nothing
local unit U
local real x = 0
local real y = 0
set U = GetNearestUnitInGroupFromXY(U,x,y,g)
endfunction
if FirstOfGroup(g) == null then
else
//Blabla
endif
if FirstOfGroup(g) != null then
//Do some stuff