• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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

Status
Not open for further replies.
Level 9
Joined
Sep 20, 2015
Messages
385
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.

JASS:
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

JASS:
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
 
Level 40
Joined
Feb 27, 2007
Messages
5,151
  • 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:
JASS:
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
 
Level 40
Joined
Feb 27, 2007
Messages
5,151
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.
 
Level 9
Joined
Sep 20, 2015
Messages
385
upload_2019-8-10_10-24-11.png


I copied and pasted the and get this error

EDIT: NVM I solved it
 
Last edited:
Status
Not open for further replies.
Top