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

Buff Engine Help [Not MUI!]

Status
Not open for further replies.
Hi everybody.

Im currently working on a system of mine. The buff engine.
The problem is that its just not MUI.
I'll give you the code. The system contains 3 example triggers and the loop.
It seems to be something with the loop.
When casting a buff on several units, they will have infinity duration.
When casting two buffs different buffs on units, all of them will have the latest casted buff in inifity time. I hope you can help me.


~x-omg-x

  • Example 1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Buff [Example1]
    • Actions
      • -------- --------
      • -------- Indexing --------
      • -------- --------
      • Set Buff_IndexMax = 50
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Buff_IndexSize Less than Buff_IndexMax
        • Then - Actions
          • Set Buff_IndexSize = (Buff_IndexSize + 1)
        • Else - Actions
          • Set Buff_IndexSize = 0
      • Set Buff_Index = Buff_IndexSize
      • -------- --------
      • -------- Settings --------
      • -------- --------
      • Set Buff_Caster[Buff_Index] = (Triggering unit)
      • Set Buff_SpecialEffect[Buff_Index] = Abilities\Spells\Items\AIre\AIreTarget.mdl
      • Set Buff_Position[Buff_Index] = (Position of Buff_Caster[Buff_Index])
      • Set Buff_Movementspeed[Buff_Index] = (500.00 + (100.00 x (Real((Level of Buff [Example1] for Buff_Caster[Buff_Index])))))
      • Set Buff_Heal[Buff_Index] = 0.00
      • Set Buff_Damage[Buff_Index] = 25.00
      • Set Buff_Duration[Buff_Index] = 5.00
      • -------- --------
      • -------- Starting Up --------
      • -------- --------
      • Unit - Set the custom value of Buff_Caster[Buff_Index] to (Integer(Buff_Duration[Buff_Index]))
      • Unit Group - Add Buff_Caster[Buff_Index] to Buff_Group
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Buff Engine <gen> is on) Equal to True
        • Then - Actions
        • Else - Actions
          • Trigger - Turn on Buff Engine <gen>
      • Custom script: call RemoveLocation(udg_Buff_Position[udg_Buff_Index])
  • Example 2
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Buff [Example2]
    • Actions
      • -------- --------
      • -------- Indexing --------
      • -------- --------
      • Set Buff_IndexMax = 50
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Buff_IndexSize Less than Buff_IndexMax
        • Then - Actions
          • Set Buff_IndexSize = (Buff_IndexSize + 1)
        • Else - Actions
          • Set Buff_IndexSize = 0
      • Set Buff_Index = Buff_IndexSize
      • -------- --------
      • -------- Settings --------
      • -------- --------
      • Set Buff_Caster[Buff_Index] = (Triggering unit)
      • Set Buff_SpecialEffect[Buff_Index] = Abilities\Spells\Human\HolyBolt\HolyBoltSpecialArt.mdl
      • Set Buff_Position[Buff_Index] = (Position of Buff_Caster[Buff_Index])
      • Set Buff_Movementspeed[Buff_Index] = 0.00
      • Set Buff_Heal[Buff_Index] = 20.00
      • Set Buff_Damage[Buff_Index] = 0.00
      • Set Buff_Duration[Buff_Index] = (5.00 + (5.00 x (Real((Level of Buff [Example2] for Buff_Caster[Buff_Index])))))
      • -------- --------
      • -------- Starting Up --------
      • -------- --------
      • Unit - Set the custom value of Buff_Caster[Buff_Index] to (Integer(Buff_Duration[Buff_Index]))
      • Unit Group - Add Buff_Caster[Buff_Index] to Buff_Group
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Buff Engine <gen> is on) Equal to True
        • Then - Actions
        • Else - Actions
          • Trigger - Turn on Buff Engine <gen>
      • Custom script: call RemoveLocation(udg_Buff_Position[udg_Buff_Index])
  • Example 3
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Buff [Example3]
    • Actions
      • -------- --------
      • -------- Indexing --------
      • -------- --------
      • Set Buff_IndexMax = 50
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Buff_IndexSize Less than Buff_IndexMax
        • Then - Actions
          • Set Buff_IndexSize = (Buff_IndexSize + 1)
        • Else - Actions
          • Set Buff_IndexSize = 0
      • Set Buff_Index = Buff_IndexSize
      • -------- --------
      • -------- Settings --------
      • -------- --------
      • Set Buff_Caster[Buff_Index] = (Target unit of ability being cast)
      • Set Buff_SpecialEffect[Buff_Index] = Abilities\Spells\Orc\WarStomp\WarStompCaster.mdl
      • Set Buff_Position[Buff_Index] = (Position of Buff_Caster[Buff_Index])
      • Set Buff_Movementspeed[Buff_Index] = 300.00
      • Set Buff_Heal[Buff_Index] = 0.00
      • Set Buff_Damage[Buff_Index] = (5.00 + (5.00 + (Real((Level of Buff [Example3] for Buff_Caster[Buff_Index])))))
      • Set Buff_Duration[Buff_Index] = 5.00
      • -------- --------
      • -------- Starting Up --------
      • -------- --------
      • Unit - Set the custom value of Buff_Caster[Buff_Index] to (Integer(Buff_Duration[Buff_Index]))
      • Unit Group - Add Buff_Caster[Buff_Index] to Buff_Group
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Buff Engine <gen> is on) Equal to True
        • Then - Actions
        • Else - Actions
          • Trigger - Turn on Buff Engine <gen>
      • Custom script: call RemoveLocation(udg_Buff_Position[udg_Buff_Index])
  • Buff Engine
    • Events
      • Time - Every 1.00 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Buff_Group and do (Actions)
        • Loop - Actions
          • Set Buff_Position[Buff_Index] = (Position of (Picked unit))
          • Set Buff_CustomValue[Buff_Index] = (Custom value of (Picked unit))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • Buff_CustomValue[Buff_Index] Less than or equal to 0
                  • ((Picked unit) is alive) Equal to False
            • Then - Actions
              • Unit - Set (Picked unit) movement speed to (Default movement speed of (Picked unit))
              • Unit Group - Remove (Picked unit) from Buff_Group
            • Else - Actions
              • Set Buff_Duration[Buff_Index] = (Buff_Duration[Buff_Index] - 1.00)
              • Unit - Set the custom value of Buff_Caster[Buff_Index] to (Integer(Buff_Duration[Buff_Index]))
              • Special Effect - Create a special effect at Buff_Position[Buff_Index] using Buff_SpecialEffect[Buff_Index]
              • Special Effect - Destroy (Last created special effect)
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Buff_Damage[Buff_Index] Greater than 0.00
                • Then - Actions
                  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    • If - Conditions
                      • (Life of (Picked unit)) Greater than Buff_Damage[Buff_Index]
                    • Then - Actions
                      • Unit - Cause (Picked unit) to damage (Picked unit), dealing Buff_Damage[Buff_Index] damage of attack type Spells and damage type Normal
                    • Else - Actions
                      • Unit - Set life of (Picked unit) to 1.00
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Buff_Heal[Buff_Index] Greater than 0.00
                • Then - Actions
                  • Unit - Cause (Picked unit) to damage (Picked unit), dealing (0.00 - Buff_Heal[Buff_Index]) damage of attack type Spells and damage type Normal
                • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Buff_Movementspeed[Buff_Index] Greater than 0.00
                • Then - Actions
                  • Unit - Set (Picked unit) movement speed to ((Default movement speed of (Picked unit)) + Buff_Movementspeed[Buff_Index])
                • Else - Actions
          • Custom script: call RemoveLocation(udg_Buff_Position[udg_Buff_Index])
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Number of units in Buff_Group) Equal to 0
        • Then - Actions
          • Trigger - Turn off (This trigger)
        • Else - Actions
