Пытаюсь кодить новую WASD систему на Jass но где-то косячнул работает не полностью).Помогите мне пж....
library WASDmovement initializer OnInit requires TerrainPathability 
    globals
        unit array WASD_Hero
       
        boolean array WASD_IsKeyDown_W
        boolean array WASD_IsKeyDown_A
        boolean array WASD_IsKeyDown_S
        boolean array WASD_IsKeyDown_D
       
        constant oskeytype WASD_KEY_W = ConvertOsKeyType($57)      //Wkey
        //constant oskeytype WASD_KEY_W = ConvertOsKeyType($26) //upkey
        constant oskeytype WASD_KEY_A = ConvertOsKeyType($41)      //Akey
        //constant oskeytype WASD_KEY_A = ConvertOsKeyType($25) //leftkey
        constant oskeytype WASD_KEY_S = ConvertOsKeyType($53)      //Skey
        //constant oskeytype WASD_KEY_S = ConvertOsKeyType($28) //downkey
        constant oskeytype WASD_KEY_D = ConvertOsKeyType($44)      //Dkey
        //constant oskeytype WASD_KEY_D = ConvertOsKeyType($27) //rightkey
       
        private constant real WASD_camera = 1800
        private constant real WASD_fps = 1 / 33.0
        private constant real WASD_agi = 3.0
        private constant real WASD_aspd = 0.03
        private boolean WASD_willmove = false
        private timer WASD_timer = CreateTimer()
   
        group Iswalking = CreateGroup()
        group Inbackswing = CreateGroup()
        group Cannotturn = CreateGroup()
        group Cannotwalk = CreateGroup()
        group Cannotmove = CreateGroup()
        real array WASD_angle
   
    endglobals
   
   
    function MoveUnit takes unit unitu, real pointx, real pointy returns nothing
        if IsTerrainWalkable(pointx, pointy) == true then
        call SetUnitX(unitu, pointx)
        call SetUnitY(unitu, pointy)
        endif
    endfunction
   
    private function WASD_move takes nothing returns nothing
        local integer i = 0
        local real WASD_ms
        local real x1
        local real x2
        local real y1
        local real y2
        local real dx
        local real dy
        local real dr
        loop
            exitwhen i > 24
            set dx = 0.0
            set dy = 0.0
            set WASD_willmove = false
           
            if WASD_IsKeyDown_W[i] == true then
                set dy = dy + 1.0
                set WASD_willmove = true
            endif
           
            if WASD_IsKeyDown_A[i] == true then
                set dx = dx - 1.0
                set WASD_willmove = true
                //call DisplayTextToForce( GetPlayersAll(), "A key is down")
            endif
           
            if WASD_IsKeyDown_S[i] == true then
                set dy = dy - 1.0
                set WASD_willmove = true
                //call DisplayTextToForce( GetPlayersAll(), "S key is down")
            endif
           
            if WASD_IsKeyDown_D[i] == true then
                set dx = dx + 1.0
                set WASD_willmove = true   
                //call DisplayTextToForce( GetPlayersAll(), "D key is down")               
            endif
           
            if dx != 0 and dy != 0 then
                set dx = dx/2
                set dy = dy/2
            endif
           
            if WASD_willmove == true then
                call DisplayTextToPlayer( Player(i),0,0, R2S(dx))
                call DisplayTextToPlayer( Player(i),0,0, R2S(dy))
                set WASD_angle[i] = Atan2(dy, dx)
            endif
           
            //moving hero 
            if GetWidgetLife( WASD_Hero[i]) >= 0.405 then //checks if alive
                //call DisplayTextToForce( GetPlayersAll(), "Hero alive")
           
                if IsUnitInGroup( WASD_Hero[i], Cannotmove) == false and  WASD_willmove == true then
                    set WASD_ms = ( 300 + (WASD_agi * GetHeroAgi(WASD_Hero[i], true) ) )  /  ( 1 / WASD_fps)
                    set x1 = GetUnitX( WASD_Hero[i] )
                    set y1 = GetUnitY( WASD_Hero[i] )
                    set x2 = x1 + WASD_ms*Cos(WASD_angle[i])
                    set y2 = y1 + WASD_ms*Sin(WASD_angle[i])
                    call MoveUnit( WASD_Hero[i], x2, y2)
                    call DisplayTextToForce( GetPlayersAll(), "Hero move")
                   
                endif
               
                //changing angle (movement)
               
                if IsUnitInGroup( WASD_Hero[i], Cannotturn) == false and WASD_willmove == true then
                    call SetUnitFacing( WASD_Hero[i], Rad2Deg( WASD_angle[i]) )
                endif
               
                //walking animation
               
                if IsUnitInGroup( WASD_Hero[i], Cannotwalk) == false and WASD_willmove == true and IsUnitInGroup(WASD_Hero[i], Inbackswing) == false then
                //checked if Unit can walk, will walk, alive, in backswing
               
                //check if its already walking
                    if IsUnitInGroup( WASD_Hero[i], Iswalking) == false then
                        call SetUnitAnimationByIndex( WASD_Hero[i] , 3 )
                        call SetUnitTimeScale( WASD_Hero[i], 1 + WASD_aspd*GetHeroAgi( WASD_Hero[i], true) )
                        call GroupAddUnit(Iswalking, WASD_Hero[i])
                    endif
                endif
               
                //turn off walking animation
                if IsUnitInGroup( WASD_Hero[i] , Cannotwalk) == false and WASD_willmove == false and IsUnitInGroup(WASD_Hero[i], Iswalking) == true and IsUnitPaused(WASD_Hero[i]) == false then
                    call GroupRemoveUnit(Iswalking, WASD_Hero[i])
                   call SetUnitAnimationByIndex( WASD_Hero[i] , 2 )
                endif
           
            endif
           
            set i = i + 1
        endloop
   
    endfunction
   
   
   
    private function WASD_WP takes nothing returns nothing
        set WASD_IsKeyDown_W[GetPlayerId(GetTriggerPlayer())] = true
        call DisplayTextToForce( GetPlayersAll(), "W key is pressed")
    endfunction
    private function WASD_WR takes nothing returns nothing
        set WASD_IsKeyDown_W[GetPlayerId(GetTriggerPlayer())] = false
        call DisplayTextToForce( GetPlayersAll(), "W key is released")
    endfunction
    private function WASD_AP takes nothing returns nothing
        set WASD_IsKeyDown_A[GetPlayerId(GetTriggerPlayer())] = true
        call DisplayTextToForce( GetPlayersAll(), "A key is pressed")
    endfunction
    private function WASD_AR takes nothing returns nothing
        set WASD_IsKeyDown_A[GetPlayerId(GetTriggerPlayer())] = false
        call DisplayTextToForce( GetPlayersAll(), "A key is released")
    endfunction
    private function WASD_SR takes nothing returns nothing
        set WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = false
        call DisplayTextToForce( GetPlayersAll(), "S key is released")
    endfunction
    private function WASD_SP takes nothing returns nothing
        set WASD_IsKeyDown_S[GetPlayerId(GetTriggerPlayer())] = true
        call DisplayTextToForce( GetPlayersAll(), "S key is pressed")
    endfunction
    private function WASD_DP takes nothing returns nothing
        set WASD_IsKeyDown_D[GetPlayerId(GetTriggerPlayer())] = true
        call DisplayTextToForce( GetPlayersAll(), "D key is pressed")
    endfunction
    private function WASD_DR takes nothing returns nothing
        set WASD_IsKeyDown_D[GetPlayerId(GetTriggerPlayer())] = false
        call DisplayTextToForce( GetPlayersAll(), "D key is released")
    endfunction
   
    private function WASD_hero takes nothing returns nothing
        if GetOwningPlayer(GetTriggerUnit()) == GetTriggerPlayer() and IsUnitType(udg_Tanks[1], UNIT_TYPE_HERO) == true  then
        set WASD_Hero[GetConvertedPlayerId(GetTriggerPlayer())] = udg_Tanks[1]
        call DisplayTextToForce( GetPlayersAll(), GetUnitName(udg_Tanks[GetConvertedPlayerId(GetTriggerPlayer())]))
    
        
        endif
    endfunction
   
    private function OnInit takes nothing returns nothing
        local trigger wp = CreateTrigger()
        local trigger wr = CreateTrigger()
        local trigger ap = CreateTrigger()
        local trigger ar = CreateTrigger()
        local trigger sp = CreateTrigger()
        local trigger sr = CreateTrigger()
        local trigger dp = CreateTrigger()
        local trigger dr = CreateTrigger()
        local integer i = 0
        local trigger hs = CreateTrigger()
       
        loop
            exitwhen i > 24
            call BlzTriggerRegisterPlayerKeyEvent( wp, Player(i), WASD_KEY_W, 0, true) //for detecting press
            call BlzTriggerRegisterPlayerKeyEvent( wr, Player(i), WASD_KEY_W, 0, false) 
            call DisplayTextToForce( GetPlayersAll(), "W Registed")
           
           
            call BlzTriggerRegisterPlayerKeyEvent( dp, Player(i), WASD_KEY_D, 0, true)
            call BlzTriggerRegisterPlayerKeyEvent( dr, Player(i), WASD_KEY_D, 0, false)
           
            call BlzTriggerRegisterPlayerKeyEvent( ap, Player(i), WASD_KEY_A, 0, true)
            call BlzTriggerRegisterPlayerKeyEvent( ar, Player(i), WASD_KEY_A, 0, false)
           
            call BlzTriggerRegisterPlayerKeyEvent( sp, Player(i), WASD_KEY_S, 0, true)
            call BlzTriggerRegisterPlayerKeyEvent( sr, Player(i), WASD_KEY_S, 0, false)
           
            call TriggerRegisterPlayerSelectionEventBJ( hs, Player(i), true )
            set i = i + 1
        endloop
       
        call TriggerAddAction(wp, function WASD_WP)
        call TriggerAddAction(wr, function WASD_WR)
        call TriggerAddAction(ap, function WASD_AP)
        call TriggerAddAction(ar, function WASD_AR)
        call TriggerAddAction(sp, function WASD_SP)
        call TriggerAddAction(sr, function WASD_SR)
        call TriggerAddAction(dp, function WASD_DP)
        call TriggerAddAction(dr, function WASD_DR)
       
        call TriggerAddAction(hs, function WASD_hero)
       
        set wp = null
        set wr = null
        set ap = null
        set ar = null
        set dp = null
        set dr = null
        set sp = null
        set sr = null
        set hs = null
   
        call TimerStart( WASD_timer, WASD_fps, true, function WASD_move)
    endfunction
