• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Unit is selected-problems

Status
Not open for further replies.
Level 8
Joined
Sep 24, 2007
Messages
300
I want to create AMH that detects whether selected unit is visible to player or not.

Preety simple triggering...if everything worked as it should. But ofc it doesnt.

I have no idea how to get out the "Selecting player". Triggering Player DOESN'T work (tried "debugging", it failed completely).

  • add units
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Set array = (array + 1)
      • Set unit[array] = (Triggering unit)
      • Trigger - Add to detect selection <gen> the event (Unit - unit[array] Is selected)
  • detect selection
    • Events
    • Conditions
    • Actions
      • Set player = (Triggering player)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • ((Triggering unit) is visible to player) Not equal to (!=) True
          • Then - Actions
            • Game - Display to (All players) the text: ((Name of player) + is maphacker!)
          • Else - Actions


edit: I tested out. If player 1 selects his own units, triggering player == player 1. If player 1 selects units owned by player 2, triggering unit == player 2.

Totally messed up thing..
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
You can't, but what you can do is have a different trigger for each player (so you know which player selected said unit by which trigger fired). You would need to use a little bit of custom script though.
 
Why don't you use
  • Tr
  • Events
    • Player - Player 1 (Red) selects a unit
    • Player - Player 2 (Blue) ...
    • Player - Player 3 ...
  • Conditions
    • (Unit-type of (Triggering unit)) Equal to X
  • Actions
    • Game - Display to (All players) the text: ((Name of (Triggering Player))+ is a maphacker!)
or
  • Trigger
  • Events
    • Time - Elapsed time is 0.00 seconds
  • Conditions
  • Actions
    • Set Unit1 = (your unit)
    • Player Group - Pick every player in (All players) and do (Actions)
      • Loop - Actions
        • If (All conditions are true) then do (Actions) else do (Actions)
          • If - Conditions
            • ((Unit1) is visible to (Picked player)) Equal to True
          • Then - Actions
            • Game - Display to (All players) the text: "((Name of (Picked player))+ is a maphacker!)"
You can also run a periodic event.
 
Level 8
Joined
Sep 24, 2007
Messages
300
10x again

And the last but not least: Why this won't work? I would like to detect
issued orders the same way as player's selection.
  • order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • Set ugroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in ugroup and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Multiple ConditionsAnd - All (Conditions) are true
                • Conditions
                  • ((Triggering unit) is owned by Player 1 (Red)) Equal to (==) True
                  • ((Target unit of issued order) is visible to Player 1 (Red)) Not equal to (!=) True
                  • (Target unit of issued order) Equal to (==) (Picked unit)
            • Then - Actions
              • Game - Display to (All players) the text: ((Name of Player 1 (Red)) + is maphacker!)
            • Else - Actions
 
Hm, shouldn't this:
  • (Target unit of issued order) Equal to (==) (Picked unit)
be
  • (Picked unit) Not Equal to (Target unit of issued order)
and this

  • ((Target unit of issued order) is visible to Player 1 (Red)) Not equal to (!=) True
should be this
  • ((Target unit of issued order) is visible to Player 1 (Red)) Equal to True
?

Else, I don't get why the trigger should return the Player 1 (Red) as a maphacker.
You also need to define the anti-maphack unit. It has to be a unit type. Currently, you detect every interaction a unit owned by Player 1 can have in-game, so every time a unit owned by Player 1 is issued to target another unit, it will call Player 1 a maphacker, since you pick every unit in the Playable Map Area and you don't define it's unit-type. This is what your trigger does.
Use an additional condition
  • ((Unit-type of (Target unit of issued order)) Equal to (anti-map hack unit)
 
Level 8
Joined
Sep 24, 2007
Messages
300
Trigger is actually like this:
  • order
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Multiple ConditionsAnd - All (Conditions) are true
            • Conditions
              • ((Triggering unit) is owned by Player 1 (Red)) Equal to (==) True
              • ((Target unit of issued order) is visible to Player 1 (Red)) Not equal to (!=) True
        • Then - Actions
          • Game - Display to (All players) the text: ((Name of Player 1 (Red)) + is maphacker!)
        • Else - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Multiple ConditionsAnd - All (Conditions) are true
                • Conditions
                  • ((Triggering unit) is owned by Player 2 (Blue)) Equal to (==) True
                  • ((Target unit of issued order) is visible to Player 2 (Blue)) Not equal to (!=) True
            • Then - Actions
              • Game - Display to (All players) the text: ((Name of Player 2 (Blue)) + is maphacker!)
            • Else - Actions
When there is an issued order, it checks who is the owner and whether the target is visible to the owner. If unit owned by player 1 is issued an order to attack unit owned by player 2 and that unit is not visible to player 1->maphack.

But it doesn't work (nothing happens).
 
How can a unit is issued an order to attack a unit that is not visible to its owner? This is not the way anti-mh works. You should instead just have a check of whether the unit is visible to player. If it is, then it mean that the player is hacking the map. Why don't you visit the Spells section? There alreay are simple GUI-coded anti-mh systems.
 
Level 8
Joined
Sep 24, 2007
Messages
300
How can a unit is issued an order to attack a unit that is not visible to its owner? This is not the way anti-mh works. You should instead just have a check of whether the unit is visible to player. If it is, then it mean that the player is hacking the map. Why don't you visit the Spells section? There alreay are simple GUI-coded anti-mh systems.

With mh? :)
I mean, with MH on, you can order unit to attack enemy units that are actually in fog of war for you.
I even displayed the names of the ordered unit, targeted unit and if it's visible. It worked fine.

