Welcome to the forum, Frobozz.
There are several aspects to doing the type of combat you describe. I'll go over some of them.
First things first, you'll need to declare some
grammar for your code. For instance, your "shoot" verb definition might look like this:
Code: Select all
verb "shoot"
* DoVague
* object DoShoot
* object "with" held DoShoot
Then, you might want to come up with some
object classes (and maybe make up some new
properties while you're at it), like:
Code: Select all
property ammo
class gun
{
type gun
ammo 0
}
(See also HbE's
type entry)
Then you can make all of the guns in your game using that object class. Lastly, you'll want to make a verb routine:
Code: Select all
routine DoShoot
{
! first, check that the player has a gun
local i , n
if not xobject ! if the player didn't specify WHICH gun
{
for i in player
{
if i.type = gun
{
xobject = i
n++ ! count how many guns we've found
}
}
if n > 1 ! more than one gun
{
"You'll have to specify which gun to use."
return false ! don't use up a turn
}
elseif not n
{
"You don't have a gun."
return false
}
}
elseif xobject.type ~= gun
{
"That doesn't make any sense."
return false
}
if not object.after
{
"Why would you shoot that?"
return false
}
return true ! take up a turn
}
Now, you could code your robber like such:
Code: Select all
property hit_points
character ruffian "ruffian"
{
article "the"
adjective 0
noun "ruffian"
is unfriendly
hit_points 100
after
{
object DoShoot
{
if self is not living
{
"The ruffian is already dead."
return true
}
elseif random(2) = 2 ! hit the robber half of the time
{
"You hit!"
self.hit_points -= 50
if self.hit_points < 1
{
"The ruffian dies!"
self is not living
self.name is "dead ruffian"
self.adjective is "dead"
}
}
else
"You miss!"
return true
}
}
Now, that doesn't cover everything and I'm sure there are some bugs there, and there are other ways you could do it. You can also do a system where you character has weapons equipped which are automatically used when the player attacks.
Still, I hope that gives you some ideas about how you'd like to handle it for your game.