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

[General] kill command in multiplayer

Level 6
Joined
May 13, 2023
Messages
45
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 65
Joined
Aug 10, 2018
Messages
6,703
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