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

Temporary charm item trigger

Status
Not open for further replies.
Level 1
Joined
Sep 29, 2022
Messages
1
Hi all :)
Ive seen many different posts about mind control and temporary charm triggers, but none of them meet my request...
Im trying to figure out how to make a trigger for an item ability. Hardly tried to change the other already existed triggers of a temporary charm but didnt work at all.

So thats what I want:
An item with a Charm ability used possessing the target (hero or non hero) for 10 seconds and then releases it back to its previous owner.

Im fresh and green in triggering, so the details with explanations would be highly appreciated.
<3
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,597
So this type of ability is pretty much guaranteed to create bugs / issues due to the nature of it. But if you're fine with that then it's not that complicated.

Some questions come to mind though, for example, what happens if you Charm an already Charmed unit? Let's say Player 1 charms Player 2's unit and then Player 3 charms that same unit a moment later. What happens here? The unit must return to it's original owner (Player 2) but it's last owner was Player 1. Issues like these arise when dealing with custom abilities, especially ones of this nature that can easily cause issues with other triggers.

With that in mind, I would design this using a Unit Indexer to track the original Owner of the Charmed unit and any other variables tied to it + a Unit Group to contain the Charmed units + a Periodic Interval trigger which loops over the Unit Group, picks each unit, and manages their Duration / Owner changing effects.

I'll post an example but you won't be able to open my demo map unless you're on the latest version of wc3.

Edit: Here it is. See the attached map for a demonstration. This REQUIRES a Unit Indexer in your map (see the link above).
  • Charm Cast
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Charm (Custom)
    • Actions
      • Set VariableSet Charm_Unit = (Target unit of ability being cast)
      • Set VariableSet Charm_CV = (Custom value of Charm_Unit)
      • Set VariableSet Charm_Duration[Charm_CV] = 10.00
      • -------- --------
      • -------- The original Owner will be (null) by default and after Charm expires: --------
      • Custom script: if udg_Charm_OriginalOwner[udg_Charm_CV] == null then
      • Set VariableSet Charm_OriginalOwner[Charm_CV] = (Owner of Charm_Unit)
      • Custom script: endif
      • -------- --------
      • -------- Change the Owner and Add the Target to the Charm Unit Group: --------
      • -------- [ Note: It's okay to Add a Unit to a Unit Group that it already belongs to. Nothing will happen in that case. ] --------
      • Unit - Change ownership of Charm_Unit to (Owner of (Triggering unit)) and Change color
      • Unit Group - Add Charm_Unit to Charm_UnitGroup
      • -------- --------
      • -------- The Charm Loop trigger will tick down the Duration and reset Ownership once that expires: --------
      • -------- [ Note: It's okay to Turn an already On trigger On again. Nothing will happen in that case. ] --------
      • Trigger - Turn on Charm Loop <gen>
  • Charm Loop
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Charm_UnitGroup and do (Actions)
        • Loop - Actions
          • Set VariableSet Charm_Unit = (Picked unit)
          • Set VariableSet Charm_CV = (Custom value of Charm_Unit)
          • -------- --------
          • -------- The amount you subtract here should be equal to the Periodic Interval time: --------
          • Set VariableSet Charm_Duration[Charm_CV] = (Charm_Duration[Charm_CV] - 0.05)
          • -------- --------
          • -------- If the Duration is <= 0.01 then it's finished: --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Charm_Duration[Charm_CV] Less than or equal to 0.01
            • Then - Actions
              • -------- Reset the Ownership: --------
              • Unit - Change ownership of Charm_Unit to Charm_OriginalOwner[Charm_CV] and Change color
              • -------- --------
              • -------- (Null) the Original Owner variable so that it will get Set again in the Charm Cast trigger: --------
              • Custom script: set udg_Charm_OriginalOwner[udg_Charm_CV] = null
              • -------- --------
              • -------- Remove this unit from the Unit Group so it's no longer ticking down it's duration: --------
              • Unit Group - Remove Charm_Unit from Charm_UnitGroup.
              • -------- --------
              • -------- Turn off this trigger if there are no more charmed units: --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Number of units in Charm_UnitGroup) Equal to 0
                • Then - Actions
                  • Trigger - Turn off Charm Loop <gen>
                • Else - Actions
            • Else - Actions
Edit: I added this trigger to make sure the effects of Charm end when a unit dies:
  • Charm Dies Reset
    • Events
      • Unit - A unit Dies
    • Conditions
      • Charm_Duration[(Custom value of (Triggering unit))] Greater than 0.00
    • Actions
      • Set VariableSet Charm_Unit = (Triggering unit)
      • Set VariableSet Charm_CV = (Custom value of Charm_Unit)
      • -------- --------
      • -------- Reset the Ownership: --------
      • Unit - Change ownership of Charm_Unit to Charm_OriginalOwner[Charm_CV] and Change color
      • -------- --------
      • -------- (Null) the Original Owner variable so that it will get Set again in the Charm Cast trigger: --------
      • Custom script: set udg_Charm_OriginalOwner[udg_Charm_CV] = null
      • -------- --------
      • -------- Remove this unit from the Unit Group so it's no longer ticking down it's duration: --------
      • Unit Group - Remove Charm_Unit from Charm_UnitGroup.
      • -------- --------
      • -------- Turn off the Charm Loop trigger if there are no more charmed units: --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Charm_UnitGroup) Equal to 0
        • Then - Actions
          • Trigger - Turn off Charm Loop <gen>
        • Else - Actions
I wouldn't use Banish as the base ability, that was just for the demo map since I was being lazy. Instead, use something that doesn't have any weird effects.

Also, note that you can categorize any Ability as an Item ability. Furthermore, the ability casting Events such as "A unit Starts the effect of an ability" will work for abilities used by Items. Most new users make the mistake of using the "A unit Uses an Item" Event for this sort of thing but that's not what we need here. Lastly, I'm almost certain that the Item ability category is only for organization purposes and is no different than a Unit ability. In other words, it shouldn't make a difference if you set the ability to an Item or Unit ability.
 

Attachments

  • Charm 2.w3m
    24.7 KB · Views: 6
Last edited:
Status
Not open for further replies.
Top