[SOLVED] make it so that when a player does something it activates a randomizer

Started by keozeo, Tue 25/08/2015 06:11:50

Previous topic - Next topic

keozeo

Ok so I made a sanity meter and now I'm working on some basic effects. I want for when the player examines/picks up/uses an item or opens a door it has a chance of displaying a message if your sanity is below 45. I have the randomizer and sanity variable displayed here:
Code: ags
if (player_Sanity< 45)
{
    int dice_roll = Random(100);
    if (dice_roll < 25)
    {
       (Display "I'm a bit tense.")
       
    }
}
but I'm missing the "flag" or trigger for it if you will. I have the variable as a global. I'm pretty sure this is incredibly simple.

Mandle

Well for example:

Picks up an object:

You will link this event through the Room's Objects screen by selecting the object and clicking on "Player Interacts Object" in the bottom right area. Then click the little doodad next to the script reference that shows up. This will take you to the part of the room script that handles what to do when the object is clicked on with the Interact Cursor. In here you will tell AGS to make the object invisible and also add the relevant Inventory Item to the player's inventory. Now you can also place you code in this same function so that your sanity meter is checked when the player picks up the certain object.

There are more global ways to do this as well but this is the simplest method.

(For example a more efficient way would be to put all your Sanity Meter stuff into a Function called Check_Sanity or whatever and then call that function instead of putting the same code into every interaction possible)

For examine do the same steps but link from when the player uses the Look Cursor on something etc etc.

I might also add that your question in this thread is more like "How do I use AGS?" as this is all really basic stuff that you really need to know to get anywhere using the program. I know that just looking at the manual as a newcomer is very overwhelming...

I would suggest you go to youtube and search for "How to use AGS". There is an amazing series video tutorials there using the game "Danny's Quest" as the example build I believe. Even just watching the first few videos will show you how to do what you are asking in this thread, but I highly suggest watching through the whole series.

It will teach you everything you need to know to make a game, and give you the tools to figure out the rest in creative ways on your own.

Cheers!

keozeo

Thanks, this was massively helpful. I think I can do it now.
Edit: Ok so here's what I did so you can imitate or do the same.
Code: ags
function Check_Sanity (int)  
{
if (player_Sanity< 45)
{
    int dice_roll = Random(100);
    if (dice_roll < 25)
    {
       (Display "I'm a bit tense.")
       
    }
}
I'm not only going to make that one function, I'm going to make 1 other one for door ways that, when your sanity gets low enough, a random dice roll could make the door lead somewhere else. I think I know how to do this so it should be simple.

Edited by mod: Removed unnecessary quote.

Khris

Please don't quote the entire previous post.

Go to other room randomly:
Code: ags
function GoToRoom(int r1, int r2) {
  int r = r1;
  if (player_sanity < 45 && Random(100) < 25) r = r2;
  player.ChangeRoom(r);
}


Now call GoToRoom(3, 12); instead of player.ChangeRoom(3);

keozeo

Quote from: Khris on Tue 25/08/2015 08:53:12

Go to other room randomly: (code here)

Now call GoToRoom(3, 12); instead of player.ChangeRoom(3);
Sorry, I wond quote the entire post anymore. Thanks man. This has been a big help, and I hope you all enjoy what comes out of it

SMF spam blocked by CleanTalk