endlibrary
`
ОЖИДАНИЕ РЕКЛАМЫ...
28
Пытаюсь кодить новую WASD систему на Jass но где-то косячнул
ты косячнул в синтаксисе, ибо ты приложил код vJass'a
7
Хотя бы уточнил, что именно не работает.
 private function WASD_hero takes nothing returns nothing
        if GetOwningPlayer(GetTriggerUnit()) == GetTriggerPlayer() and IsUnitType(udg_Tanks[1], UNIT_TYPE_HERO) == true  then
        set WASD_Hero[GetConvertedPlayerId(GetTriggerPlayer())] = udg_Tanks[1]
        call DisplayTextToForce( GetPlayersAll(), GetUnitName(udg_Tanks[GetConvertedPlayerId(GetTriggerPlayer())]))
    
        
        endif
    endfunction
Когда красный игрок выберет своей танк он запишется в переменную WASD_Hero[1] , а в таймере на движение и детектах нажатий красный игрок проходит под индексом 0. .
set WASD_Hero[GetConvertedPlayerId(GetTriggerPlayer())] = udg_Tanks[1]
заменить на
set WASD_Hero[GetPlayerId(GetTriggerPlayer())] = udg_Tanks[1]
если все остальные странности кода работают верно, то должно помочь
Ответы (1)
28
если все остальные странности кода работают верно, то должно помочь
У него есть всё самое необходимое в коде, кроме DoNothing почему-то.. вот как можно было забыть вещь, без которой ни один код корректно работать не станет?
Чтобы оставить комментарий, пожалуйста, войдите на сайт.