i need a attack detection for this knockback system:
map link: http://www.hiveworkshop.com/forums/pastebin_data/uvmka9/_files/001.w3x
Any questions? Just ask!
thanks
map link: http://www.hiveworkshop.com/forums/pastebin_data/uvmka9/_files/001.w3x
JASS:
//TESH.scrollpos=17
//TESH.alwaysfold=0
library IsTerrainWalkable initializer Init
globals
// this value is how far from a point the item may end up for the point to be considered pathable
private constant real MAX_RANGE=10.
// the following two variables are set to the position of the item after each pathing check
// that way, if a point isn't pathable, these will be the coordinates of the nearest point that is
public real X=0.
public real Y=0.
private rect r
private item check
private item array hidden
private integer hiddenMax = 0
endglobals
private function Init takes nothing returns nothing
set check=CreateItem('ciri',0,0)
call SetItemVisible(check,false)
set r=Rect(0.0,0.0,128.0,128.0)
endfunction
private function HideBothersomeItem takes nothing returns nothing
if IsItemVisible(GetEnumItem()) then
set hidden[hiddenMax]=GetEnumItem()
call SetItemVisible(hidden[hiddenMax],false)
set hiddenMax=hiddenMax+1
endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
// first, hide any items in the area so they don't get in the way of our item
call MoveRectTo(r,x,y)
call EnumItemsInRect(r,null,function HideBothersomeItem)
// try to move the check item and get it's coordinates
call SetItemPosition(check,x,y)//this unhides the item...
set X=GetItemX(check)
set Y=GetItemY(check)
call SetItemVisible(check,false)//...so we must hide it again
// before returning, unhide any items that got hidden at the start
loop
exitwhen hiddenMax<=0
set hiddenMax=hiddenMax-1
call SetItemVisible(hidden[hiddenMax],true)
set hidden[hiddenMax]=null
endloop
// return pathability status
return (x-X)*(x-X)+(y-Y)*(y-Y)<MAX_RANGE*MAX_RANGE
endfunction
endlibrary
JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
library angleBetweenXY
function angleBetweenXY takes real xa, real ya, real xb, real yb returns real
return bj_RADTODEG*Atan2(yb-ya,xb-xa)
endfunction
endlibrary
JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
library remainingPlayers
globals
private integer counter=0
private group tempGroup=CreateGroup()
endglobals
private function f takes nothing returns boolean
if GetUnitTypeId(GetFilterUnit())=='h000' and GetWidgetLife(GetFilterUnit())>=1 then
set counter=counter+1
endif
return false
endfunction
function remainingPlayers takes nothing returns integer
set counter=0
call GroupEnumUnitsInRect(tempGroup,bj_mapInitialPlayableArea,Filter(function f))
return counter
endfunction
endlibrary
JASS:
//TESH.scrollpos=83
//TESH.alwaysfold=0
scope kb
private struct kData
unit u
real direction
integer power
integer gravPull
boolean friction
boolean killsTouchees
endstruct
globals
private timer time=CreateTimer()
private kData array kDB
private integer dbIndex=-1
private group GROUP=CreateGroup()
private unit tempBomb
private real tempGravPull
private player tempOwner
endglobals
private function f takes nothing returns boolean
if GetUnitTypeId(GetFilterUnit())=='h000' then
call SetUnitExploded(GetFilterUnit(),true)
call KillUnit(GetFilterUnit())
endif
return false
endfunction
private function f2 takes nothing returns boolean
local real angleTowards=angleBetweenXY(GetUnitX(GetFilterUnit()),GetUnitY(GetFilterUnit()),GetUnitX(tempBomb),GetUnitY(tempBomb))
local real distance=SquareRoot(((GetUnitX(GetFilterUnit())-GetUnitX(tempBomb))*(GetUnitX(GetFilterUnit())-GetUnitX(tempBomb)))+((GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))*(GetUnitY(GetFilterUnit())-GetUnitY(tempBomb))))
if GetOwningPlayer(GetFilterUnit())!=tempOwner then
call SetUnitX(GetFilterUnit(),GetUnitX(GetFilterUnit())+(tempGravPull-distance)/20*Cos(angleTowards*bj_DEGTORAD))
call SetUnitY(GetFilterUnit(),GetUnitY(GetFilterUnit())+(tempGravPull-distance)/20*Sin(angleTowards*bj_DEGTORAD))
endif
return false
endfunction
private function p takes nothing returns nothing
local integer index=0
local kData tempDat
local real x
local real y
loop
exitwhen index>dbIndex
set tempDat=kDB[index]
set x=GetUnitX(tempDat.u)+tempDat.power*Cos(tempDat.direction*bj_DEGTORAD)
set y=GetUnitY(tempDat.u)+tempDat.power*Sin(tempDat.direction*bj_DEGTORAD)
if IsTerrainWalkable(x,y) then
call SetUnitX(tempDat.u,x)
call SetUnitY(tempDat.u,y)
else
set tempDat.direction=0-tempDat.direction
set x=GetUnitX(tempDat.u)+tempDat.power*Cos(tempDat.direction*bj_DEGTORAD)
set y=GetUnitY(tempDat.u)+tempDat.power*Sin(tempDat.direction*bj_DEGTORAD)
if IsTerrainWalkable(x,y) then
call SetUnitX(tempDat.u,x)
call SetUnitY(tempDat.u,y)
else
set tempDat.direction=tempDat.direction-180
endif
if tempDat.friction then
set tempDat.power=tempDat.power*3/4
endif
endif
if tempDat.killsTouchees then
call GroupEnumUnitsInRange(GROUP,GetUnitX(tempDat.u),GetUnitY(tempDat.u),70,Filter(function f))
endif
if tempDat.friction then
set tempDat.power=tempDat.power-1
endif
if GetUnitState(tempDat.u,UNIT_STATE_LIFE)<1 then
set tempDat.power=tempDat.power-1
endif
if tempDat.gravPull>0 then
set tempBomb=tempDat.u
set tempGravPull=tempDat.gravPull
set tempOwner=GetOwningPlayer(tempDat.u)
call GroupEnumUnitsInRange(GROUP,GetUnitX(tempDat.u),GetUnitY(tempDat.u),tempDat.gravPull,Filter(function f2))
endif
if tempDat.power<0 then
call tempDat.destroy()
set kDB[index]=kDB[dbIndex]
set dbIndex=dbIndex-1
if dbIndex==-1 then
call PauseTimer(time)
endif
endif
set index=index+1
endloop
endfunction
function knockb takes unit u, real direction, integer power, boolean friction, boolean killsTouchees, integer gravPull returns nothing
local kData tempDat=kData.create()
set tempDat.u=u
set tempDat.direction=direction
set tempDat.power=power
set tempDat.friction=friction
set tempDat.killsTouchees=killsTouchees
set tempDat.gravPull=gravPull
set dbIndex=dbIndex+1
set kDB[dbIndex]=tempDat
if dbIndex==0 then
call TimerStart(time,.03,true,function p)
endif
endfunction
endscope
Any questions? Just ask!
thanks