Пробую работать со снарядами и наткнулся на ошибку снаряд не летит в сторону юнита который прицеплен к курсору.(Помечен переменной Target)
function Trig_ShootTest_Actions2 takes nothing returns nothing
local timer TimerAct = GetExpiredTimer()
local integer id = GetHandleId(TimerAct)
local unit marine = LoadUnitHandle(Hash, id, StringHash("marine"))
local unit Target = LoadUnitHandle(Hash, id, StringHash("Target"))
local unit Dummy = LoadUnitHandle(Hash, id, StringHash("Dummy"))

local real process = LoadReal(Hash, id, StringHash("process")) + LoadReal(Hash, id, StringHash("Speed"))
local group gACT
local unit u = null

 if process > LoadReal(Hash, id, StringHash("maxDist")) then
 call DestroyGroup(LoadGroupHandle(Hash, id, StringHash("group")))
 call KillUnit(Dummy)
 call FlushChildHashtable(Hash, id)
 call PauseTimer(TimerAct)
 call DestroyTimer(TimerAct)
 
else

 call SaveReal(Hash, id, StringHash("process"), process)
 call SetUnitX(Dummy, GetUnitX(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Cos(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 call SetUnitY(Dummy, GetUnitY(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Sin(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 
 set gACT =CreateGroup()
 call GroupEnumUnitsInRange(gACT, GetUnitX(Dummy),GetUnitY(Dummy), LoadReal(Hash, id, StringHash("Aoe")), null )
 
 loop
 
  set u = FirstOfGroup(gACT)
  exitwhen u == null
  
  if GetWidgetLife(u) > 0.405 and not IsUnitInGroup(u, LoadGroupHandle(Hash, id, StringHash("group"))) then
  
      if IsUnitEnemy(u, GetOwningPlayer(marine)) then
         call UnitDamageTarget(marine, u, LoadReal(Hash, id, StringHash("Damege")), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
         call DestroyEffect(AddSpecialEffectTarget(LoadStr(Hash, id, StringHash("BloodEfect")), u, "chest"))
      else
      
      endif
  
  endif
  
  call GroupRemoveUnit(gACT, u)
  
  endloop
  
   call DestroyGroup(gACT)
   
  endif 

set marine = null
set Dummy = null
set TimerAct = null
set gACT = null

endfunction


function Trig_ShootTest_Actions takes nothing returns nothing
local unit marine = gg_unit_H000_0003
local unit Target = gg_unit_n000_0005
local real xMarine = GetUnitX(marine)
local real yMarine = GetUnitY(marine)
local real xTarget = GetUnitX(Target)
local real yTarget = GetUnitY(Target)
local real angle = bj_RADTODEG * Atan2(yTarget - yMarine, xTarget - xMarine)
local unit Dummy = CreateUnit(GetOwningPlayer(marine), 'n001', xMarine, yMarine, angle)

local real maxDis = 1200
local real Damege = 50
local real Aoe = 90
local real Speed = 700

local string BloodEfect = "WeaponsandEffect/BloodDamage.mdx"

local timer TimerAct = CreateTimer()
local integer id = GetHandleId(TimerAct)
if xMarine == xTarget and yMarine == yMarine then
        set angle = GetUnitFacing(marine)
    endif

call SetUnitX(Dummy, xMarine + 50 * Cos(angle * bj_DEGTORAD))
call SetUnitY(Dummy, yMarine + 50 * Sin(angle * bj_DEGTORAD))

call SaveUnitHandle(Hash, id, StringHash("marine"), marine)
call SaveUnitHandle(Hash, id, StringHash("Target"), Target)
call SaveUnitHandle(Hash, id, StringHash("Dummy"), Dummy)

call SaveReal(Hash, id, StringHash("Damege"), Damege)
call SaveReal(Hash, id, StringHash("maxDis"), maxDis)
call SaveReal(Hash, id, StringHash("Aoe"), Aoe)
call SaveReal(Hash, id, StringHash("angle"), angle)
call SaveReal(Hash, id, StringHash("Speed"), Speed * 0.03)
call SaveStr(Hash, id, StringHash("BloodEfect"), BloodEfect)
call SaveReal(Hash, id, StringHash("process"), 0)
call SaveGroupHandle(Hash, id, StringHash("group"), CreateGroup())


call TimerStart(TimerAct, 0.03, true, function Trig_ShootTest_Actions2)

set marine = null
set Target = null
set Dummy = null
set TimerAct = null


endfunction

function Trig_ShootTest_Conditions takes nothing returns boolean  
    return BlzGetTriggerPlayerMouseButton() == MOUSE_BUTTON_TYPE_RIGHT
    return UnitHasItemOfTypeBJ(udg_UnitBody[1], 'I000') == true
endfunction


//===========================================================================
function InitTrig_ShootTest takes nothing returns nothing
    set gg_trg_ShootTest = CreateTrigger(  )
    call TriggerRegisterPlayerMouseEventBJ( gg_trg_ShootTest, Player(0), bj_MOUSEEVENTTYPE_DOWN )
    call TriggerAddCondition( gg_trg_ShootTest, Condition( function Trig_ShootTest_Conditions ) )
    call TriggerAddAction( gg_trg_ShootTest, function Trig_ShootTest_Actions )
    
endfunction

jasonrus96, просто пробуй улучшать свой код, начиная банально с табуляции и названий функций, заканчивая структурами и сложными системами, на рефе и вовсе можно на луа перейти спокойно

Тебе просто практика нужна
`
ОЖИДАНИЕ РЕКЛАМЫ...

Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
28
Когда скилом код юзаешь все работает.
хочешь сказать что условие или событие не срабатывает? или даммик всё-таки создаётся но не летит?
9
rsfghd, Дамик создается нормально в нужном направлении но не летит

Либо я тут что то напортачил
local timer TimerAct = GetExpiredTimer()
local integer id = GetHandleId(TimerAct)
local unit marine = LoadUnitHandle(Hash, id, StringHash("marine"))


local unit Dummy = LoadUnitHandle(Hash, id, StringHash("Dummy")) 
local real process = LoadReal(Hash, id, StringHash("process")) + LoadReal(Hash, id, StringHash("Speed"))
local group gACT
local unit u = null

 if process > LoadReal(Hash, id, StringHash("maxDist"))  then
 call DestroyGroup(LoadGroupHandle(Hash, id, StringHash("group")))
 call KillUnit(Dummy)
 call FlushChildHashtable(Hash, id)
 call PauseTimer(TimerAct)
 call DestroyTimer(TimerAct)
 
else

 call SaveReal(Hash, id, StringHash("process"), process)
 call SetUnitX(Dummy, GetUnitX(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Cos(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 call SetUnitY(Dummy, GetUnitY(Dummy) + LoadReal(Hash, id, StringHash("Speed")) * Sin(LoadReal(Hash, id, StringHash("angle")) * bj_DEGTORAD))
 
 set gACT =CreateGroup()
 call GroupEnumUnitsInRange(gACT, GetUnitX(Dummy),GetUnitY(Dummy), LoadReal(Hash, id, StringHash("Aoe")), null )
 
 loop
 
  set u = FirstOfGroup(gACT)
  exitwhen u == null
  
  if GetWidgetLife(u) > 0.405 and not IsUnitInGroup(u, LoadGroupHandle(Hash, id, StringHash("group"))) then
  
      if IsUnitEnemy(u, GetOwningPlayer(marine)) then
         call UnitDamageTarget(marine, u, LoadReal(Hash, id, StringHash("Damege")), false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, null)
         call DestroyEffect(AddSpecialEffectTarget(LoadStr(Hash, id, StringHash("BloodEfect")), u, "chest"))
      else
      
      endif
  
  endif
  
  call GroupRemoveUnit(gACT, u)
  
  endloop
  
   call DestroyGroup(gACT)
   
  endif 

set marine = null
set Dummy = null
set TimerAct = null
set gACT = null

endfunction
28
Дамик создается нормально в нужном направлении но не летит
попробуй тогда продебажить угол и скорость
9
rsfghd, Не знаю как 😄

rsfghd, Нашел нужно было в переменную maxDist исправить на maxDis 😅
28
Нашел нужно было в переменную maxDist исправить на maxDis 😅
пользовался бы структурами, с такими проблемами не мучился, потому что компилятор помог бы)
28
jasonrus96, просто указанные тобой переменные помещенные в структуре, которая на самом деле массивная целочисленная, сейчас попробую набросать
28
jasonrus96, у меня рефа нет так что как-то так
код
library ShootSystemLib
globals
    constant hashtable H = InitHashtable( )
    constant group TempGroup = CreateGroup( )
    constant location LFZ = Location( 0.00, 0.00 )
endglobals

native UnitAlive takes unit id returns boolean

function GetLocZ takes real x, real y returns real
    call MoveLocation( LFZ, x, y )
    return GetLocationZ( LFZ )
endfunction

struct vector
    real x
    real y
    real z
    
    method normalize takes nothing returns nothing
        local real l = SquareRoot( x * x + y * y + z * z )
        
        if l == 0.00 then
            set l = 1.00
        endif
        
        set x = x * ( 1.00 / l )
        set y = y * ( 1.00 / l )
        set z = z * ( 1.00 / l )
    endmethod
    
    static method create takes real x, real y, real z returns thistype
        local thistype this = thistype.allocate( )
        
        set this.x = x
        set this.y = y
        set this.z = z
        
        call this.normalize( )
        
        return this
    endmethod
endstruct

struct bullet
    unit caster
    unit dummy
    player p
    
    real x
    real y
    real z
    real s // speed
    real d // distance
    real r // radius
    
    vector v
endstruct

function Move takes nothing returns nothing
    local bullet A = LoadInteger( H, GetHandleId( GetExpiredTimer( ) ), 0 )
    local unit u
    
    set A.x = A.x + A.s * A.v.x * Cos( A.v.z )
    set A.y = A.y + A.s * A.v.y * Cos( A.v.z )
    set A.z = A.z + A.s * A.v.z
    
    set A.d = A.d - A.s
    
    call SetUnitX( A.dummy, A.x )
    call SetUnitY( A.dummy, A.y )
    call SetUnitFlyHeight( A.dummy, A.z - GetLocZ( A.x, A.y ), 0.00 )
    
    call GroupEnumUnitsInRange( TempGroup, A.x, A.y, A.r, null )
    
    loop
        set u = FirstOfGroup( TempGroup )
        exitwhen u == null
        call GroupRemoveUnit( TempGroup, u )
        
        if UnitAlive( u ) and IsUnitEnemy( u, A.p ) and RAbsBJ( GetUnitFlyHeight( u ) - GetUnitFlyHeight( A.dummy ) ) <= 100.00 then
            call GroupClear( TempGroup )
            call UnitDamageTarget( A.caster, u, 100.00, false, false, null, null, null )
            call DestroyEffect( AddSpecialEffectTarget( "Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl", u, "chest" ) )
        endif
    endloop
    
    if A.d <= 0.00 or A.z - GetLocZ( A.x, A.y ) <= 20.00 then
        call PauseTimer( GetExpiredTimer( ) )
        call FlushChildHashtable( H, GetHandleId( GetExpiredTimer( ) ) )
        call DestroyTimer( GetExpiredTimer( ) )
        
        call KillUnit( A.dummy )
        
        set A.dummy = null
        set A.caster = null
        call A.v.destroy( )
        call A.destroy( )
    endif
endfunction

function Trig_Untitled_Trigger_001_Actions takes nothing returns nothing
    local timer t = CreateTimer( )
    local bullet A = bullet.create( )
    local real x = GetSpellTargetX( )
    local real y = GetSpellTargetY( )
    local real z = GetLocZ( x, y ) + 50.00
    
    set A.caster = GetTriggerUnit( )
    set A.p = GetOwningPlayer( A.caster )
    
    // for offset
    set A.x = GetUnitX( A.caster )
    set A.y = GetUnitY( A.caster )
    set A.z = GetUnitFlyHeight( A.caster ) + GetLocZ( A.x, A.y ) + 50.00
    
    set A.v = vector.create( x - A.x, y - A.y, z - A.z )
    
    set A.x = A.x + 50.00 * A.v.x * Cos( A.v.z )
    set A.y = A.y + 50.00 * A.v.y * Cos( A.v.z )
    set A.z = GetUnitFlyHeight( A.caster ) + GetLocZ( A.x, A.y ) + 50.00
    
    // for move
    set A.v.x = x - A.x
    set A.v.y = y - A.y
    set A.v.z = z - A.z
    
    call A.v.normalize( )
    
    set A.d = 1200.00
    set A.s = 1500.00 * 0.03125
    set A.r = 40.00
    
    set A.dummy = CreateUnit( A.p, 'u000', A.x, A.y, Atan2( A.v.y, A.v.x ) * bj_RADTODEG )
    call SetUnitPathing( A.dummy, false )
    call UnitAddAbility( A.dummy, 'Arav' )
    call SetUnitX( A.dummy, A.x )
    call SetUnitY( A.dummy, A.y )
    call SetUnitFlyHeight( A.dummy, A.z - GetLocZ( A.x, A.y ), 0.00 )
    
    call SaveInteger( H, GetHandleId( t ), 0, A )
    call TimerStart( t, 0.03125, true, function Move )
    
    set t = null
endfunction

//===========================================================================
function Untitled_Trigger_001_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000'
endfunction

function InitTrig_Untitled_Trigger_001 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_001 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_001, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_001, Condition( function Untitled_Trigger_001_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_001, function Trig_Untitled_Trigger_001_Actions )
endfunction
endlibrary

а, ну и советую задуматься над тем, чтобы добавить коллизию для юнитов, это не сложно
Загруженные файлы
9
rsfghd, мне бы еще разобраться как сделать мультишот на базе моего кода не могу Loop впихнуть почему-то на локалки ругается.
28
jasonrus96, локалки могут быть объявлены только вначале функции
9
rsfghd, я знаю вот по этому не могу Loop сделать и заствить кучу снарядов веером лететь.
Показан только небольшой набор комментариев вокруг указанного. Перейти к актуальным.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.