Добавлен
Всем привет!
Пытаюсь перенести старый код в vJASS.
Есть такие команды:
  1. GetTableInt(a, "LearnSkillOrder")
  2. SetTableInt(a, "LearnSkillOrder", i)
  3. GetAttachmentTable(GetExpiredTimer())
  4. GetTableUnit(a, "hero")
  5. AttachObject(m, "hero", hero)
Эти команды не работают на vJASS.
Вопрос: Как эти команды будут выглядеть в vJASS?
На всякий случай прикрепляю весь код:
function AILearnSkill takes unit h, string a returns nothing
    local integer i = GetTableInt(a, "LearnSkillOrder")+1
    if i == 1 or i == 4 or i == 8 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill1"))
    elseif i == 2 or i == 5 or i == 9 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill2"))
    elseif i == 3 or i == 7 or i == 10 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "BaseSkill3"))
    elseif i == 6 then
        call SelectHeroSkill(h, GetStoredInteger(udg_GameCache, UnitId2String(GetUnitTypeId(h)), "UltimateSkill"))
    endif
    call SetTableInt(a, "LearnSkillOrder", i)
endfunction

function AISetItem takes nothing returns nothing
    set bj_lastRemovedItem=GetEnumItem()
endfunction

function AIItemFilter takes nothing returns boolean
    return IsItemVisible(GetFilterItem()) and GetWidgetLife(GetFilterItem()) > 0
endfunction

function AIHasEmptyInventorySlot takes unit u returns boolean
    return UnitItemInSlot(u, 0) == null or UnitItemInSlot(u, 1) == null or UnitItemInSlot(u, 2) == null or UnitItemInSlot(u, 3) == null or UnitItemInSlot(u, 4) == null or UnitItemInSlot(u, 5) == null
endfunction

function AIFilterEnemyConditions takes nothing returns boolean
    return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 and IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetAttachedUnit(GetExpiredTimer(), "hero")))
endfunction

function AILoop takes nothing returns nothing
    local string a = GetAttachmentTable(GetExpiredTimer())
    local unit h = GetTableUnit(a, "hero")
    local rect i
    local location r
    local real x = GetUnitX(h)
    local real y = GetUnitY(h)
    local group g
    local boolexpr b
    local boolexpr be
    local unit f
    local string o = OrderId2String(GetUnitCurrentOrder(h))
    local real l = GetUnitState(h, UNIT_STATE_LIFE)
    local real e = 5
    if l <= 0 then
        set e = 1.5
    endif
    if l < GetUnitState(h, UNIT_STATE_MAX_LIFE)/5 then
        call IssuePointOrder(h, "move", GetUnitX(gg_unit_nfoh_0001), GetUnitY(gg_unit_nfoh_0001))
        set e = 3
    else
        if ((o == "smart") or (o == "attack") or (o == "patrol") or (o == "move") or (o == "stop") or (o == "hold") or (o == null)) then
            set g = CreateGroup()
            set b = Condition(function AIFilterEnemyConditions)
            call GroupEnumUnitsInRange(g, x, y, 500, b)
            set f = FirstOfGroup(g)
            if f == null then
                set i = Rect(x-800, y-800, x+800, y+800)
                set be = Condition(function AIItemFilter)
                set bj_lastRemovedItem=null
                call EnumItemsInRect(i, be, function AISetItem)
                if bj_lastRemovedItem != null and (GetItemType(bj_lastRemovedItem) == ITEM_TYPE_POWERUP or AIHasEmptyInventorySlot(h)) then
                    call IssueTargetOrder(h, "smart", bj_lastRemovedItem)
                else
                    set r = GetRandomLocInRect(bj_mapInitialPlayableArea)
                    call IssuePointOrderLoc(h, "patrol", r)
                    call RemoveLocation(r)
                endif
                call RemoveRect(i)
                call DestroyBoolExpr(be)
            else
                call IssueTargetOrder(h, "attack", f)
            endif
            call DestroyGroup(g)
            call DestroyBoolExpr(b)
        endif
    endif
    if GetHeroSkillPoints(h) > 0 and l > 0 then
        call AILearnSkill(h, a)
    endif
    call TimerStart(GetExpiredTimer(), e, true, function AILoop)
    set h = null
    set i = null
    set r = null
    set g = null
    set b = null
    set f = null
    set be = null
endfunction

function StartAI takes unit hero returns nothing
    local timer m = CreateTimer()
    call AttachObject(m, "hero", hero)
    call TimerStart(m, 0, false, function AILoop)
    set m = null
endfunction

function PlayerLeaves takes nothing returns nothing
    local player p = GetTriggerPlayer()
    call DisplayTextToForce(bj_FORCE_ALL_PLAYERS, GetPlayerName(p)+" has left the game.")
    if udg_Hero[GetPlayerId(p)] != null then
        call StartAI(udg_Hero[GetPlayerId(p)])
    endif
    set p = null
