I want to take the player to a different death screen depending on what kills them

I am working on my first game, and I want to do the thing I mentioned in the title. However, I don’t know how to do it. To help, here is a simple example to show what I want to do.

There is a simple game with 3 rooms: room 1, room 2, and room 3. The player starts in room 1. If the player enters into room 2, they get attacked by a bear, and lose 50% of their health (in my game, losing health is caused by entering the room, and not by the object.) If a player enters room 3, they get attacked by a Lion, and lose 50% of their health. In this example, I would want “You have been killed by a bear: game over” when the player is killed by the bear, and “You have been killed by a lion: game over” when the player is killed by the lion. Obviously, my game has a lot more, and a lot more ways to die. However, just tell me what to do for my example, and I will figure it out for my actual game.

EDIT: I am making a text adventure.


I'm sure someone will come to your rescue with a piece of code for you, but I think the easiest way would be to have a script which checks which room the player was in when the players health reaches or becomes less than zero, and then prints the message accordingly based on the outcome of that check.


Are you creating a gamebook or a textadventure?


I apologize if this has been a while since you posted this, im bad with dates. But im currently attempting to make a solution to your problem, only requiring you to make objects and rooms, one room per ending that is. If you wish to talk privately about it, My discord is ᒲᔑ∷╎#3200 The weird letters are simply Standard Galactic Alphabet for Mari.
My idea is you can do what you want there via simply using object containers to act as a trigger switch, If you go into 1 room, You take 50 damage, and the room closes/opens the container, And the next room detects that, And if it has will send you to the end room, Aka the ending. Meaning you can also extend this via if's and elses.


For example, I made a "game" using that, And the script i used was
"
DecreaseHealth (50)
if (not Hp Ending Detector 1.isopen) {
MoveObject (player, Vacuum)
}
else {
HelperCloseObject (Hp Ending Detector 1)
}
"
Replace the names with your named stuff, The Hp Ending Detector 1 is the container i was using, Just need to start it off as open, and a openable/closable container. Im testing this right now, And if it works i will say such.


It does work, The link is this, Please note that i made this as a example/test, So it doesnt look amazing.
https://textadventures.co.uk/games/view/rjzsjllsdkeuwotmlxf7nq/script-testing-2


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

Support

Forums