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

[Spell] Semi-Triggered "Stimpack" Ability

Status
Not open for further replies.
Level 9
Joined
Jan 12, 2010
Messages
454
Hello,

I am trying to make a Starcraft-esk Stimpack ability based on Chemical Rage and using a trigger to "damage" the marine everytime he uses the Stimpack but I'm not quite sure how do go about it, since I want to do a precentage of his total health as damage instead of a set ammount.

Heres what I have so far:

  • Events
    • Unit - A unit Begins casting an ability
  • Conditions
    • (Ability being cast) Equal to Stimpack
  • Actions
    • Unit - Set life of (Triggering unit) to 90.00%
I know this isn't right, since it will set the marine's life to 90% regardless of his current HP.

So how could I damage his health by 10% everytime he uses the Stimpack? And to go with that how could I add a check to not use the ability if his health is below 10%?

And if you havent figured it out yes, I suck at triggering, and could not do it to save my life.

Any help would be greatly appreicated.

Regards,

Jake

(Btw - I posted this here instead of Triggers & Scripts because it said "Need help getting started with a trigger? If so, this is not the right place - please use the World Editor Help Zone.")
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
You do know how percentages work, right? :p
If you want to damage the unit by 10%, just do health = health - max health * 0.10 and you've damaged him for 10% of his max HP ^^


  • Ability
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Chemical Rage
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Percentage life of (Triggering unit)) Greater than 10.00
        • Then - Actions
          • Unit - Set life of (Triggering unit) to ((Life of (Triggering unit)) - (0.10 x (Max life of (Triggering unit))))
        • Else - Actions
          • Unit - Order (Triggering unit) to Stop
You'll have to tick "Data - Morphing Flags -> Interruptible" off.
 
Level 9
Joined
Jan 12, 2010
Messages
454
Ah thanks, but like I said; "I suck at Warcraft III triggering", which is sad since I was pretty good at Starcraft triggering way back when.

Well off-topic aside thanks for the help ap0calypse, a rep to you for humoring my triggering ignorance lol. :grin:

Regards,

Jake
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Oh... I'm sorry, then let me teach you (don't worry, just a teeny weeny little bit).
All triggers you see are actually part of a scripting language called JASS.
To convert a trigger to JASS, you must select the trigger and then go to Edit -> Convert to Custom Text.
When you play a game in Warcraft, all GUI triggers are automatically converted to JASS.

Why do I say this? Well, because if you're really confused about the entire windows within windows thing, then perhaps you could skip GUI altogether and learn JASS? :D

Here's how the trigger looks like when I CONVERT it to JASS:

JASS:
function Trig_Ability_GUI_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A000' ) ) then
        return false
    endif
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hfoo' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Ability_GUI_Func001C takes nothing returns boolean
    if ( not ( GetUnitLifePercent(GetTriggerUnit()) > 10 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Ability_GUI_Actions takes nothing returns nothing
    if ( Trig_Ability_GUI_Func001C() ) then
        call SetUnitLifeBJ( GetTriggerUnit(), ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) - ( ( 0.10 * GetUnitStateSwap(UNIT_STATE_MAX_LIFE, GetTriggerUnit()) ) + 1 ) ) )
    else
        call IssueImmediateOrderBJ( GetTriggerUnit(), "stop" )
    endif
endfunction

//===========================================================================
function InitTrig_Ability_GUI takes nothing returns nothing
    set gg_trg_Ability_GUI = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Ability_GUI, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Ability_GUI, Condition( function Trig_Ability_GUI_Conditions ) )
    call TriggerAddAction( gg_trg_Ability_GUI, function Trig_Ability_GUI_Actions )
endfunction

But don't worry! That code is rubbish...
Here's when I code it myself:

JASS:
function castAbility takes nothing returns boolean
    local real currentHP = GetWidgetLife(GetTriggerUnit())
    local real maxHP = GetUnitState(GetTriggerUnit(), UNIT_STATE_MAX_LIFE)
    
    if GetSpellAbilityId() == 'A000' and GetUnitTypeId(GetTriggerUnit()) == 'hfoo' then
        if currentHP / maxHP > 0.1 then
            call SetWidgetLife(GetTriggerUnit(), currentHP - 0.1 * maxHP) // - 10% of max HP
        else
            call IssueImmediateOrder(GetTriggerUnit(), "stop") // Cancel the spell (not enough HP)
        endif
    endif
    
    return false
endfunction

//These are the events of the trigger
function InitTrig_Ability_JASS takes nothing returns nothing
    set gg_trg_Ability_JASS = CreateTrigger()
    
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Ability_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Ability_JASS, Condition(function castAbility))
endfunction

As you can see, it's a bit more 'clean'.
And it works better: in the first trigger (GUI rubbish), you actually drain 10-11% of his HP each time (due to the sloppy real handling of Warcraft).
In the real JASS trigger, you drain 10%.


But I assume you're not here for a lecture... I'll just send you the testmap so you can see for yourself :)

One last note: all text behind double slashes ("//") doesn't do anything at all (they're comments, meant to say stuff to people).
 

Attachments

  • WorldEditTestMap.w3x
    17.8 KB · Views: 45

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,456
Ah thanks, but like I said; "I suck at Warcraft III triggering", which is sad since I was pretty good at Starcraft triggering way back when.

The same can be said for me... I did a lot with StarCraft editing, even going so far as to program Billiards into it - to an extent - while I just avoided the WarCraft III modding scene until about 2 years ago when I discovered the differences between Events, Conditions and Actions (at least how they operate in GUI) and since then I realized that programming was to be my career choice. Nice opportunities we can owe to the makers of a game originally built on death and destruction.
 
Status
Not open for further replies.
Top