• 🏆 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!
  • ✅ The POLL for Hive's Texturing Contest #33 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!

[Trigger] Need help with selecting units in view of camera...

Status
Not open for further replies.
Level 4
Joined
Aug 12, 2014
Messages
48
I never had to make a trigger like this so I am not sure if I am even on the right track. In the Multi-player RPG I am developing, I decided to make it so no selections are allowed, everything has to be triggered to select a unit.

  • Actions
    • Game - Disable selection and deselection functionality (Disable selection circles)
    • Game - Disable pre-selection functionality (Disable pre-selection circles, life bars, and object info)
(This prevents you from directly selecting units. You can still select units in other ways with triggers)

The bellow trigger sort of works. It finds all units in view of the character and randomly selects one for the player.

  • Red Selection
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set Selection_Hero_Position = (Position of Chosen_Hero[1])
      • Set Selection_Player_Hero = Chosen_Hero[1]
      • Set Selection_Enemy_Units = (Units within 1400.00 of Selection_Hero_Position matching (((Matching unit) belongs to an enemy of Player 1 (Red)) Equal to True))
      • If ((Selection_Enemy_Units is empty) Equal to True) then do (Game - Display to Player Group - Player 1 (Red) the text: No targets are in t...) else do (Do nothing)
      • Unit Group - Pick every unit in Selection_Enemy_Units and do (Actions)
        • Loop - Actions
          • Selection - Add (Random unit from Selection_Enemy_Units) to selection
          • Set Selection_Target = (Picked unit)
          • Set Selection_Targets_Position = (Position of Selection_Target)
          • Set Range_1 = (Cos(((Angle from Selection_Hero_Position to Selection_Targets_Position) - (Facing of Selection_Player_Hero))))
          • Set Range_2 = (Cos(30.00))
          • Custom script: set udg_Range_2 = Cos(80 * bj_DEGTORAD)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Range_1 Greater than Range_2
            • Then - Actions
              • Selection - Add (Picked unit) to selection for Player 1 (Red)
              • Set Selection_RED_Target = (Picked unit)
              • Trigger - Turn on Red Target <gen>
              • Game - Display to Player Group - Player 1 (Red) for 0.50 seconds the text: Found A Target
            • Else - Actions
(This is just testing at this point, I will clean up the trigger, all leaks, etc if I decide to keep this system)

PROBLEM:
For some reason, when I hit escape, it finds a unit and adds it (working as it should) but when I click on it from my available selections, it right away removes the unit from selections leaving only my hero selected.

or

It adds it for a fraction of a second and then right away removes it leaving only my hero selected. This is what usually happens the first time I hit escape but if I hit escape 3, 4, 5 times, the trigger works just fine. What do I need to change in the trigger? IS it also possible that part of the problem is a unit / vision / acquisition range issue?

HOW I WANT IT TO WORK BECAUSE I THINK I NEED TO START OVER:

First/3rd person RPG game loads... Hero is always selected... he runs around and finds a unit he wants to kill (unit is literally visible on screen)... player hits escape and with hero still selected, it cycles through visible units and adds one to his selections, hero can then click on the unit in his selection window and do whatever... or hit escape and keep cycling through until he gets the particular unit he wants.

How can I rewrite this so that it works as I would like it to. I made this Frankenstein trigger using different system I found here on hive so I know its far from perfect.
 
Last edited:
For some reason, when I hit escape, it finds a unit and adds it (working as it should) but when I click on it from my available selections, it right away removes the unit from selections leaving only my hero selected.

or

It adds it for a fraction of a second and then right away removes it leaving only my hero selected. This is what usually happens the first time I hit escape but if I hit escape 3, 4, 5 times, the trigger works just fine. What do I need to change in the trigger? IS it also possible that part of the problem is a unit / vision / acquisition range issue?

