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. Lead your forces to battle in the 15th Techtree Contest. The call is yours, commander!
    Dismiss Notice
  4. The reforging of the races is complete. Come see the 14th Techtree Contest Results.
    Dismiss Notice
  5. It's time to choose your horse in the race - the 32nd Modeling Contest Poll is up!
    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.

Sc2 Shield

Discussion in 'Triggers & Scripts' started by GhostThruster, May 11, 2011.

  1. GhostThruster

    GhostThruster

    Joined:
    Jul 24, 2009
    Messages:
    4,845
    Resources:
    34
    Models:
    7
    Icons:
    21
    Packs:
    1
    Skins:
    1
    Maps:
    3
    Spells:
    1
    Resources:
    34
    Well, it's a basic shield system. Take a look. It's only a test. Any errors/shortcuts (I'm aware of the Shield Bar stuffing up constantly)?

    Easy to understand/change and credits are inside.
     
    Last edited: Jun 14, 2011
  2. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    Good job, however I'd like to point out a few things:

    The floating texts. You shouldn't create/destroy them during each loop, change the text instead.

    You could have a string that has as many | characters as the full bar should have. When you create the new string, you don't necessarily have to loop, you could use substring function.

    Text = Full colour + substring from the ||||||| bar + |r + Empty colour + substring from the ||||||| bar + |r

    You're only using two indexes of the point array, use two non-array variables instead.

    In Damage trigger, you're looping through all units in the worst case scenario. I believe using a hastable would be better, especially when there are many units using the shield in the map. You could get the unit's handle and load/save the values into a hashtable.

    • For each (Integer ES_int[4]) from 1 to ES_int[1], do (Actions)
      • Loop - Actions
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • GDD_DamagedUnit Equal to ES_unit[ES_int[4]]
          • Then - Actions
            • Set ES_cd[ES_int[4]] = ES_cdtime[ES_int[4]]
          • Else - Actions


    Ditch the BJ, use native instead :)
    • Custom script: call UnitRemoveAbilityBJ( 'A000', temp_unit )


    Instead of the 0.01 wait, I'd like to see a timer with 0 expiration time.
     
  3. GhostThruster

    GhostThruster

    Joined:
    Jul 24, 2009
    Messages:
    4,845
    Resources:
    34
    Models:
    7
    Icons:
    21
    Packs:
    1
    Skins:
    1
    Maps:
    3
    Spells:
    1
    Resources:
    34
    ~Changed. Btw, is there any advantage using this over having to destroy and re-create the text?

    I'll still need to use a loop to create the 'full bar'. I guess it's just easier the way I did it.

    Again, is there any benefit or does it make no difference? I've seen many other systems use this.


    Lol, sorry I'm not good with hashtables. The loop doesn't do much anyways, it is basically just resetting a few real variables and moving floating text.

    Mind showing me please? I only used Custom Script there because 'temp_unit' is not an 'existing' variable (it only 'exists' in the other custom scripts where I set it up as a local variable).

    ~Changed. Will it still nullify the damage?

    Thank you for the feedback Maker :) +rep
     
  4. Maker

    Maker

    Joined:
    Mar 6, 2006
    Messages:
    9,174
    Resources:
    17
    Maps:
    2
    Spells:
    14
    Tutorials:
    1
    Resources:
    17
    My understanding is that it's better to use the same text so that no new objects are created constantly in memory.


    Non array variables are faster, and reserve less memory.

    You're looping through all units to find the correct unit.

    Let's say you have 80 units in the map that have the shield, and that the GDD_DamageUnit is stored to ES_Unit[80]. In that case there would be 80 checks, which is not good. On average one would have to do maxIndex/2 checks, 40 in this case.

    If the values were saved to a hashtable, then you could just get the handle id of the unit and directly load the data assigned to that id.

    Custom script: call UnitRemoveAbility(temp_unit, 'A000' )

    I just noticed that you should null the unit at the very end of the trigger. Now it's not nulled if the mana condition is not met.

    Yes it should since even a timer with 0 expirating isn't instant. Thus the ability is removed after a delay, and HP is reset.

    You're welcome :)
     
  5. GhostThruster

    GhostThruster

    Joined:
    Jul 24, 2009
    Messages:
    4,845
    Resources:
    34
    Models:
    7
    Icons:
    21
    Packs:
    1
    Skins:
    1
    Maps:
    3
    Spells:
    1
    Resources:
    34
    *There I've fixed it up for ya!

    K, now that you've explained to me, I will fix those things up with the exception of the Hashtable implementation (lolz I don't know how).

    Thanks again.

    Is there no one else who wishes to comment?
     
  6. MiniMage

    MiniMage

    Joined:
    Jun 5, 2008
    Messages:
    1,744
    Resources:
    22
    Models:
    21
    Skins:
    1
    Resources:
    22
    Hehe, the sc2 shields are awesome, I think I'll add them to my goblin map just for the hell of it. XD
     
  7. dardas

    dardas

    Joined:
    Sep 12, 2008
    Messages:
    649
    Resources:
    0
    Resources:
    0
    Hmm.. how about add GetLocalPlayer or so on, to find any player which can see the shielded unit, to show/hide the texttag for, since right now its a very bad tactical spell, since any player in the game sees you from all the map.
     
  8. mckill2009

    mckill2009

    Joined:
    Mar 10, 2009
    Messages:
    4,696
    Resources:
    34
    Maps:
    5
    Spells:
    27
    JASS:
    2
    Resources:
    34
    you should submit this in spell section hehe...
     
  9. GhostThruster

    GhostThruster

    Joined:
    Jul 24, 2009
    Messages:
    4,845
    Resources:
    34
    Models:
    7
    Icons:
    21
    Packs:
    1
    Skins:
    1
    Maps:
    3
    Spells:
    1
    Resources:
    34
    Nah, it's too simple, and half of it is Weep's GDD.

    @dardas: Any recommendations as to who can see the bars and when? If it is only the owning player, then the enemy can not see or measure how much shield strength your unit has when attacking.
     
  10. dardas

    dardas

    Joined:
    Sep 12, 2008
    Messages:
    649
    Resources:
    0
    Resources:
    0
    nah, check fog.
    Code (vJASS):

    native IsFogEnabled takes nothing returns boolean
    constant native IsFoggedToPlayer takes real x, real y, player whichPlayer returns boolean
    constant native IsLocationFoggedToPlayer takes location whichLocation, player whichPlayer returns boolean
    constant native IsUnitFogged takes unit whichUnit, player whichPlayer returns boolean
     

    Hope that helped ^^

    Edit:
    i just thought of this too:
    Code (vJASS):

    constant native IsUnitHidden takes unit whichUnit returns boolean