Anyway, will check the spells, ty.
 
Level 8
Joined
Sep 24, 2007
Messages
300
Ok, I would like to hide units when they are not visible to player, something
like this:
  • hide
    • Events
      • Time - Every 0.20 seconds of game time
    • Conditions
    • Actions
      • Set ugroup = (Units in (Playable map area))
      • Unit Group - Pick every unit in ugroup and do (Actions)
        • Loop - Actions
          • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • ((Picked unit) is visible to Player 1 (Red)) Not equal to (!=) True
            • Then - Actions
              • Custom script: if GetLocalPlayer() == Player(0) then
              • Unit - Hide (Picked unit)
              • Custom script: endif
            • Else - Actions
              • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • ((Picked unit) is visible to Player 2 (Blue)) Not equal to (!=) True
                • Then - Actions
                  • Custom script: if GetLocalPlayer() == Player(1) then
                  • Unit - Hide (Picked unit)
                  • Custom script: endif
                • Else - Actions
                  • Custom script: if GetLocalPlayer() == Player(0) then
                  • Unit - Unhide (Picked unit)
                  • Custom script: endif
                  • Custom script: if GetLocalPlayer() == Player(1) then
                  • Unit - Unhide (Picked unit)
                  • Custom script: endif
Just the problem is, that when units are hided, they can't be unhided because they can't be seen to player even if they come in line of sight.

So...I need a way to hide/put under cover units in some other way. Ideas are welcome.
 
Last edited:
Thanks, but before other people say so, yeah I know that it doesn't hide the shadow or get rid of the health bar when you press Alt. =P

It isn't the most efficient (due to the shadow and health bar), but it is definitely better than hiding the unit locally.

EDIT: Best way is to make a dummy unit and order them to cast Invisibility on the target unit (No shadow or health bar). The only problem is the detect invisibility abilities and if the target attacks or casts a spell. However, you can use a timer to have a dummy unit constantly cast Invisibility maybe. Unless there is some object editor field that allows you to change the problems listed.

EDIT2: There is also a better way, to add "Ghost" (rawcode: 'Agho') which is the most efficient. (Since you can attack with it up) But I don't know if it'd work for your situation since you want to control who can see him. You can probably tinker around with the invisibility detection but that'd probably collide for the player's units that should be invisible and it'd just be a mess. =(
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If you add permanent invisibility and Ghost at the same time it will make the unit invisible, even when attacking/casting.

Pharoah_ said:
Why don't you use
  • Tr
    • Events
      • Player - Player 1 (Red) selects a unit
      • Player - Player 2 (Blue) ...
      • Player - Player 3 ...
    • Conditions
      • (Unit-type of (Triggering unit)) Equal to X
    • Actions
      • Game - Display to (All players) the text: ((Name of (Triggering Player))+ is a maphacker!)

Whats really dumb about where they've placed this event is that it is actually a player-unit event, yet for some reason they categorize it as a player event. If you look at the JASS code, that event breaks down to:

JASS:
function TriggerRegisterPlayerSelectionEventBJ takes trigger trig, player whichPlayer, boolean selected returns event
    if selected then
        return TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_SELECTED, null)
    else
        return TriggerRegisterPlayerUnitEvent(trig, whichPlayer, EVENT_PLAYER_UNIT_DESELECTED, null)
    endif
endfunction

As you can see, it refers to a player-unit event rather than a player event.
 
Level 8
Joined
Sep 24, 2007
Messages
300
I was thinking about casting spells on units, but I think casting spell on so many units (later in the game it can really increase) every short time period would be too laggy.

I will try adding ghost, because it's made through trigger action.
 
Status
Not open for further replies.
Top