XGM Forum
Сайт - Статьи - Проекты - Ресурсы - Блоги

Форуме в режиме ТОЛЬКО ЧТЕНИЕ. Вы можете задать вопросы в Q/A на сайте, либо создать свой проект или ресурс.
Вернуться   XGM Forum > Warcraft> Академия: форум для вопросов> Jass
Ник
Пароль
Войти через VK в один клик
Сайт использует только имя.

Закрытая тема
 
Blizzru

offline
Опыт: 4,117
Активность:
Первый мой спелл - код...
Гдето краем уха я слышал, что от BJ функций лучше избавляться...
Тут есть строка содержащая BJ что мне с ней делать?
function Trig_Magic_Ball_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A01E' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Magic_Ball_Actions takes nothing returns nothing
    local unit Unit_TargetMagicBall
    local unit Unit_CasterMagicBall
    set Unit_CasterMagicBall = GetSpellAbilityUnit()
    set Unit_TargetMagicBall = GetSpellTargetUnit()
    call PolledWait( ( DistanceBetweenPoints(GetUnitLoc(Unit_CasterMagicBall), GetUnitLoc(Unit_TargetMagicBall)) / 650.00 - 0.30 ) )
    call CreateNUnitsAtLoc( 1, 'h008', GetOwningPlayer(Unit_CasterMagicBall), GetUnitLoc(Unit_TargetMagicBall), 270 )
    call SetUnitAbilityLevelSwapped( 'A01F', GetLastCreatedUnit(), GetUnitAbilityLevelSwapped('A01E', Unit_CasterMagicBall) )
    call IssueImmediateOrder( GetLastCreatedUnit(), "thunderclap" )
endfunction

//===========================================================================
function InitTrig_Magic_Ball takes nothing returns nothing
    set gg_trg_Magic_Ball = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Magic_Ball, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Magic_Ball, Condition( function Trig_Magic_Ball_Conditions ) )
    call TriggerAddAction( gg_trg_Magic_Ball, function Trig_Magic_Ball_Actions )
endfunction
Вот эта строка...
call TriggerRegisterAnyUnitEventBJ( gg_trg_Magic_Ball, EVENT_PLAYER_UNIT_SPELL_EFFECT )
Старый 23.02.2012, 16:31
Hanabishi
COOL STATUS
offline
Опыт: отключен
Blizzru, жутко утечный неоптимальный код.
Вот так лучше, но всё равно через вейт не одобряю.
function Trig_Magic_Ball_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A01E'
endfunction

function Trig_Magic_Ball_Actions takes nothing returns nothing
    local unit Unit_TargetMagicBall = GetSpellTargetUnit()
    local unit Unit_CasterMagicBall = GetSpellAbilityUnit()
    local integer dx = GetUnitX(Unit_TargetMagicBall)-GetUnitX(Unit_CasterMagicBall)
    local integer dy = GetUnitY(Unit_TargetMagicBall)-GetUnitY(Unit_CasterMagicBall)
    local unit u
    call TriggerSleepAction(SquareRoot(dx*dx+dy*dy)/650.00-0.30)
    set u = CreateUnit(GetOwningPlayer(Unit_CasterMagicBall),'h008',GetUnitX(Unit_TargetMagicBall),GetUnitY(Unit​_TargetMagicBall),270)
    call SetUnitAbilityLevel(u,'A01F',GetUnitAbilityLevel(Unit_CasterMagicBall,'A01E'))
    call IssueImmediateOrder(u,"thunderclap")
    set Unit_TargetMagicBall = null
    set Unit_CasterMagicBall = null
    set u = null
endfunction

//===========================================================================
function InitTrig_Magic_Ball takes nothing returns nothing
    local integer index = 0
    set gg_trg_Magic_Ball = CreateTrigger()
    loop
    exitwhen(index>bj_MAX_PLAYER_SLOTS)
        call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        set index = index+1
    endloop
    call TriggerAddCondition(gg_trg_Magic_Ball,Condition(function Trig_Magic_Ball_Conditions))
    call TriggerAddAction(gg_trg_Magic_Ball,function Trig_Magic_Ball_Actions )