endfunction

function SetupSkills takes nothing returns nothing
    local string h
// Paladin
    set h = UnitId2String('Hpal')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AHhb')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AHds')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AHad')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AHre')
// Archmage
    set h = UnitId2String('Hamg')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AHbz')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AHab')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AHwe')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AHmt')
// Mountain King
    set h = UnitId2String('Hmkg')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AHtc')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AHtb')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AHbh')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AHav')
// Blood Mage
    set h = UnitId2String('Hblm')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AHfs')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AHbn')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AHdr')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AHpx')
// Blademaster
    set h = UnitId2String('Obla')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AOwk')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AOcr')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AOmi')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AOww')
// Far Seer
    set h = UnitId2String('Ofar')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AOfs')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AOsf')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AOcl')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AOeq')
// Tauren Chieftain
    set h = UnitId2String('Otch')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AOsh')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AOae')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AOws')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AOre')
// Shadow Hunter
    set h = UnitId2String('Oshd')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AOhw')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AOhx')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AOsw')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AOvd')
// Death Knight
    set h = UnitId2String('Udea')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AUdc')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AUdp')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AUau')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AUan')
// Lich
    set h = UnitId2String('Ulic')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AUfn')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AUfu')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AUdr')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AUdd')
// Dreadlord
    set h = UnitId2String('Udre')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AUav')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AUsl')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AUcs')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AUin')
// Crypt Lord
    set h = UnitId2String('Ucrl')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AUim')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AUts')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AUcb')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AUls')
// Keeper of the Grove
    set h = UnitId2String('Ekee')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AEer')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AEfn')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AEah')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AEtq')
// Priestess of the Moon
    set h = UnitId2String('Emoo')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AEfa')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AEst')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AEar')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AEsf')
// Demon Hunter
    set h = UnitId2String('Edem')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AEmb')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AEim')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AEev')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AEme')
// Warden
    set h = UnitId2String('Ewar')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'AEbl')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'AEfk')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'AEsh')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'AEsv')
// Alchemist
    set h = UnitId2String('Nalc')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANhs')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANab')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANcr')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANtm')
// Naga Sea Witch
    set h = UnitId2String('Nngs')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANfl')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANfa')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANms')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANto')
// Tinker
    set h = UnitId2String('Ntin')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANsy')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANcs')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANeg')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANrg')
// Beast Master
    set h = UnitId2String('Nbst')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANsg')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANsq')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANsw')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANst')
// Dark Ranger
    set h = UnitId2String('Nbrn')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANsi')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANba')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANdr')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANch')
// Firelord
    set h = UnitId2String('Nfir')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANic')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANso')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANlm')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANvc')
// Pandaren Brewmaster
    set h = UnitId2String('Npbm')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANbf')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANdh')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANdb')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANef')
// Pit Lord
    set h = UnitId2String('Nplh')
    call StoreInteger(udg_GameCache, h, "BaseSkill1", 'ANrf')
    call StoreInteger(udg_GameCache, h, "BaseSkill2", 'ANht')
    call StoreInteger(udg_GameCache, h, "BaseSkill3", 'ANca')
    call StoreInteger(udg_GameCache, h, "UltimateSkill", 'ANdo')
endfunction

//===========================================================================
function InitTrig_AI takes nothing returns nothing
    local integer i = 0
    set gg_trg_AI = CreateTrigger(  )
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerEventLeave( gg_trg_AI, Player(i) )
        set i = i + 1
    endloop
    call TriggerAddAction( gg_trg_AI, function PlayerLeaves )
    call ExecuteFunc("SetupSkills")
endfunction

Принятый ответ

