Command running function starting turnscript is only half working, and I'm pulling my beard out!

CheeseMyBaby
11 May 2018, 15:42Edit: The title should be "half" working, not "halv". Grmmml.
The problem
(code below)First: I know there's plenty of libs around for this. I'm trying to make it work without a lib to do some actual learning.
When the player shoot at an enemy the enemy is supposed to return fire (from turn 2)
This is working if (and only if) the player keep shooting.
Here's an example:
-
shoot soldier
You hit the soldier. -
shoot soldier
You hit the soldier.
The soldier is shooting at you. -
shoot soldier
You hit the soldier.
The soldier is shooting at you.
...this works fine (although it needs more and better scripting, I'm just trying to make it work).
The problem is that if the player does something else, the returned fire.
Example:
-
shoot soldier
You hit the soldier.
The soldier is shooting at you. -
look at self
Wow, you look like a crappy scripter! -
shoot soldier
You hit the soldier.
The soldier is shooting at you.
The question:
How do I make the enemy shoot back at the player even if the player decides to stop shooting?The code
The command:
shoot #object#; fire at #object#
...runs this script:
if (Got(pistol)) {
if (HasAttribute(object, "target")) {
if (object.dead = false) {
if (pistol.bullets > 0) {
msg ("<b>Bang</b>")
pistol.bullets = pistol.bullets - 1
player.weight = Round(player.weight, 2)
player.weight = player.weight - 0.01
takingfire (object, game.pov)
// Universal enemy hit
n = GetRandomInt(1, 100)
if (n <= 30) {
object.ehp = object.ehp - 5
msg ("You hit the " + object.alias + " in the {random:gut:stomach:belly}!")
if (object.ehp <=0 ) {
msg ("The " + object.alias + " is dead!")
object.dead = true
object.alias = ("[✝ ") + object.alias + (" ]")
}
}
else if (n <= 60) {
msg ("You hit the " + object.alias + " in the {random:chest:ribs}!")
object.ehp = object.ehp -5
if (object.ehp <= 0 ) {
msg ("The " + object.alias + " is dead!")
object.dead = true
object.alias = ("[✝ ") + object.alias + (" ]")
}
}
else if (n <= 80) {
msg ("You hit the " + object.alias + " in the {random:left leg:right leg:left foot:right foot:left knee:right knee}.")
object.ehp = object.ehp - 1
if (object.ehp <=0 ) {
msg ("The " + object.alias + " is dead!")
object.dead = true
object.alias = ("[✝ ") + object.alias + (" ]")
}
}
else if (n <= 90) {
msg ("You miss.")
}
else if (n <= 99) {
msg ("You hit the " + object.alias + " in the face!")
object.ehp = object.ehp - 9
if (object.ehp <=0 ) {
msg ("The " + object.alias + " is dead!")
object.dead = true
object.alias = ("[✝ ") + object.alias + (" ]")
}
}
else if (n = 100) {
msg ("Headshot! The " + object.alias + " head explodes!")
object.ehp = object.ehp - 50
if (object.ehp <=0 ) {
msg ("The " + object.alias + " is dead!")
object.dead = true
object.alias = ("[✝ ") + object.alias + (" ]")
}
}
}
else {
msg ("You need to reload!")
}
}
else {
msg ("No point in wasting bullets on the dead.")
}
}
else {
msg ("Maybe you sholdn't shoot at that?")
}
}
else {
msg ("You point your index finger towards " + object.alias + " and shout <b>pew pew</b>.")
}
The function
being called is this:(It's not finished yet, obviously. At the moment it's just printing a line. I did this to check if the
weapontype
-attribute is working.)
if (object.dead = true) {
DisableTurnScript (underattack)
object.attacking = false
}
else if (object.attacking = false) {
object.attacking = true
}
else if (object.weapontype = 0) {
msg ("FIST Attack")
}
else if (object.weapontype = 1) {
msg ("PISTOL Attack")
}
else if (object.weapontype = 2) {
msg ("RIFLE Attack")
}
else if (object.weapontype = 3) {
msg ("BAZOOKA Attack")
}
else {
if (object.dead = true) {
}
}
The turnscript
Is only recalling the function:
takingfire (object, game.pov)

K.V.
11 May 2018, 15:59I can't really test this without the whole game, but try this script in the place of what you've got for your function:
// Check if object is dead
if (not GetBoolean(object, "dead")) {
// Not dead, so make sure object is attacking
if (not object.attacking) {
// Not attacking, but should be. So set to true
object.attacking = true
}
// Make sure object has a weapontype
if (not HasAttribute(object, "weapontype")) {
msg ("NO attack set up!")
}
else {
// The object does have a weapontype, so let's do this!
switch (object.weapontype) {
case (0) {
msg ("FIST Attack")
}
case (1) {
msg ("PISTOL Attack")
}
case (2) {
msg ("RIFLE Attack")
}
case (3) {
msg ("BAZOOKA Attack")
}
default {
// The weapon type is not accounted for in the above switch script
msg ("The weapontype is not listed!")
}
}
}
}
else {
// object is dead!!!
DisableTurnScript (underattack)
object.attacking = false
}

CheeseMyBaby
11 May 2018, 16:17No difference I'm afraid.

K.V.
11 May 2018, 16:30If you email me the files, I'll investigate.
UPDATE
Also include the commands to get me there, please, sir.

K.V.
11 May 2018, 16:36Never mind. I see the problem.
Try this on the turn script:
foreach(object, ScopeReachable()){
if (HasAttribute(object, "attacking")){
takingfire (object, game.pov)
}
}
EDIT
If the player can have the "attacking" attribute at any point, you probably want to change the first line to this to exclude the player:
foreach(object, ListExclude(ScopeReachable(), game.pov)){
If you see how the switch script works, I'd recommend using that code instead of your original code. It checks for two or three more things to avoid errors, plus it is MUCH easier to modify later, especially when adding attacks. You only need to add a case (or modify a case).
http://docs.textadventures.co.uk/quest/functions/corelibrary/scopereachable.html
http://docs.textadventures.co.uk/quest/scripts/foreach.html

CheeseMyBaby
11 May 2018, 17:19I get what you're saying about the switch. Good thinking!
The rest is still the same though. I'll put the kids to bed and then look at it with, hopefully, a fresh pair of eyes!
Thanks for trying KV!

K.V.
11 May 2018, 17:52I get what you're saying about the switch. Good thinking!
mrangel and Pixie nearly had to beat me over the head to get me to try using switch scripts...
Kids, always listen to mrangel and Pixie!
The rest is still the same though.
Damn and blast! Send me those files, and I'll kick their ass!
I'll put the kids to bed and then look at it with, hopefully, a fresh pair of eyes!
Yeah, that sounds like a solid plan.
Is your turn script enabled?
I see where you disable it, but I don't see it being enabled. It seems like it should be here:
EDITED - This is version 2
if (Got(pistol)) {
if (HasAttribute(object, "target")) {
if (object.dead = false) {
if (pistol.bullets > 0) {
msg ("<b>Bang</b>")
pistol.bullets = pistol.bullets - 1
player.weight = Round(player.weight, 2)
player.weight = player.weight - 0.01
// commented out because the turn script will call this
//takingfire (object, game.pov)
// Added by KV
object.attacking = true
EnableTurnScript (underattack)

CheeseMyBaby
11 May 2018, 20:01Is your turn script enabled?
This is where I go stick my head in the cat's litter box.

K.V.
11 May 2018, 20:17Everyone who has ever created a turn script has forgotten to enable a turn script at least once (if not 100 times).

CheeseMyBaby
11 May 2018, 21:37I'm making a vow right now. This was the first and last time this happens!
(or I'll wear that litter box as a hat all year long)

K.V.
11 May 2018, 22:17Ha!
Dude...
Send me a picture of you wearing that hat!
(I've forgotten to enable a turn script of my own within this past hour. It was only the 111th time I failed to enable a turn script...)
hegemonkhan
12 May 2018, 00:51every (even professionals as well) programmer (and computer user/fixer) has made some very stupid mistakes... it's just human nature, lol
(HK has some great "stories of stupidity" .... laughs.... embarrassedly...)