Hello!
I'm still fairly new to using Twine, so excuse any fumbles I may have.
I'm making a little RPG game (I'm bored to death at work) and I've run into a small roadblock.
What I want to do:
Have a monster (or even the PC) deal a random amount of damage (per hit or per encounter). I'd also like to have the monster give a random amount of exp (but I'm thinking whatever ends up working with the damage would also work for the exp).
What I've got:
I'm using (datamap:) to load all the monster's information in it so it's easily accessible, which looks something like this:
(set: $wolf to (datamap: "id", "wolf", "type", "animal", "health", 3, "damage", 2, "exp", 3, "loot", (a: "nothing", "wolf pelt")))
The code above has fixed damage and exp reward, how would I change it so that when the monster does damage, it can select from a range (ie. 1 - 3)?
My "combat" passage looks like this:
(set: $monster to $wolf)
(if: (either: 0, 1) is 0)[
The (print: $monster's id) [hits] you!
Your armor shields you for (print: $pc_armor's defense) point(if: $pc_armor's defense < 1)[s] of damage!
You suffer (print: $monster's damage) damage.
(set: $hp to $hp - ($monster's damage - $pc_armor's defense))[
(if: (($monster's damage) - ($pc_armor's defense)) < 1)[
(set: $monster's damage to 0)
]
]
(if: $hp is < 1)[You suffered a fatal wound and died!
[[Restart Your Journey?|1]]
]
(else:)[You have $hp/$max_hp health.
[[(either: "Swing", "Slash")|2 - Fight]]
]
]
(else:)[ You hit the (print: $monster's id) for (print: $pc_weapon's damage)!
(set: ($monster's health) = ($monster's health) - ($pc_weapon's damage))
(if: ($monster's health) < 1)[
(set: $monster_kill to $monster_kill + 1)
The [[(print: $monster's id) is dead|2 - Loot]]! ]
(else:)[
Its health is (print: $monster's health).
[[(either: "Swing", "Slash")|2 - Fight]]
[[Return to Town|2 - Town]] ]
]
Apologies if it looks like a hot mess and sub-optimal (code-wise).
I've tried to add in numbers to an array within the datamap, but it returns an error every time I attempt to access it (specifically with (either: (...$monster's damage))).
Any help would be much appreciated!