NewToJass, vjass это диалект
он ничего не убирает а лишь дополняет
если в vjass чтото не работает то и в jass это тоже не работает
`
ОЖИДАНИЕ РЕКЛАМЫ...
0
1
7 лет назад
0
Или если есть готовые наработки AI (чтобы умели бегать, юзать спелы и т.д) на vJASS, буду благодарен.
Заранее спасибо.
0
28
7 лет назад
0
NewToJass, vjass это диалект
он ничего не убирает а лишь дополняет
если в vjass чтото не работает то и в jass это тоже не работает
Принятый ответ
0
27
7 лет назад
Отредактирован MpW
0
попробуй это
раскрыть
globals
hashtable Hash
endglobals
function AISetItem takes nothing returns nothing
set bj_lastRemovedItem=GetEnumItem()
endfunction
function AIItemFilter takes nothing returns boolean
return IsItemVisible(GetFilterItem()) and GetWidgetLife(GetFilterItem()) > 0
endfunction
function AIHasEmptyInventorySlot takes unit u returns boolean
return UnitItemInSlot(u, 0) == null or UnitItemInSlot(u, 1) == null or UnitItemInSlot(u, 2) == null or UnitItemInSlot(u, 3) == null or UnitItemInSlot(u, 4) == null or UnitItemInSlot(u, 5) == null
endfunction
function AIFilterEnemyConditions takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 and IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), GetOwningPlayer(GetAttachedUnit(GetExpiredTimer(), "hero")))
endfunction
function AILearnSkill takes unit h returns nothing
local integer id = GetUnitTypeId(h)
local integer lv
local integer i = LoadInteger(Hsh,id,4)
if i == 1 or i == 4 or i == 8 then
set lv = LoadInteger(Hash,id,0)
call SelectHeroSkill(h, lv)
elseif i == 2 or i == 5 or i == 9 then
set lv = LoadInteger(Hash,id,1)
call SelectHeroSkill(h, lv)
elseif i == 3 or i == 7 or i == 10 then
set lv = LoadInteger(Hash,id,2)
call SelectHeroSkill(h, lv)
elseif i == 6 then
set lv = LoadInteger(Hash,id,3)
call SelectHeroSkill(h, lv)
endif
call SaveInteger(Hash, id, 4, i+1)
endfunction
function AILoop takes nothing returns nothing
local integer id = GetHandleId(GetExpiredTimer())
local unit h = LoadUnitHandle(Hash, id, 0)
local integer a = LoadInteger(Hash, GetUnitTypeId(h),4)
local rect i
local location r
local real x = GetUnitX(h)
local real y = GetUnitY(h)
local group g
local boolexpr b
local boolexpr be
local unit f
local string o = OrderId2String(GetUnitCurrentOrder(h))
local real l = GetUnitState(h, UNIT_STATE_LIFE)
local real e = 5
local string a = GetAttachmentTable(GetExpiredTimer())
local unit h = GetTableUnit(a, "hero")

if l <= 0 then
set e = 1.5
elseif l < GetUnitState(h, UNIT_STATE_MAX_LIFE)/5 then
call IssuePointOrder(h, "move", GetUnitX(gg_unit_nfoh_0001), GetUnitY(gg_unit_nfoh_0001))
set e = 3
else
if ((o == "smart") or (o == "attack") or (o == "patrol") or (o == "move") or (o == "stop") or (o == "hold") or (o == null)) then
set g = CreateGroup()
set b = Condition(function AIFilterEnemyConditions)
call GroupEnumUnitsInRange(g, x, y, 500, b)
set f = FirstOfGroup(g)
if f == null then
set i = Rect(x-800, y-800, x+800, y+800)
set be = Condition(function AIItemFilter)
set bj_lastRemovedItem=null
call EnumItemsInRect(i, be, function AISetItem)
if bj_lastRemovedItem != null and (GetItemType(bj_lastRemovedItem) == ITEM_TYPE_POWERUP or AIHasEmptyInventorySlot(h)) then
call IssueTargetOrder(h, "smart", bj_lastRemovedItem)
else
set r = GetRandomLocInRect(bj_mapInitialPlayableArea)
call IssuePointOrderLoc(h, "patrol", r)
call RemoveLocation(r)
endif
call RemoveRect(i)
call DestroyBoolExpr(be)
else
call IssueTargetOrder(h, "attack", f)
endif
call DestroyGroup(g)
call DestroyBoolExpr(b)
endif
endif
if GetHeroSkillPoints(h) > 0 and l > 0 then
call AILearnSkill(h)
endif
call TimerStart(GetExpiredTimer(), e, true, function AILoop)
set h = null
set i = null
set r = null
set g = null
set b = null
set f = null
set be = null
endfunction
function StartAI takes unit hero returns nothing
local timer m = CreateTimer()
local integer id = GetHandleId(m)
call AttachObject(m, "hero", hero)
call SaveUnitHandle(Hash, id, 0, hero)
call TimerStart(m, 0, false, function AILoop)
set m = null
endfunction
function SetupSkills takes nothing returns nothing
local integer h
Paladin
set Hash = InitHashtable()
set h =('Hpal')
call SaveInteger(Hash, h, 0, 'AHhb') BaseSkill1
call SaveInteger(Hash, h, 1, 'AHds') BaseSkill2
call SaveInteger(Hash, h, 2, 'AHad') BaseSkill3
call SaveInteger(Hash, h, 3, 'AHre') UltimateSkill
call SaveInteger(Hash, h, 4, 1) общий скилл
endfunction
но не знаю заработает ли. Короче переделал на хэш-таблицу (хотя можно было оставить кэш, но зэш-таблица роднее), так как многих функции отсутствует, пришлось переделывать. Вот например GetAttachedUnit оставил в коде без изменении. Не знаю, сможешь ли хэш-таблица в качестве ключей-равкодов нормально хранить, никогда не пробовал. А так нужно серьезно подумать/переделать все. Точно не отвечаю, что все сразу заработает, потому что не тестил.
Чтобы оставить комментарий, пожалуйста, войдите на сайт.