[Update]
- Allright, i have found out that my system isnt indexing right, but i dont know how to fix it. Could anyone help me?
- The problem is that it in the loop, is replacing the old values with the new ones.
 
Last edited:
Well I already see a problem here:
  • Set Buff_Position[Buff_Index] = (Position of (Picked unit))
you use Buff_Index without setting it anywhere (therefore it will always affect only the last added buff). You should not loop through Buff_Group, but through Buff_Indexes from 1 to 50.

Im not sure if you mean the following.

I have to get rid of the unit group, and just do

  • For each integer (Integer) from 1 to (Buff_IntegerMax)
    • Set Buff_Position[Buff_Index] = (Position of (Picked unit))
    • [...]
If thats what you mean, then i'll go recoding my system ;)
If not, then please describe it a little bit more. Im pretty new to indexing ;)
 
Level 12
Joined
Apr 15, 2008
Messages
1,063
  • For each integer (Integer) from 1 to (Buff_IntegerMax)
    • Set Buff_Position[Buff_Index] = (Position of (Picked unit))
    • [...]
Not exactly. Here, you use (Picked unit) without Pick Group. The unit you will be referring in this loop is Buff_Caster[Integer A].

If I understand it correctly, you want to keep track of some buffs. That means you need to evaluate each buff every second, not each unit. If one unit had more buffs, it wouldn't work.

Also, you can access unit through buff ID (you saved unit in Buff_Caster), but you can't get buff ID from unit. So for that reason it is easier to loop through buff ID's, rather than units.

So basically what you do each second is that you loop through all buffs there are, substract 1 from their duration and check if they expired. (Also evaluate any effects the buff has)
  • Loop
    • Events
      • Time - every 1 second
  • Actions
    • For (Integer A) from 1 to BuffIDMax
      • If (multiple)
        • Conditions
          • Buff_Caster[Integer A] not equals to No Unit
        • Then
          • Set Buff_duration[Integer A] = Buff_duration[Integer A] - 1
          • If (multiple)
            • Conditions
              • Buff_duration[Integer A] less than or equal to 0
            • Actions
              • Set Buff_caster[Integer A] = no unit
            • Else
              • //--------buff effects
 
Status
Not open for further replies.
Top