Random Chance while wandering

CheshireTiger
26 Jan 2022, 21:34

Id like an Npc to appear by chance while the player object has a certain flag

Example: player being flaged 'Unlucky' and starts moving around map normally, with a chance of Pickpocket (npc) encounter every time they enter a room.

End result: the npc will not be encountered if

  1. player spends time in any room doing stuff while flagged

  2. player choices did not result in flag in first place


mrangel
27 Jan 2022, 02:43

OK. So you want a script to run when the player enters a new room.
You want the game.roomenter script, which is called something like "Script when entering a room" on the 'Scripts' tag of the game.

You want it to check a flag on the player, for which you use the function GetBoolean, and you want a random chance, for which you use the function RandomChance.

So your script would look like:

if (GetBoolean (game.pov, "unlucky") and RandomChance (15)) {
  // Put the code for your pickpocket event here
}

(Where unlucky is the name of your flag, and 15 is the percentage chance of it happening each time the player enters a room - 15% will be about every 6 rooms on average)

If you'd rather do that using the GUI rather than code view, just create an "If" statement. Set its type to "Expression", and the expression will be GetBoolean (game.pov, "unlucky") and RandomChance (15). (I realise this is probably unnecessary, but too many times lately I've posted code here and got the followup question how to enter it in the GUI, because copy-and-pasting a few lines of code is too hard)


CheshireTiger
27 Jan 2022, 15:39

I see. Thanks again, Angel.