# Summit gate javascript help

**URL:** <https://discourse.codecombat.com/t/summit-gate-javascript-help/32395>\
**Category:** Level Help\
**Created:** [March 18, 2022, 5:40am UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395 "2022-03-18T05:40:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 18, 2022, 5:40am UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/1 "2022-03-18T05:40:42Z")

</div>

> **here the code**
>
> ```python
> // Fight your way into the Inner Sanctum of the ogre chieftain, and defeat her.
> // summon troops
> var stage = 1;
> var tacktick = 'hold';
> var summonTypes = ['griffin-rider'];
> function summon() {
> var types = summonTypes[hero.built.length % summonTypes.length];
> if (hero.gold >= hero.costOf(types)) {
> hero.summon(types);
> }
> }
> 
> /* -summon
> -command
> -findlowhelt
> -attack
> -strat
> -move
> -collect
> -command troop
>    
> */
> 
> function findLowHelt() {
> var lowestHealth = 99999;
> var lowestFriend = null;
> var friends = hero.findFriends();
> for (var f = 0; f < friends.length; f++) {
> var friend = friends[f];
> if (friend.health < lowestHealth && friend.health < friend.maxHealth) {
> lowestHealth = friend.health;
> lowestFriend = friend;
> }
> }
> return lowestFriend;
> }
> 
> function commandPal(pal, warlock) {
> var friends = hero.findFriends();
> var low = findLowHelt();
> for (var i = 0; i < friends.length; i ++) {
> var friend = friends[i];
> if (low) {
> if (pal.canCast("heal", low)) {
> hero.command(pal, "cast", "heal", low);
> }
> } else if (pal.health < 100) {
> hero.command(pal, "shield");
> } else if (stage < 4) {
> hero.command(paladin, "move", {'x': 94, 'y': 34});
> } else if (stage == 5) {
> hero.command(paladin, "move", {'x': 284, 'y': 33});
> } else {
> var enemy = pal.findNearestEnemy();
> if (warlock) {
> enemy = warlock;
> }
> if (enemy) {
> hero.command(pal, "attack", enemy);
> }
> }
>         
> }
> } 
> 
> function commandSol(sol, warlock) {
> var enemy = sol.findNearestEnemy();
> if (warlock) {
> enemy = warlock;
> } if (stage == 3) {
> hero.command(soldier, "move", {'x': 84, 'y': 34});
> } else if (enemy) {
> hero.command(sol, "attack", enemy);
> }
>     
> }
> 
> function commandTroops() {
> var friends = hero.findFriends();
> var warlock = hero.findNearest(hero.findByType("warlock"));
> for (var i = 0; i < friends.length; i ++) {
> var friend = friends[i];
> if (tacktick == 'hold') {
> hero.command(friend, "defend", {'x': 1, 'y': 40});
> } else if (friend.type == "paladin") {
> commandPal(friend, warlock);
> } else {
> commandSol(friend, warlock);
> }
> }
> }
> 
> function move(pos) {
> if (hero.isReady("jump")) {
> hero.jumpTo(pos);
> }
> else {
> hero.move(pos);
> }
> }
> 
> function attack(target) {
> if (target) {
> if (hero.distanceTo(target) < 10) {
> move(target.pos);
> } else if (hero.isReady("bash")) {
> hero.bash(target);
> } else if (hero.canCast("chain-lightning", target)) {
> hero.cast("chain-lightning", target);
> } else {
> hero.attack(target);
> }
>          
> }
> }
> 
> function pickUp() {
> var item = hero.findNearestItem();
> if (item) {
> move(item.pos);
> }
> }
> 
> commandTroops();
> hero.moveXY(31, 56);
> while(true) {
> var catal = hero.findNearest(hero.findByType("catapult"));
> var warlok = hero.findNearest(hero.findByType("warlock"));
> var enemy = hero.findNearestEnemy();
> var item = hero.findNearestItem();
> var time = hero.time;
> if (catal) {
> stage = 1;
> attack(catal);
> } else if (time < 20) {
> tacktick = 'defend';
> stage = 2;
> move({"x": 50, "y": 33});
> } else if (stage < 4) {
> if (enemy) {
> stage = 3;
> attack(enemy);
> }
> else {
> move({"x": 172, "y": 46});
> }
> if (hero.pos.x > 170) {
> stage = 4;
> }
> } else if (stage < 5) {
> if (hero.pos.x < 240) {
> move({"x": 274, "y": 35});
> tacktick = 'defend';
> } else if (item && hero.distanceTo(item) < 10) {
> pickUp();
> tacktick = "attack";
> } else if (warlok) {
> enemy = warlok;
> summon();
> attack(enemy);
> } else if (enemy && enemy.type != 'gates') {
> attack(enemy);
> } else if (item && hero.distanceTo(item) < 45) {
> pickUp();
> tacktick = 'defend';
> summon();
> } else {
> attack(enemy);
> } if (hero.pos.x > 290) {
> stage = 5;
> } 
> tacktick = attack;
> } else {
> summon();
> attack(enemy);
> } commandTroops();
>     
> }
> 
> ```

help while hero trying to kill catapult catapult kill him first anyone have idea how do i avoid getting kiiled?

---

<div class="post-metadata">

**Author:** ![Learned](https://avatars.discourse-cdn.com/v4/letter/l/dec6dc/32.png) [@Learned](https://discourse.codecombat.com/u/Learned)\
**Post date:** [March 18, 2022, 4:34pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/2 "2022-03-18T16:34:29Z")

</div>

I would recommend moving soldiers towards the catapults instead of the hero.

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [March 18, 2022, 4:38pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/3 "2022-03-18T16:38:01Z")

</div>

I just had my character attack the catapults and they didn’t hit me.

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 20, 2022, 2:27pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/4 "2022-03-20T14:27:00Z")

</div>

oh ok sip 20 cahrrrrrr

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 22, 2022, 1:10pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/5 "2022-03-22T13:10:39Z")