endfunction
Старый 23.02.2012, 17:07
Ty3uK

offline
Опыт: 2,469
Активность:
Объявление локальных переменных должно быть в самом начале функций. То есть строчку с local поставь перед строчкой с set (первую и вторую строку события поменять)

Ty3uK добавил:
Hanabishi, а ордер через ид почему бы не отдать?
Старый 23.02.2012, 17:08
Hanabishi
COOL STATUS
offline
Опыт: отключен
Ty3uK, разницы нет, а ид искать лень =Р
Старый 23.02.2012, 17:10
Ty3uK

offline
Опыт: 2,469
Активность:
Разве нет? Просто всегда считал, что через ид быстрее работает :)
Старый 23.02.2012, 17:13
alpha

offline
Опыт: 7,387
Активность:
вот тебе более-менее быстрый алгоритм
вэйт выпели лучше
» code
  function Trig_Magic_Ball_Actions takes nothing returns nothing

    local unit Unit_TargetMagicBall = GetSpellTargetUnit()
    local unit Unit_CasterMagicBall = GetSpellAbilityUnit()
    local unit u
    
    local integer dx = GetUnitX(Unit_TargetMagicBall) - GetUnitX(Unit_CasterMagicBall)
    local integer dy = GetUnitY(Unit_TargetMagicBall) - GetUnitY(Unit_CasterMagicBall)
    
    call TriggerSleepAction(SquareRoot(dx*dx+dy*dy)/650.-.3)
    
    set u = CreateUnit(GetOwningPlayer(Unit_CasterMagicBall),'h008',GetUnitX(Unit_TargetMagicBall),GetUnitY(Unit​_TargetMagicBall),270.)
    call SetUnitAbilityLevel(u, 'A01F', GetUnitAbilityLevel(Unit_CasterMagicBall, 'A01E'))
    call IssueImmediateOrder(u, "thunderclap")
    
    set Unit_TargetMagicBall = null
    set Unit_CasterMagicBall = null
    set u = null

  endfunction

function Trig_Magic_Ball_Conditions takes nothing returns boolean

    if (GetSpellAbilityId() == 'A01E') then
      call Trig_Magic_Ball_Actions()
    endif
    
    return false

endfunction

//===========================================================================
function InitTrig_Magic_Ball takes nothing returns nothing
    set gg_trg_Magic_Ball = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(1), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(2), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(3), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(4), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(5), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(6), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(7), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(8), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(9), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(10),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(11),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(12),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(13),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(14),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(15),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(16),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerAddCondition(gg_trg_Magic_Ball,Condition(function Trig_Magic_Ball_Conditions))
endfunction
Ty3uK:
Разве нет? Просто всегда считал, что через ид быстрее работает :)
потеря в читабельности происходит)
Объявление локальных переменных должно быть в самом начале функций. То есть строчку с local поставь перед строчкой с set (первую и вторую строку события поменять)
имея нормальный JNGP это не важно
Использовать еще лучше вместо Player натив-функции переменную
типа такой:
» code
globals
  player array W
endglobals

//init
    set W[0] = Player(0)
    set W[1] = Player(1)
    set W[2] = Player(2)
    set W[3] = Player(3)
    set W[4] = Player(4)
    set W[5] = Player(5)
    set W[6] = Player(6)
    set W[7] = Player(7)
    set W[8] = Player(8)
    set W[9] = Player(9)
    set W[10] = Player(10)
    set W[11] = Player(11)
    set W[12] = Player(12)
    set W[13] = Player(13)
    set W[14] = Player(14)
    set W[15] = Player(15)
Старый 23.02.2012, 17:50
Blizzru

offline
Опыт: 4,117
Активность:
Помоему пару строчек лучше чем 100500
Старый 23.02.2012, 18:12
Ty3uK

