• 🏆 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!

[General] kill command in multiplayer

Level 6
Joined
May 13, 2023
Messages
44
Hi, I would like to make a trigger that kills the unit currently selected by Player 1, I managed to make a trigger see below. The problem is whenever I use it in Multiplayer it sometimes kills units selected by player 2 or 3 and in other occasions it kicks the players out of the game.
  • Kill Selected Unit
    • Events
      • Player - Player 1 (Red) types a chat message containing -kill as An exact match
    • Conditions
    • Actions
      • Unit Group - Pick every unit in (Units currently selected by Player 1 (Red)) and do (Actions)
        • Loop - Actions
          • Unit - Kill (Picked unit)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,557
That trigger is doing exactly what you've told it to do. You aren't checking who the selected unit belongs to so it'll always kill it regardless.

Also, the (Units currently selected by Player) function causes Desyncs so you'll want to avoid using it in multiplayer.

The solution is to do this:
  • Select
    • Events
      • Player - Player 1 (Red) Selects a unit
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • Unit Group - Add (Triggering unit) to SelectedUnits
  • Deselect
    • Events
      • Player - Player 1 (Red) Deselects a unit
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • Unit Group - Remove (Triggering unit) from SelectedUnits
  • Kill
    • Events
      • Player - Player 1 (Red) types a chat message containing -kill as An exact match
    • Conditions
    • Actions
      • Unit Group - Pick every unit in SelectedUnits and do (Actions)
        • Loop - Actions
          • Unit - Kill (Triggering unit)
  • Die
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Owner of (Triggering unit)) Equal to Player 1 (Red)
    • Actions
      • Unit Group - Remove (Triggering unit) from SelectedUnits
SelectedUnits is a Unit Group variable.
 
Top