1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  4. Rubbed the right way, the genie is out of its lamp! The 12th Concept Art Contest Results have been announced.
    Dismiss Notice
  5. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  6. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Mana-based shield system

Discussion in 'Triggers & Scripts' started by Fingolfin, Nov 22, 2009.

  1. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,220
    Resources:
    154
    Models:
    144
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    154
    Hello everyone.
    I was wondering if anyone knows how to make a nice protoss-like shield system using mana points?

    I was checking out this system for damage detection and manipulation:
    http://www.wc3c.net/showthread.php?t=108009

    But cant get it to work somehow, due to optional library requieries (at least one each of wich were implemented!)
    I heard vexorian made a system like this, but i cant seem to find it.
    Noone who could bother helping me out on making this?
    I have basic knowledge of jass and vJass.
    Thanks in advance.
     
  2. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,930
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    The version I had from vexorian was dated. It leaked and infact does not even work in version 1.24 (this was a very old one from pre 1.20 days).

    I advise looking at my shield system in the spell section to see how damage prevention is done and then making your own system.
     
  3. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,220
    Resources:
    154
    Models:
    144
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    154
    I checked your spell pack, really nice. But i cant actually find any damage detection in it; it is using the standard blizzard event "[specific unit] is damaged", and a trigger automatically created for each unit that has the shield. I thought that event was unsafe to use? Or is that "unit is attacked"?

    Furthermore, i understand you are using an ability wich increases health by 2000 while it's applied. Though i found a smaller code snippet in wich a guy had used a similar way, resetting the units hp as soon as it was damaged, but comments suggested that healing up the unit wasn't a good option. Could you explain to me how this system works?

    What i'm searching for is simply a way to detect the damage event, how much damage is dealt, and then stop it from happening. the rest i can do on my own.
     
  4. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    25,930
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    You have to use the even I used, even if for every unit on the map.
    Basically my system detects when a unit takes damage, sets a certain ammount to reheal of the damage taken and makes it so that they can not die from the damage. It then waits 0 seconds via timer (yes 0 is a delay) and reheals the unit the damage it took so that it is back at normal HP.

    My spell had 2 bugs in the maths, one of which I fixed in a non released update. It is still less buggy than a lot of less professional solutions which do not take into account the delay of the damage.
     
  5. Lord_BoNes

    Lord_BoNes

    Joined:
    Sep 5, 2007
    Messages:
    264
    Resources:
    0
    Resources:
    0
    Can't you just give the unit 100% mana shield, when it is created, and then order the unit to activate it.
     
  6. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,220
    Resources:
    154
    Models:
    144
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    154
    No, because mana shield is lame.
    It requires reactivation every time mana runs out, and even though it can be triggered, it leaves a visible icon that gives you the ability to manually deactivate it!
    It just looks so utterly unprofessional.
     
  7. Fingolfin

    Fingolfin

    Joined:
    Jan 11, 2009
    Messages:
    3,220
    Resources:
    154
    Models:
    144
    Icons:
    1
    Packs:
    4
    Skins:
    2
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    154
    I altered your library a little, and here's how it turned out:

    Code (vJASS):
    library DamageShield requires Common, DamageShieldRegen
        //This system requires Dr Super Good's DamageShieldRegen system to opperate.

        globals
            //The system ID is used by the universal hash system to identify data stored on a non local source.
            //This is to prevent collisions with other spells.
            private constant integer SYSTEM_ID = StringHash("Damage Shield")
        endglobals
       
        struct DamageShield
            trigger DamageTrigger = CreateTrigger()
            unit Affected
            boolean ShowArt = false
           
            static method ondamage takes nothing returns boolean
                local real d = GetEventDamage()
                local unit u = GetTriggerUnit()
                if d > 0 then
                if d < GetUnitState(u, UNIT_STATE_MANA) then
                call SetUnitState(u, UNIT_STATE_MANA, GetUnitState(u, UNIT_STATE_MANA)-d)
                call DamageShieldRegen_Add(u,0)
                else
                call DamageShieldRegen_Add(u,GetUnitState(u, UNIT_STATE_MANA)-d)
                call SetUnitState(u, UNIT_STATE_MANA, 0)
                endif
                endif
                set u = null
                return false
            endmethod  
           
           
           
           
            static method get takes unit whichunit returns DamageShield
                //call BJDebugMsg("get")
                return LoadInteger(Chash,GetHandleId(whichunit),SYSTEM_ID)
            endmethod  
           
           
           
            static method create takes unit whichunit returns DamageShield
                local DamageShield shield = DamageShield.allocate()
                set shield.Affected = whichunit
                call TriggerRegisterUnitEvent(shield.DamageTrigger,whichunit,EVENT_UNIT_DAMAGED)
                call TriggerAddCondition(shield.DamageTrigger,Condition(function DamageShield.ondamage))
                call SaveInteger(Chash,GetHandleId(whichunit),SYSTEM_ID,shield)
                set whichunit = null
                return shield
            endmethod

        endstruct
       
        function AddShield takes unit u, boolean art returns nothing
                    local DamageShield shield
                    set shield = DamageShield.get(u)
                    if shield == 0 then
                        set shield = DamageShield.create(u)
                    endif
    endfunction

    endlibrary
     


    It actually works!
    I also have another trigger that uses the AddShield function on new units.

    Thank you, and let me know if there are any flaws in my changes.


    PS: I removed the "onDestroy" method, since the shield will not be destroyed anyways.
    EDIT: just realized it will have to be, once the unit dies. Will fix that later.