offline
Опыт: 2,469
Активность:
Одним jngp дело не заканчивается. А автор, видимо, юзает обычный ве. Про него тоже забывать не стоит
Старый 23.02.2012, 18:23
alpha

offline
Опыт: 7,387
Активность:
чем? байтами кода?
читобельностью разве что
alpha добавил:
Ty3uK:
А автор, видимо, юзает обычный ве. Про него тоже забывать не стоит
Я уточнил просто, для общего развития)
Старый 23.02.2012, 18:24
Blizzru

offline
Опыт: 4,117
Активность:
Hanabishi, это что за Bj? Без неё никак?
exitwhen(index>bj_MAX_PLAYER_SLOTS)
alpha,
с твоими алгоритмами...
call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(0), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(1), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(2), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(3), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(4), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(5), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(6), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(7), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(8), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(9), EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(10),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(11),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(12),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(13),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(14),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(15),EVENT_PLAYER_UNIT_SPELL_EFFECT, null)
    call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball, Player(16),EVENT_PLAYER_UNIT_SPELL_EFFECT, null
Помоему не быстрее... это ведь обычные глобалки...

Отредактировано Blizzru, 23.02.2012 в 18:34.
Старый 23.02.2012, 18:25
alpha

offline
Опыт: 7,387
Активность:
посмотри тело BJ-функции затем строй выводы
если тебя пугает множество букв, то твори дальше на гуи
alpha добавил:
Blizzru:
Hanabishi, это что за Bj? Без неё никак?
exitwhen(index>bj_MAX_PLAYER_SLOTS)
JNGP в руки и разузнай что за покемон
Старый 23.02.2012, 18:27
Doc

offline
Опыт: 63,163
Активность:
alpha, если уж делать массив, то имхо заносить туда только играющих/нужных, а потом уже на них все регать.
Старый 23.02.2012, 18:31
alpha

offline
Опыт: 7,387
Активность:
Doc:
alpha, если уж делать массив, то имхо заносить туда только играющих/нужных
Понятное дело, откуда мне знать кто там у него является нужным, а кто ненужным?
alpha добавил:
Blizzru, пользуйся похожей конструкцией:
((код jass
function UnitEvent takes trigger a, playerunitevent b returns nothing
call TriggerRegisterPlayerUnitEvent(a,W[0],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[1],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[2],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[3],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[4],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[5],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[6],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[7],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[8],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[9],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[10],b,null)
call TriggerRegisterPlayerUnitEvent(a,W[11],b,null)
endfunction
))
Старый 23.02.2012, 18:36
Blizzru

offline
Опыт: 4,117
Активность:
При загрузке (почти в самом конце) выкидывает Fatal Error.

function Trig_Magic_Ball_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A01E'
endfunction

function Trig_Magic_Ball_Actions takes nothing returns nothing
    local unit Unit_TargetMagicBall = GetSpellTargetUnit()
    local unit Unit_CasterMagicBall = GetSpellAbilityUnit()
    local real dx = GetUnitX(Unit_TargetMagicBall)-GetUnitX(Unit_CasterMagicBall)
    local real dy = GetUnitY(Unit_TargetMagicBall)-GetUnitY(Unit_CasterMagicBall)
    local unit UnitLast01
    call TriggerSleepAction(SquareRoot(dx*dx+dy*dy)/650.00-0.30)
    set UnitLast01= CreateUnit(GetOwningPlayer(Unit_CasterMagicBall),'h008',GetUnitX(Unit_TargetMagicBall),GetUnitY(Unit​_TargetMagicBall),270)
    call SetUnitAbilityLevel(UnitLast01,'A01F',GetUnitAbilityLevel(Unit_CasterMagicBall,'A01E'))
    call IssueImmediateOrder(UnitLast01,"thunderclap")
    set Unit_TargetMagicBall = null
    set Unit_CasterMagicBall = null
    set UnitLast01 = null
