Добавлен Bornikkeny
LibMath дополнительная библиотека
library LibMath
function GetAngleXY takes real x, real y, real xx, real yy returns real
return bj_RADTODEG * Atan2(yy - y, xx - x)
endfunction
function GetDisXY takes real x, real y, real xx, real yy returns real
return SquareRoot((xx-x) * (xx-x) + (yy-y) * (yy-y))
endfunction
function CreateRectXY takes real x, real y, real radius returns rect
return Rect(x - radius, y - radius, x + radius, y + radius)
endfunction
function GetAliveUnit takes unit u returns boolean
if GetWidgetLife(u) > 0.405 then
return true
else
return false
endif
endfunction
function GetXYRect takes real x, real y, rect r returns boolean
local real Xmax = GetRectMaxX(r)
local real Ymax = GetRectMaxY(r)
local real Xmin = GetRectMinX(r)
local real Ymin = GetRectMinY(r)
if x>=Xmin and x<=Xmax and y<=Ymax and y>=Ymin then
return true
else
return false
endif
endfunction
function DistanceBetweenPointsX takes real x,real y,real xx,real yy returns real
local real dx = xx - x
local real dy = yy - y
return SquareRoot(dx * dx + dy * dy)
endfunction
function GetPolarX takes real x, real f, real d returns real
return x + Cos(f*0.0174)*d
endfunction
function GetPolarY takes real y, real f, real d returns real
return y + Sin(f*0.0174)*d
endfunction
function GetZ takes real X, real Y returns real
call MoveLocation(GZL,X,Y)
return GetLocationZ(GZL)
endfunction
function GetUnitsInGroup takes group g returns integer
local integer i = 0
local group gg = g
local unit u
loop
set u = FirstOfGroup(gg)
exitwhen u == null
set i = i + 1
call GroupRemoveUnit(gg,u)
endloop
call DestroyGroup(g)
set gg = null
return i
endfunction
function GetTargetOffset takes unit host, unit target, real speedm returns real
local real speedt = GetUnitMoveSpeed(target)
local real x = GetUnitX(host)
local real y = GetUnitY(host)
local real xx = GetUnitX(target)
local real yy = GetUnitY(target)
local real fac = GetUnitFacing(target)
local real dis = GetDisXY(x,y,xx,yy)
local real time = dis/speedm
local real dispost = GetDisXY(xx,yy,GetPolarX(xx,fac,time*speedt),GetPolarY(yy,fac,time*speedt))
local real X = GetPolarX(xx,fac,dispost)
local real Y = GetPolarY(yy,fac,dispost)
return GetAngleXY(x,y,X,Y)
endfunction
endlibrary
А тут основная проблема:
Код
library MeatHook initializer Init_Hook uses LibMath //Функции типа GetAngleXY, GetPolarX(Y),GetDisXY
globals
mhook ahook[100]
integer ihook = -1
endglobals
struct xar
unit u[300]
integer i = 0
endstruct
struct mhook
unit host = null
unit target = null
real face = 0
real speed = 0
unit head = null
real headdis = 0
real headdismax = 0
integer chaini = 0
xar chain[100]
real targetx = 0
real targety = 0
real scale = 0
integer move = 1
integer i = 0
static method Create takes unit host, real tx, real ty, real scale returns mhook
local mhook h = mhook.create()
local integer i = GetPlayerId(GetOwningPlayer(host))
local real x = GetUnitX(host)
local real y = GetUnitY(host)
local real f = GetAngleXY(x,y,tx,ty)
set h.host = host
set h.face = f
set h.speed = 600
set h.head = CreateUnit(Player(i),'h007',GetPolarX(GetUnitX(host),f,h.scale/2),GetPolarY(GetUnitY(host),f,h.scale/2),f)
set h.headdismax = 1400
set h.targetx = tx
set h.targety = ty
set h.scale = scale
set h.chain[ihook+1] = xar.create()
set h.chain[ihook+1].u[0] = h.head
set h.i = i
call UnitAddAbility(h.head,'Amrf')
call UnitAddAbility(h.head,'Amrf')
call SetUnitFlyHeight(h.head,50,0)
call SetUnitPathing(h.head,false)
return h
endmethod
method Start takes nothing returns boolean
if ihook < 1000 then
set ihook = ihook + 1
set ahook[ihook] = this
return true
else
return false
endif
endmethod
method Destroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i > this.chaini
//call RemoveUnit(this.chain[i])
set this.chain[ihook].u[i] = null
set i = i + 1
endloop
set i = 0
set this.chain[ihook].u[this.chaini+1] = null
call this.chain[ihook].destroy()
call RemoveUnit(this.head)
set this.target = null
set this.host = null
set this.head = null
loop
exitwhen i > ihook
if ahook[i] == this then
set ahook[i] = ahook[ihook]
set ahook[ihook] = 0
set ihook = ihook - 1
set i = ihook // выход из цикла
endif
set i = i + 1
endloop
call this.destroy()
endmethod
endstruct
private function Engine takes nothing returns nothing
local integer i = 0
local real x
local real y
local real x1
local real y1
local real xc
local real yc
local integer ii = 0
local real f
local mhook h
local group g = CreateGroup()
local unit t
loop
exitwhen i > ihook
if ahook[i] != 0 then
set h = ahook[i]
//--run--//
set x = GetUnitX(h.head)
set y = GetUnitY(h.head)
if h.move == 1 then
set h.headdis = h.headdis + h.speed*0.025
set x1 = GetPolarX(x,h.face,h.speed*0.025)
set y1 = GetPolarY(y,h.face,h.speed*0.025)
call SetUnitX(h.head,x1)
call SetUnitY(h.head,y1)
//Enum=====================
call GroupEnumUnitsInRange(g,x1,y1,h.scale,null)
loop
set t = FirstOfGroup(g)
exitwhen t == null
call GroupRemoveUnit(g,t)
if GetAliveUnit(t)&&IsPlayerEnemy(Player(h.i),GetOwningPlayer(t))&&IsUnitType(t,UNIT_TYPE_GROUND) then
set h.target = t
call SetUnitPathing(t,false)
set h.move = 0
call GroupClear(g)
endif
endloop
//Chain====================
loop
exitwhen ii > h.chaini
if ii > 0 then
set xc = GetUnitX(h.chain[ihook].u[ii])
set yc = GetUnitY(h.chain[ihook].u[ii])
set f = GetAngleXY(xc,yc,GetUnitX(h.chain[ihook].u[ii-1]),GetUnitY(h.chain[ihook].u[ii-1]))
call SetUnitX(h.chain[ihook].u[ii],GetPolarX(xc,f,h.speed*0.025))
call SetUnitY(h.chain[ihook].u[ii],GetPolarY(yc,f,h.speed*0.025))
call SetUnitFacing(h.chain[ihook].u[ii],f)
endif
set ii = ii + 1
endloop
set xc = GetUnitX(h.chain[ihook].u[h.chaini])
set yc = GetUnitY(h.chain[ihook].u[h.chaini])
set f = GetAngleXY(GetUnitX(h.host),GetUnitY(h.host),GetUnitX(h.chain[ihook].u[h.chaini]),GetUnitY(h.chain[ihook].u[h.chaini]))
set x = GetPolarX(GetUnitX(h.host),f,h.scale/2)
set y = GetPolarY(GetUnitY(h.host),f,h.scale/2)
if GetDisXY(xc,yc,x,y) >= h.scale/2 then
set h.chain[ihook].u[h.chaini+1] = CreateUnit(Player(h.i),'h007',x,y,f)
call UnitAddAbility(h.chain[ihook].u[h.chaini+1],'Amrf')
call UnitAddAbility(h.chain[ihook].u[h.chaini+1],'Amrf')
call SetUnitFlyHeight(h.chain[ihook].u[h.chaini+1],50,0)
set h.chaini = h.chaini + 1
endif
if h.headdis > h.headdismax then
set h.move = 0
endif
else
set x = GetUnitX(h.chain[ihook].u[h.chaini])
set y = GetUnitY(h.chain[ihook].u[h.chaini])
set h.chain[ihook].u[h.chaini+1]= h.host
set ii = 0
loop
exitwhen ii > h.chaini
set xc = GetUnitX(h.chain[ihook].u[ii])
set yc = GetUnitY(h.chain[ihook].u[ii])
//set f = GetAngleXY(GetUnitX(h.head),GetUnitY(h.head),GetUnitX(h.host),GetUnitY(h.host))
set f = GetAngleXY(xc,yc,GetUnitX(h.chain[ihook].u[ii+1]),GetUnitY(h.chain[ihook].u[ii+1]))
call SetUnitX(h.chain[ihook].u[ii],GetPolarX(xc,f,h.speed*0.025))
call SetUnitY(h.chain[ihook].u[ii],GetPolarY(yc,f,h.speed*0.025))
call SetUnitFacing(h.chain[ihook].u[ii],f-180)
if ii == 0 then
call SetUnitPosition(h.target,xc,yc)
endif
set ii = ii + 1
endloop
//Destroy==================
if GetDisXY(GetUnitX(h.chain[ihook].u[h.chaini]),GetUnitY(h.chain[ihook].u[h.chaini]),GetUnitX(h.host),GetUnitY(h.host)) < 100 then
call SetUnitPathing(h.target,true)
call RemoveUnit(h.chain[ihook].u[h.chaini])
set h.chaini = h.chaini - 1
if h.chaini == 0 then
call h.Destroy()
endif
endif
endif
else
set ahook[i] = ahook[ihook]
set ahook[ihook] = 0
set ihook = ihook - 1
set i = i - 1
endif
set i = i + 1
endloop
call DestroyGroup(g)
set g = null
set t = null
endfunction
function Trig_HookC_Bool takes nothing returns boolean
if GetSpellAbilityId() == 'A01D' then //Способность Мясной хук
return true
else
return false
endif
endfunction
function Trig_HookC_Actions takes nothing returns nothing
local mhook h
set h = mhook.Create(GetSpellAbilityUnit(),GetSpellTargetX(),GetSpellTargetY(),110)
call h.Start()
endfunction
function Init_Hook takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( t, function Trig_HookC_Actions )
call TriggerAddCondition(t,function Trig_HookC_Bool)
call TimerStart(CreateTimer(),0.025,true,function Engine)
endfunction
endlibrary
))
'h007' - юнит-дамми со способностью Aloc и имеет возможность двигаться (для процедуры SetUnitX(Y), т.к. быстрее альтернатив)
Суть проблемы:
При использовании способности Мясной хук (A01D) герой кидает хук который притягивает попавшего юнита. Всё замечательно, кроме одного НО.
Если во время полета одного Хука кинуть еще один Хук то будет плохо. То есть, MUI не пахнет.
При использовании способности Мясной хук (A01D) герой кидает хук который притягивает попавшего юнита. Всё замечательно, кроме одного НО.
Если во время полета одного Хука кинуть еще один Хук то будет плохо. То есть, MUI не пахнет.
Подозреваю что дело в chain[array] т.к. система не может во время игры увеличить объем массивов. Помогите сделать MUI.
Принятый ответ
nvc123:
nvc123, и всё же твой хук не тот что мне нужен.
Я решил проблему, спасибо что дал идею обрабатывать движение внутри структуры, а не в стеке.
Хорошо группы реализуешь как альтернативу unit[array]. Я тоже самое получил.Bornikkeny, сделал специально чтобы доказать тебе что ты несёшь бред
даже 2 скрина приложилдумаю закинуть библиотеки сможешь сам (в папку *твой jngp*\AdicHelper\lib)
nvc123, и всё же твой хук не тот что мне нужен.
Я решил проблему, спасибо что дал идею обрабатывать движение внутри структуры, а не в стеке.
кот
library Hook initializer Init_Hook uses LibMath
globals
mhook ahook[100]
integer ihook = -1
endglobals
struct mhook
unit host = null
unit target = null
real face = 0
real speed = 0
real dis = 0
real dismax = 0
integer chaini = 0
unit chain[50]
real scale = 0
integer move = 1
integer i = 0
static method Create takes unit host, real tx, real ty, real scale returns mhook
local mhook h = mhook.create()
local integer i = GetPlayerId(GetOwningPlayer(host))
local real x = GetUnitX(host)
local real y = GetUnitY(host)
local real f = GetAngleXY(x,y,tx,ty)
set h.host = host
set h.face = f
set h.speed = 600
set h.dismax = 1400
set h.scale = scale
set h.chain[0] = CreateUnit(Player(i),'h007',GetPolarX(GetUnitX(host),f,h.scale/2),GetPolarY(GetUnitY(host),f,h.scale/2),f)
set h.i = i
call UnitAddAbility(h.chain[0],'Amrf')
call UnitAddAbility(h.chain[0],'Amrf')
call SetUnitFlyHeight(h.chain[0],50,0)
call SetUnitPathing(h.chain[0],false)
return h
endmethod
method Start takes nothing returns boolean
if ihook < 1000 then
set ihook = ihook + 1
set ahook[ihook] = this
return true
else
return false
endif
endmethod
method Destroy takes nothing returns nothing
local integer i = 0
loop
exitwhen i > ihook
if ahook[i] == this then
set ahook[i] = ahook[ihook]
set ahook[ihook] = 0
set ihook = ihook - 1
set i = ihook // выход из цикла
endif
set i = i + 1
endloop
set this.target = null
set this.host = null
call this.destroy()
endmethod
method Move takes nothing returns nothing
local integer i1 = 0
local integer l = 0
local real x
local real y
local real xh
local real yh
local real f
if move == 1
set dis = dis + speed*0.025
loop
exitwhen i1 > .chaini
set x = GetUnitX(.chain[i1])
set y = GetUnitY(.chain[i1])
if i1 > 0 then
set f = GetAngleXY(x,y,GetUnitX(.chain[i1-1]),GetUnitY(.chain[i1-1]))
call SetUnitX(.chain[i1],GetPolarX(x,f,.speed*0.025))
call SetUnitY(.chain[i1],GetPolarY(y,f,.speed*0.025))
else
set f = face
call SetUnitX(chain[i1],GetPolarX(x,f,.speed*0.025))
call SetUnitY(chain[i1],GetPolarY(y,f,.speed*0.025))
endif
call SetUnitFacing(chain[i1],f)
set i1 = i1 + 1
endloop
set x = GetUnitX(chain[chaini])
set y = GetUnitY(chain[chaini])
set f = GetAngleXY(GetUnitX(.host),GetUnitY(.host),x,y)
set xh = GetPolarX(GetUnitX(.host),f,.scale/2)
set yh = GetPolarY(GetUnitY(.host),f,.scale/2)
//Create==================
if GetDisXY(xh,yh,x,y) >= .scale/2 then
set chaini = chaini + 1
set chain[chaini] = CreateUnit(Player(.i),'h007',xh,yh,f)
call UnitAddAbility(.chain[.chaini],'Amrf')
call UnitAddAbility(.chain[.chaini],'Amrf')
call SetUnitFlyHeight(.chain[.chaini],50,0)
endif
if dis > dismax then
set move = 0
endif
else
//REVERSE=============
set xh = GetUnitX(host)
set yh = GetUnitY(host)
set chain[chaini+1] = host
loop
exitwhen l > chaini
set x = GetUnitX(chain[l])
set y = GetUnitY(chain[l])
//if chain[chaini] == null then
// set f = GetAngleXY()
//endif
set f = GetAngleXY(x,y,GetUnitX(chain[l+1]),GetUnitY(chain[l+1]))
call SetUnitX(chain[l],GetPolarX(x,f,speed*0.025))
call SetUnitY(chain[l],GetPolarY(y,f,speed*0.025))
call SetUnitFacing(chain[l],f-180)
set l = l + 1
endloop
//Destroy==================
set x = GetUnitX(chain[chaini])
set y = GetUnitY(chain[chaini])
set xh = GetUnitX(host)
set yh = GetUnitY(host)
if GetDisXY(GetUnitX(chain[chaini]),GetUnitY(chain[chaini]),GetUnitX(host),GetUnitY(host)) < 100 then
call RemoveUnit(chain[chaini])
set chain[chaini] = null
set chaini = chaini - 1
if chaini == -1 then
call .Destroy()
endif
endif
endif
endmethod
endstruct
private function Engine takes nothing returns nothing
local integer i = 0
local mhook h
local group g
local unit t
loop
exitwhen i > ihook
if ahook[i] != 0 then
set h = ahook[i]
//--run--//
call h.Move()
else
set ahook[i] = ahook[ihook]
set ahook[ihook] = 0
set ihook = ihook - 1
set i = i - 1
endif
set i = i + 1
endloop
//call DestroyGroup(g)
set g = null
set t = null
endfunction
function Trig_HookC_Bool takes nothing returns boolean
if GetSpellAbilityId() == 'A01D' then //Способность Мясной хук
return true
else
return false
endif
endfunction
function Trig_HookC_Actions takes nothing returns nothing
local mhook h
set h = mhook.Create(GetSpellAbilityUnit(),GetSpellTargetX(),GetSpellTargetY(),110)
call h.Start()
endfunction
function Init_Hook takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( t, function Trig_HookC_Actions )
call TriggerAddCondition(t,function Trig_HookC_Bool)
call TimerStart(CreateTimer(),0.025,true,function Engine)
endfunction
endlibrary
`
ОЖИДАНИЕ РЕКЛАМЫ...
Чтобы оставить комментарий, пожалуйста, войдите на сайт.
Ред. Bornikkeny
Ред. nvc123
ты забиваешь весь массив и пытаешься пихать сверх него
какая максимальная длина хука в юнитах?
вообще код бред какой то
структура xar нафиг не нужна
храним юнитов в хуке и всё
если делать хук как в доте то всё что тебе надо это
+ статичные методы new и update
Ред. nvc123
не неси бред
то что код оптимален не значит что он не муи
даже скорее наоборот
Bornikkeny, у тебя не хук а бред какойто
и угол если звено зависит от поворота
даже 2 скрина приложил
nvc123, и всё же твой хук не тот что мне нужен.
Я решил проблему, спасибо что дал идею обрабатывать движение внутри структуры, а не в стеке.