1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The poll for Hive's 12th Concept Art Contest is up! Go cast your vote for your favourite genie!
    Dismiss Notice
  4. Travel to distant realms and encounter scenes unknown to the common folk. The Greatest of Adventures is upon us with the 8th Cinematic Contest. Join in on a fun ride.
    Dismiss Notice
  5. The 18th Icon Contest is ON! Choose any ingame unit and give him/her Hero abilities. Good luck to all.
    Dismiss Notice
  6. Contestants are to create a scene set in the Stone Age. Come and see what you can come up with. We wish you the best of luck!
    Dismiss Notice
  7. Colour outside the lines! Techtree Contest #13 is a go. The contest is optionally paired.
    Dismiss Notice
  8. Greetings cerebrates, our Swarm needs new spawners that will have numerous children. Join the HIVE's 31st Modeling Contest - Spawners and Spawned! The contest is optionally paired.
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] How do i transfer these two GUI triggers to JASS?

Discussion in 'Triggers & Scripts' started by wc3neverdies, Aug 9, 2019.

  1. wc3neverdies

    wc3neverdies

    Joined:
    Sep 20, 2015
    Messages:
    268
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hello, i am learning JASS and i can't figure out how to get the equivalent of there 2 GUI trigger is JASS. I think that i didn't understand how timers work in JASS, it seems tha ti can't use udg_variables.

    Trigger 1

    Of course the 0 index in all arrays should be replaced with GetPlayerId(GetTriggerPlayer) in GUI

    • UnitFacingGUI
      • Events
        • Player - Player 1 (Red) issues Mouse Move event
      • Conditions
      • Actions
        • Custom script: call RemoveLocation (udg_MousePosition[GetPlayerId(GetTriggerPlayer())])
        • Set MousePosition[0] = (Mouse Position for Triggered Mouse Event)
        • Set Fangle[0] = (Angle from (Position of PXHero[0]) to MousePosition[0])
        • Unit - Make PXHero[0] face (Angle from (Position of PXHero[0]) to MousePosition[0]) over 0.00 seconds


    Trigger 2

    A LoopForIntegerA should be in the actions here i know, i was just testing.

    • FacingloopGUI
      • Events
        • Time - FTimer expires
      • Conditions
      • Actions
        • Unit - Make PXHero[0] face Fangle[0] over 0.00 seconds
        • Countdown Timer - Start FTimer as a One-shot timer that will expire in 0.01 seconds



    I wrote these in JASS.

    Code (vJASS):


    function Trig_UnitFacingJASS_Copy_Actions takes nothing returns nothing

        local integer i = GetPlayerId(GetTriggerPlayer())
         
        if BlzGetTriggerPlayerMouseX() != 0.00 and BlzGetTriggerPlayerMouseY() != 0.00 then

        set udg_MousePosition[i] = BlzGetTriggerPlayerMousePosition()
        set udg_Fangle[i] = AngleBetweenPoints(GetUnitLoc(udg_PXHero[i]), udg_MousePosition[i])
        call RemoveLocation (udg_MousePosition[i])
        call SetUnitFacing( udg_PXHero[i], udg_Fangle[i] )
        call DisplayTimedTextToForce( GetPlayersAll(), 1.00, I2S(GetPlayerId(GetTriggerPlayer()  )))
        else
        endif
    endfunction


       
       
       
       


    //===========================================================================
    function InitTrig_UnitFacingJAss takes nothing returns nothing
       
        local integer i=0

        set gg_trg_UnitFacingJAss = CreateTrigger(  )

         
       
           
            loop
        exitwhen(i > 24)
        call TriggerRegisterPlayerEvent( gg_trg_UnitFacingJAss, Player(i), EVENT_PLAYER_MOUSE_MOVE  )
        set i = i + 1
        endloop


       
        call TriggerAddAction( gg_trg_UnitFacingJAss, function Trig_UnitFacingJASS_Copy_Actions )

       
    endfunction


     


    Second JASS code block

    Code (vJASS):



    function Trig_FacingLoopJASS_Actions takes nothing returns nothing
        local integer i = 0
       
        loop
        exitwhen ( i > 24)
       
        call SetUnitFacing( udg_PXHero[i], udg_Fangle[i] )
        //call DisplayTimedTextToForce( GetPlayersAll(), 1.00, R2S(udg_Fangle[0]) )
        set i = i + 1
        endloop
        //call SetUnitFacingTimed( udg_PXHero[0], udg_Fangle[0], 0 )
        //call StartTimerBJ( udg_FTimer, false, 0.01 )
    endfunction

    //===========================================================================
    function InitTrig_FacingLoopJASS takes nothing returns nothing
        set gg_trg_FacingLoopJASS = CreateTrigger(  )
        call TriggerRegisterTimerExpireEventBJ( gg_trg_FacingLoopJASS, udg_FTimer )
        call TriggerAddAction( gg_trg_FacingLoopJASS, function Trig_FacingLoopJASS_Actions )
    endfunction
     


    Thanks in advance for the help
     
  2. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,787
    Resources:
    1
    Spells:
    1
    Resources:
    1
    • Instead of detecting mouse move events yourself, I would suggest you use this library, which caches all the important information for you automatically: [vJASS] - [Snippet] Mouse Utility
    • You should use timers directly rather than triggers that fire on a timer expire event.
    • Unless a unit has movespeed of 0, it will always take some finite time to turn to face the target. Keep this in mind, as 0.01 is probably too little time to get it to face properly.
    • vJASS additions like libraries and scopes mean you don't have to use the 'inittrig + actions + conditions' format GUI triggers use.
    • Most (all?) of the natives take angle input in radians and output angles in radians, not degrees. Most of the BJ functions take/return degrees. Also keep this in mind
    If I was doing this I'd write:
    Code (vJASS):
    library FacingStuff requires MouseUtils initializer init
      globals
        private constant real FACE_INTERVAL = 0.05
        private constant integer PLAYER_COUNT = 24
        public timer FaceTimer = CreateTimer()
      endglobals

      private function periodic takes nothing returns nothing
        local integer i = 0
        local real x
        local real y

        loop
          exitwhen i >= PLAYER_COUNT

          set x = GetUnitX(udg_PXHero[i])
          set y = GetUnitY(udg_PXHero[i])
          call SetUnitFacing(udg_PXHero[i], Atan2(UserMouse[Player(i)].mouseY - y, UserMouse[Player(i)].mouseX - x)) //Atan2 returns radians, Facing accepts radians

          set i = i+1
        endloop
      endfunction

      private function init takes nothing returns nothing
        call TimerStart(FaceTimer, FACE_INTERVAL, true, function periodic)
      endfunction
    endlibrary
     
  3. wc3neverdies

    wc3neverdies

    Joined:
    Sep 20, 2015
    Messages:
    268
    Resources:
    1
    Maps:
    1
    Resources:
    1
    Hello, and thank you. How do i use that library? I have to copy paste the library code and your code in my map in a custom script?
     
  4. Pyrogasm

    Pyrogasm

    Joined:
    Feb 27, 2007
    Messages:
    2,787
    Resources:
    1
    Spells:
    1
    Resources:
    1
    No, you can put it in any JASS trigger in your map (or in the CS section if you want, but there's no reason for that). Libraries can go anywhere as long as anything that uses them says so with the requires keyword. The initializer keyword tells the compiler what function to run on map init, and that sets it all up.
     
  5. wc3neverdies

    wc3neverdies

    Joined:
    Sep 20, 2015
    Messages:
    268
    Resources:
    1
    Maps:
    1
    Resources:
    1
    upload_2019-8-10_10-24-11.png

    I copied and pasted the and get this error

    EDIT: NVM I solved it
     
    Last edited: Aug 10, 2019