# how to check if player not using a shield-mages might

**URL:** <https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311>\
**Category:** Level Help\
**Created:** [June 12, 2021, 10:16pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311 "2021-06-12T22:16:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ProfMonkey07](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/profmonkey07/32/22909_2.png) [@ProfMonkey07](https://discourse.codecombat.com/u/ProfMonkey07)\
**Post date:** [June 12, 2021, 10:16pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/1 "2021-06-12T22:16:43Z")

</div>

Continuing the discussion from [Mages Might can someone help because i suck at coding](https://discourse.codecombat.com/t/mages-might-can-someone-help-because-i-suck-at-coding/29111/3):

so I want to run some code that first checks if the player has enough mana to make a shield, then if the opponent has 15+ mana of a specific type, then check whether or not the player has an active shield of the mana type strong against the mana the opponent has, then cast that shield spell and don’t cast it again until it is broken. I can’t seem to figure out how to detect what type of shield the player is using or whether or not they are using one at all, I know to use hero.getactiveshield but the documentation wasn’t clear on how to use it

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [June 12, 2021, 10:35pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/2 "2021-06-12T22:35:07Z")

</div>

Hi! Could you please post your code, formatting it with the \</\> button so we can see what’s going on?

---

<div class="post-metadata">

**Author:** ![Hydrobolic](https://avatars.discourse-cdn.com/v4/letter/h/e47c2d/32.png) [@Hydrobolic](https://discourse.codecombat.com/u/Hydrobolic)\
**Post date:** [June 13, 2021, 2:25am UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/3 "2021-06-13T02:25:04Z")

</div>

@enPointe77 The question has nothing to do with existing code.

ProfMonkey07–  
Possible duplicate of [here](https://discourse.codecombat.com/t/help-on-mages-might/29284).

You listed four conditions:

1. Do I have enough mana for a shield?  
Check `hero.earth > 3`
2. Does the opponent have enough mana for a ball?  
Check `opponent.fire > 15` where `opponent = hero.getEnemyHero()`
3. Do I have a current shield?  
Check truthiness of `hero.getActiveShield()`
4. What type is my current shield?  
Check `shield.mana` where `shield = hero.getActiveShield()`

Sample solution, in Python, that solves a similar problem to yours. All the same concepts are here.

```python
# Summons shields to block potential enemy ball spells
# Code is untested

opponent = hero.getEnemyHero()

ball_cost = hero.getSpellData("fire-ball").cost
shield_cost = hero.getSpellData("fire-shield").cost

elements = ["fire", "earth", "water"]
affinities = {
  "fire": {"weak": "water", "strong": "earth"},
  "water": {"weak": "earth", "strong": "fire" },
  "earth": {"weak": "fire", "strong": "water"},
}

while True:
  # Condition 3, do nothing if I have an active shield
  shield = hero.getActiveShield()
  if shield: continue

  # This is where you would use Condition 4 if you wish
  # Rather than doing nothing regardless of the shield's type,
  # you could replace your shield if it is of the incorrect type
  # `shield.mana` is one of `elements`

  for element in elements:
    shield_element = affinities[element].weak
    # Condition 2, if the enemy is able to cast a ball
    # and Condition 1, if I can afford a shield to counter it
    if opponent[element] > ball_cost and hero[shield_element] > shield_cost:
      hero.cast(shield_element + "-shield")

```

---

<div class="post-metadata">

**Author:** ![ProfMonkey07](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/profmonkey07/32/22909_2.png) [@ProfMonkey07](https://discourse.codecombat.com/u/ProfMonkey07)\
**Post date:** [June 14, 2021, 10:55pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/4 "2021-06-14T22:55:17Z")

</div>

I do not have any code, I cannot figure out how to use getactiveshield, I just need the syntax for it explained to me

---

<div class="post-metadata">

**Author:** ![ProfMonkey07](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/profmonkey07/32/22909_2.png) [@ProfMonkey07](https://discourse.codecombat.com/u/ProfMonkey07)\
**Post date:** [June 14, 2021, 10:55pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/5 "2021-06-14T22:55:55Z")

</div>

oooh, that makes more sense now, thank you so much

---

<div class="post-metadata">

**Author:** ![enPointe77](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/enpointe77/32/43632_2.png) [@enPointe77](https://discourse.codecombat.com/u/enPointe77)\
**Post date:** [June 14, 2021, 11:01pm UTC](https://discourse.codecombat.com/t/how-to-check-if-player-not-using-a-shield-mages-might/29311/6 "2021-06-14T23:01:48Z")

</div>

Yeah, I see that now.