</div>

how’d u do that. 20 char

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [March 23, 2022, 12:53pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/6 "2022-03-23T12:53:42Z")

</div>

This is the section of code i use to attack:

> **(it is in python tho)**
>
> ```python
> def attack():
> enemy = hero.findNearestEnemy()
> if enemy and hero.canCast("chain-lightning") and enemy.type != "beam-tower":
> hero.cast("chain-lightning", self)
> elif enemy and hero.canCast("time-travel") and hero.health < 1800:
> hero.cast("time-travel", self)
> elif enemy:
> hero.attack(enemy)
> 
> ```

Gear:  
 ![image](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/e/1/e15538c8d9c5629f2029ef364486c20cabd0f34c.jpeg)

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 23, 2022, 2:00pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/7 "2022-03-23T14:00:46Z")

</div>

cool 200 characterssss

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 23, 2022, 2:01pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/8 "2022-03-23T14:01:11Z")

</div>

wait how u use time travel i never use them before

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [March 23, 2022, 2:23pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/9 "2022-03-23T14:23:57Z")

</div>

It’s the watch’s powerup and once you activate it it will continue your code for three seconds and then put you back where you were when you activated it.

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 23, 2022, 7:05pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/10 "2022-03-23T19:05:16Z")

</div>

so it basiclly return back time?

---

<div class="post-metadata">

**Author:** ![qwerty](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/qwerty/32/30493_2.png) [@qwerty](https://discourse.codecombat.com/u/qwerty)\
**Post date:** [March 23, 2022, 8:14pm UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/11 "2022-03-23T20:14:39Z")

</div>

But only for the person you “cast” it on

---

<div class="post-metadata">

**Author:** ![Haris](https://avatars.discourse-cdn.com/v4/letter/h/ccd318/32.png) [@Haris](https://discourse.codecombat.com/u/Haris)\
**Post date:** [March 24, 2022, 11:56am UTC](https://discourse.codecombat.com/t/summit-gate-javascript-help/32395/12 "2022-03-24T11:56:24Z")

</div>

oh i should use that