HOW I WANT IT TO WORK BECAUSE I THINK I NEED TO START OVER:[/COLOR]
First/3rd person RPG game loads... Hero is always selected... he runs around and finds a unit he wants to kill (unit is literally visible on screen)... player hits escape and with hero still selected, it cycles through visible units and adds one to his selections, hero can then click on the unit in his selection window and do whatever... or hit escape and keep cycling through until he gets the particular unit he wants.

How can I rewrite this so that it works as I would like it to. I made this Frankenstein trigger using different system I found here on hive so I know its far from perfect.

First, have you tried creating a parallel unit array for the Chosen Hero, like Chosen Hero target? That way, you could filter out which unit is selected and make sure that the system you're using does not deselect the target unit. This can be achieved by having a trigger detect a generic unit selection.

Second, is this MPI? It seems like it only filters out one player, not that I have a problem with it here.
Third, what is this udg_Target_Location variable? Does it have a value?

Fourth,

JASS:
set udg_Range_1 = Cos(AngleBetweenPoints(udg_Selection_Hero_Position, udg_Selection_Targets_Position)) - GetUnitFacing(udg_Selection_Player_Hero))
set udg_Range_2 = CosBJ(30.00)
set udg_Range_2 = Cos(80 * bj_DEGTORAD) // Same as CosBJ(80)

Why are these values calculating their angles instead of distance?
 
Level 4
Joined
Aug 12, 2014
Messages
48
Thanks for the reply. I will answer you one by one.

First: No, not yet, the trigger was thrown together late last night from various resources I found online / hive, hence the sloppy trigger and my inability to figure out the bug. I think I get what you mean though and I will try that also.

Second: Yes and no. This trigger is an attempt to see if this is a good direction to take the map in or not. Currently its just in testing but if I like it and it adds to the overall project, I will make it MPI for other users. I just put this trigger on the side while I work on other parts of the map.

Third: There are other triggers that fire and add the shop arrow effect over the target. Easy way to know which target is selected. Nothing to do with this trigger itself.

Fourth: Like I said, I never had to do a trigger like this. I thought to know if the target unit is in front of the hero (visible on screen with first person camera) I need angles more so than distance? I don't necessarily want the closest unit - I want to be able to cycle through all units in front of the hero - one at a time.

Again MyPad, thank you for the input. I am pretty good with GUI and know a little Jass but I don't really know how to make this sort of trigger. I read and understood more or less a few GNU systems on hive but I went with this because I want to exclude those units who are behind the hero and only cycle through those in front of the hero up to a certain range, selecting only one unit at a time in addition to the hero. I am guessing my thinking on this is wrong and I can alter a get nearest unit trigger to do this much more efficiently?
 
I see now what you intend to do.

You seem to know a little bit of jass so I'll post this function for you.
You can place this in a GUI to JASS trigger or in the custom script found in the Map section.

JASS:
function Angle2Angle takes real angle returns real
    local real angleDiv = angle / 180
    if R2I(angleDiv) - R2I(angleDiv)/2*2 == 0 then
        if angle > 180 then
            set angle = angle - I2R(R2I(angle/180)*180)
        elseif angle < -180 then
            set angle = (angle - I2R(R2I(angle/180)*180)) + 180
        endif
    elseif RAbsBJ(R2I(angleDiv) - R2I(angleDiv)/2*2) == 1 then
        if angle > 360 then
            set angle = angle - I2R(R2I(angle/360)*360)
        elseif angle < -360 then
            set angle = (angle - I2R(R2I(angle/180)*180)) + 360
        endif
    endif
    return angle
endfunction

function CoordinatesInSightRange takes unit whichUnit, real x, real y real angle_tolerance returns boolean
    return RAbsBJ(bj_RADTODEG * Atan2(y2 - GetUnitY(whichUnit), x2 - GetUnitX(whichUnit)) - Angle2Angle(GetUnitFacing(whichUnit))) <= angle_tolerance
endfunction

function PointInSightRange takes unit whichUnit, location loc, real angle_tolerance returns boolean
    return CoordinatesInSightRange(whichUnit, GetLocationX(loc), GetLocationY(loc), angle_tolerance)
endfunction
 
Status
Not open for further replies.
Top