Shock Spell Code!

Okay, I'm pretty proud of myself for finally putting together my own piece of code and it working so I thought I'd share it so it could help other people. Make up a little for all of my coding help requests this past week!

Anyone want to shock all the baddies in a room so that they can't act for one turn (2 turns are listed because 1 is taken up with the shock use)? This is how! The only problem is it affects the entire room worth of bad guys. Not sure how to make it targeted only to certain individuals where there are multiple combatants, though. If anyone has the answer to that, I'd be happy to hear it! But in the meanwhile, shock blast!

The combat system is the one from https://github.com/ThePix/quest/wiki/The-Zombie-Apocalypse-(on-the-web-version) in case that helps.

Command Pattern name: shock #object#

Then under script:

if (not HasBoolean(object, "dead")) {
  msg ("That's not something you can attack.")
}
else if (object.dead) {
  msg ("That one is already dead.")
}
else if (HasBoolean(object, "dead")) {
  msg ("Your weapon shocks it, causing it to stumble back.")
  DisableTurnScript (attackturnscript)
  SetTurnTimeout (2) {
    EnableTurnScript (attackturnscript)
  }
}
else {
}

I know that game.
If you want them, the player needs descriptions.

Put this somewhere.

player.critdesc = "#attacker# attack #target# with your bare hands and get a critical (#hits# hits)."
player.attackdesc = "#attacker# attack #target# with your bare hands and hit (#hits# hits)."
player.missdesc = "You swing wildly and entirely miss #target#."

Also, the Quest system already has the multiple combatants thing sorted out. All the monsters have their own name, such as creature1, creature2, and etc. You only need to click on the monster you want to attack.


K.V.

The code looks pretty good to me, but I don't see how it effects more than one object.

I'm not saying you're not speaking the truth, but it seems like you are only targeting one object. Of course, that all depends on what the attackturnscript turn script does, I reckon. (Mm-hmm.)


K.V.

Found it:

https://github.com/ThePix/quest/wiki/The-Zombie-Apocalypse-(on-the-web-version)#zombie-attack

shockturnscript

foreach (obj, GetDirectChildren(player.parent)) {
  if (HasBoolean(obj, "dead")) {
    if (not obj.dead) {
      DoAttack(obj, obj, player)
    }
  }
}

Okie dokey...

Pixie breaks it down on that page already, so I'll see if the way I attempt to explain it helps anything:


GetDirectChildren(player.parent) lists every object in the current room.


foreach (obj, GetDirectChildren(player.parent)) { is the setup to do something to each and every object in the current room.


if (HasBoolean(obj, "dead")) { checks to see if the object as the Boolean attribute "dead". (If it DOES, the script will continue for this object.)


At this point in the script, the object does have the Boolean attribute "dead".

if (not obj.dead) { makes sure it isn't already dead before killing it.


Now, we have checked the following on one of the objects in the current room:

  • It has the Boolean attribute "dead".
  • It is not dead, beacuse dead = false. We know this because (not obj.dead).

So, we shall kill it:
DoAttack(obj, obj, player)


This process will repeat for every object in the current room when calling this turn script.


To only kill the one object which you target in your command, I would make your command more like Pixie's turn script:

if (HasBoolean(object, "dead")) {
  if (not object.dead) {
    DoAttack(obj, obj, player)
  }
  else {
    msg ("That one is already dead.")
  }
}
else {
  msg ("That's not something you can attack.")
}

In fact, I was unfamiliar with this, and I would leave his attack script alone to shock one object, and add a weapon that shocks things when you attack.


You could change your command's pattern to simply: shock room, and market it as a SHOCK ALL THE BAD GUYS command.

THEN just add a weapon that shocks things so you can attack while it's equipped to shock a single target.


Ahh, cool. :) Good points!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums