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

How to make a shield?

Status
Not open for further replies.
Level 19
Joined
Aug 24, 2007
Messages
2,888
Im %99.99999 sure it CANNOT be done in GUI
(Unit - Add Shield to Unit)

I think aznricepuff has one
 
Level 11
Joined
Feb 22, 2006
Messages
752
Remarkably similar question to one tht was asked a week ago:

The overall idea is to detect the casting of a dummy spell (your shield spell basically) and then to create a trigger for the unit with the shield that detects whenever the unit is damaged (or dies). If the unit is damaged, modify the damage by adding the damage back to its life so that it looks like it never took the damage. Then you subtract that damage from the shield's life using variables and such. When the shield "collapses" destroy the trigger. When the unit dies also destroy the trigger to avoid leaking triggers. Make the original trigger (the one that detects spell cast) also check to see if there is ALREADY a shield on the targeted unit. If there is, then don't create a new trigger detecting damage and such, just add 100 (or w/e value u want) to the shield's life (through variables).

JASS:
struct shielddata
    trigger t = CreateTrigger()
    triggeraction taction
    real shieldmaxlife = 100.00
    real shieldlife = 100.00
    method onDestroy takes nothing returns nothing
        call TriggerRemoveAction( .t, .taction )
        call DestroyTrigger( .t )
    endmethod
endstruct
globals
    group shieldgroup = CreateGroup()
endglobals
function Shield_Damage takes nothing returns nothing
    local unit target = GetTriggerUnit()
    local shielddata data = GetUnitUserData( target )
    local real damage = GetEventDamage()
    local real life = GetWidgetLife( target )
    local real maxlife = GetUnitState( target, UNIT_STATE_MAX_LIFE )
    local real lifeback
    if ( life < 0.405 ) then
        //unit is dead, we destroy shield and trigger and don't worry about it anymore
        call data.destroy()
        call GroupRemoveUnit( shieldgroup, target )
        return
    endif
    if ( data.shieldlife - damage <= 0.00 ) then
        //shield is dead because it took too much damage, we manipulate life given back to match shield's remaining life before it "died"
        set lifeback = data.shieldlife
        call data.destroy()
        call GroupRemoveUnit( shieldgroup, target )
    else
        //shield is still alive, so all damage is blocked
        set lifeback = damage
    endif
    if ( life + lifeback >= maxlife ) then
        call SetWidgetLife( target, maxlife )
    else
        call SetWidgetLife( target, life + lifeback )
    endif
    set target = null
endfunction
function Trig_Shield_Spell_Conditions takes nothing returns boolean
    return ( GetSpellAbilityId == 'A000' ) //change rawcode to match one in your map
endfunction
function Trig_Shield_Spell_Actions takes nothing returns nothing
//this is your trigger action for the trigger that detects spell cast
    local shielddata data
    local unit target = GetSpellTargetUnit()
    if ( IsUnitInGroup( target, shieldgroup ) ) then
        //unit already has shield, so we simply add to shield's life and max life
        set data = GetUnitUserData( target )
        set data.shieldmaxlife = data.shieldmaxlife + 100.00
        set data.shieldlife = data.shieldlife + 100.00
    else
        //unit doesn't have shield, so we create one
        set data = shielddata.create()
        call TriggerRegisterUnitEvent( data.t, target, EVENT_UNIT_DAMAGED )
        call TriggerRegisterUnitEvent( data.t, target, EVENT_UNIT_DEATH )
        set data.taction = TriggerAddAction( data.t, function Shield_Damage )
        call SetUnitUserData( target, data )
        call GroupAddUnit( shieldgroup, target )
    endif
    set target = null
endfunction
function InitTrig_Shield_Spell takes nothing returns nothing
     local integer i = 0
     set gg_trg_Shield_Spell = CreateTrigger()
     loop
         exitwhen( i > 11 )
         call TriggerRegisterPlayerUnitEvent( gg_trg_Shield_Spell, Player(i), EVENT_UNIT_SPELL_EFFECT, null )
         set i = i + 1
     endloop
     call TriggerAddCondition( gg_trg_Shield_Spell, Condition ( function Trig_Shield_Spell_Conditions ) )
     call TriggerAddAction( gg_trg_Shield_Spell, function Trig_Shield_Spell_Actions )
endfunction


You will need vJass, and easiest way to get it is from JNGP:

http://www.wc3campaigns.net/showthread.php?t=90999

Make sure you DISABLE WE syntax checker in the Grimoire menu in WE when you start up newgen WE.

This is just a skeleton script. It doesn't have any special effects and it assumes shields are permanent until destroyed. If you need something else (like special effects or timed shields) or want me to change how something works, let me know.
 
Level 9
Joined
Jun 26, 2005
Messages
511
i think the antimagic shell only blocks magic, like spell immu dont have damage resist stats on it.

but back to the shield spell, if i use the add damage taken back to hp of the unit with shield, wouldnt the unit die if it cant take the last hit? let say the shield blocks 100 damage and the creep deals 50 damage, and your unit will have 20hp, that would kill the unit right?
 
Level 11
Joined
Feb 22, 2006
Messages
752
Dracula said:
let say the shield blocks 100 damage and the creep deals 50 damage, and your unit will have 20hp, that would kill the unit right?

Yes, the unit would die. I don't know any way around that caveat. Maybe there's a solution but I can't think of one.


GhostWolf said:
Actualy Anti Magic Shell does block damage from hitting your HP.

It does, but it will only block magic/spell damage.
 
Level 6
Joined
Aug 16, 2007
Messages
213
  • Events: /
  • Conditions:((Triggering unit) has buff Anti-magic Shell) Equal to True
  • Actions:
    • Unit - Add Hardened Skin to (Triggering unit)
    • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
      • If - Conditions
        • ((Triggering unit) has buff Anti-magic Shell) Equal to False
      • Then - Actions
        • Unit - Remove Hardened Skin from (Triggering unit)
      • Else - Actions
Try this out with anti magic shell (only to set shield HP and buff)
 
Status
Not open for further replies.
Top