endfunction

//===========================================================================
function InitTrig_Magic_Ball takes nothing returns nothing
    local integer index = 0
    set gg_trg_Magic_Ball = CreateTrigger()
    loop
    exitwhen(index>bj_MAX_PLAYER_SLOTS)
        call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        set index = index+1
    endloop
    call TriggerAddCondition(gg_trg_Magic_Ball,Condition(function Trig_Magic_Ball_Conditions))
    call TriggerAddAction(gg_trg_Magic_Ball,function Trig_Magic_Ball_Actions )
endfunction
Старый 23.02.2012, 18:38
alpha

offline
Опыт: 7,387
Активность:
где результаты отладки?
alpha добавил:
[Debug log]
Над системами трудились не для того чтобы они пылились
Старый 23.02.2012, 18:43
Blizzru

offline
Опыт: 4,117
Активность:
BoT
Миниатюры
Кликните на картинку для увеличения
Название:  qOp.jpg
Просмотров: 18
Размер:  28.7 Кбайт  
Старый 23.02.2012, 18:47
alpha

offline
Опыт: 7,387
Активность:
понятие "отладка" кури
Старый 23.02.2012, 18:48
Blizzru

offline
Опыт: 4,117
Активность:
alpha, сорь... непонял. блондин оО
Старый 23.02.2012, 18:56
Ty3uK

offline
Опыт: 2,469
Активность:
Кстати, разве GetWidgetX/Y не работает быстрее, чем GetUnitX/Y?
Старый 23.02.2012, 18:56
Hanabishi
COOL STATUS
offline
Опыт: отключен
bj_MAX_PLAYER_SLOTS
Это просто константа, максимальное число игровых слотов. Можешь заменить просто на 16.
Fatal Error
Да, есть косяк, исправил:
function Trig_Magic_Ball_Conditions takes nothing returns boolean
    return GetSpellAbilityId()=='A01E'
endfunction

function Trig_Magic_Ball_Actions takes nothing returns nothing
    local unit Unit_TargetMagicBall = GetSpellTargetUnit()
    local unit Unit_CasterMagicBall = GetSpellAbilityUnit()
    local real dx = GetUnitX(Unit_TargetMagicBall)-GetUnitX(Unit_CasterMagicBall)
    local real dy = GetUnitY(Unit_TargetMagicBall)-GetUnitY(Unit_CasterMagicBall)
    local unit UnitLast01
    call TriggerSleepAction(SquareRoot(dx*dx+dy*dy)/650.00-0.30)
    set UnitLast01= CreateUnit(GetOwningPlayer(Unit_CasterMagicBall),'h008',GetUnitX(Unit_TargetMagicBall),GetUnitY(Unit​_TargetMagicBall),270)
    call SetUnitAbilityLevel(UnitLast01,'A01F',GetUnitAbilityLevel(Unit_CasterMagicBall,'A01E'))
    call IssueImmediateOrder(UnitLast01,"thunderclap")
    set Unit_TargetMagicBall = null
    set Unit_CasterMagicBall = null
    set UnitLast01 = null
endfunction

//===========================================================================
function InitTrig_Magic_Ball takes nothing returns nothing
    local integer index = 0
    set gg_trg_Magic_Ball = CreateTrigger()
    loop
    exitwhen(index>=16)
        call TriggerRegisterPlayerUnitEvent(gg_trg_Magic_Ball,Player(index),EVENT_PLAYER_UNIT_SPELL_EFFECT,null)
        set index = index+1
    endloop
    call TriggerAddCondition(gg_trg_Magic_Ball,Condition(function Trig_Magic_Ball_Conditions))
    call TriggerAddAction(gg_trg_Magic_Ball,function Trig_Magic_Ball_Actions )
endfunction
Старый 23.02.2012, 22:50
Закрытая тема

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск

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

BB-коды Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход



Часовой пояс GMT +3, время: 03:36.