Home    LittleBigPlanet 2 - 3 - Vita - Karting    LittleBigPlanet 2    [LBP2] Tutorials
#1

Variable Probability and Adding "Luck" to Your RPG Logic

Archive: 11 posts


Hi guys,

This is going to be a really simple but possibly overlooked feature in many of the LBP RPG's I've played... LUCK!

Every RPG has some degree of luck involved - even if it isn't programmed in. There are still some things that only occur a percentage of the time regardless. Then there are things that occur which are "rolled" against your luck stat. In some games you can even decide how much luck you will have (Fallout 3, etc). You might want to have an item that increases or decreases luck. This will address how to do that.

If you're not familiar with the probability model, go check out Comphermc's tutorial on youtube (http://www.youtube.com/watch?v=oVYY0z4HSq8), then come right on back. This is a variation of that, but allowing you to effectively change the number of ports on your OR gate by making your own. I'll assume for the purpose of this tutorial that you only want to have luck between 10% and 50% in increments of 10%.


http://i1.lbp.me/img/ft/241a8c9ff013d0f6d75942bf553bad2e82104482.jpg
Standard Probability Method - 2/7 times the top outcome will be hit, or 28.5% of the time.

In the probability method, you hook up a number of OR gates, with one set being one outcome and the other set being the alternative. The problem with OR gates is that you can't change the number of ports during play. Instead, with variable probability, our "positive" (lucky) outcomes will be 5 microchips with circuit nodes. You'll want these microchips to default to OFF. You can use a tag sensor hooked to them with no corresponding tag to turn them off. The randomizer will still try to activate these circuit nodes even though the signal will not pass through. Each circuit node on the microchips will be connected to an OR gate which will go to any other logic you want to have influenced by luck. The "negative" (unlucky) outcomes will still be an OR gate with 5 inputs with no output. This is because you only want luck to go as high as 50%, as mentioned above. You don't need to add in the extra microchips.


http://ie.lbp.me/img/ft/09e4cab0856ff71beffd97e5396bcdebd13be251.jpg
Variable Probability - The OR gate on the top right will output to your other logic as with normal probability.

You'll hook the randomizer up to each of the circuit nodes on the microchips. Since you can turn microchips on and off, you can change the number of active chips, which in turn, affects your characters luck during play. By default, you'll probably always want one chip to be on so your character has some luck.

To clarify, when the microchips are off, they are functioning as additional ports on your negative OR gate. When they are on, they represent additional ports on your positive OR gate. Since turning one on adds a positive and removes a negative, you can change the ratio of positive to negative gates, increasing or decreasing the chance of a particular outcome.

Next, when you collect or equip the lucky item, it will turn on a tag. Say you want that item to grant a 20% bonus to luck. A tag sensor on your luck chip can now turn on 2 more of the microchips allowing the signal to pass through to your other logic. Now you have 3 of 10 possibilities for the randomizer to hit. It also lets you have different items grant different amounts of additional luck. If your RPG character has a "charm" slot, one necklace can turn on 2 microchips, another ring can turn on 3, etc.

Now, if your RPG is really complex, with multiple items able to be carried or equipped, you might have 2 (or more) items at any given time that will affect luck. In this case, you'll want to go with a sequencer and use the addition/subtraction method (http://www.youtube.com/watch?v=6TCbjIm5kSo).


http://if.lbp.me/img/ft/0efb00151c6d0e94b4d92c880f21902c93c5c1a0.jpg
Addition and subtraction connected to a positional sequencer. The top battery is 100%, the bottom two are 20% each, meaning the output of the final signal combiner is 40% as shown by the sequencer.

You'll then place your batteries on the sequencer, equal to the number of increments of luck you want to have. Those batteries can then be attached to your microchips to determine the total increase in luck.


http://id.lbp.me/img/ft/a0d336aa7a49e578e7523db790f5f6c5ffc36b9c.jpg
By hanging the first battery slightly off the edge of the sequencer, it will be on even when the sequencer has no input.

Post any questions if you have them!

Best of luck (no pun intended),

Shane
2011-12-14 15:50:00

Author:
shane_danger
Posts: 283


You half-lost me through, it's hard to see without pictures. Still, that's advanced stuff
I never really needed randomness other than for visuals. But I'm building an RPG. However, the only luck part is critical hit, and it will be fixed depending on player choice.
2011-12-15 02:31:00

Author:
Unknown User


You half-lost me through, it's hard to see without pictures. Still, that's advanced stuff
I never really needed randomness other than for visuals. But I'm building an RPG. However, the only luck part is critical hit, and it will be fixed depending on player choice.

Well, if you wanted to have an item or weapon with an increased critical hit chance, you could use the same system. Pictures are definitely needed. As soon as I get a chance I will add them.
2011-12-15 02:43:00

Author:
shane_danger
Posts: 283


sorry for the DP, though it's been over a week...

finally got those pics added! much easier to follow along now.
2011-12-22 22:33:00

Author:
shane_danger
Posts: 283


excellent, this is much more reliable than the rig i set up for myself, i will definitely use this technique

thanks
2011-12-23 19:20:00

Author:
Skalio-
Posts: 920


Exercise for the reader (since I don't have LBP access at the moment):

If you randomly choose a percentage from 1 to 100, you can compare it to a desired value to simulate probabilistic scenarios. There are a couple of ways to do this, but if you work it out, it can serve as an extremely robust 'variable probability' system. Let me explain...

Let's say that you have collected a "powerup" (or some luck-related thing, similar to what's described in the OP) that gives a 42% chance of a desired outcome. This just means that it assigns some sort of powerup signal a value of 42%. If you're reading along you probably know what that means, so I won't spend any more time on it.

Alright, so you've got your 42% signal. Now, let's randomly choose a value from 1 to 1001 (a percentage, that is). There is a 42% chance that the randomly chosen signal will be less than or equal to 42%. Well, duh! All you need to do is compare your "powerup" signal value to the randomly chosen one. If the random one is less than or equal to the desired value, you should output a success, whatever that means for your specific application.

There are a few advanced techniques at work, but I figure there are some tinkerers out there who'd want to give it a go. For science!

1To do this, I'd take advantage of our base-10 numbering system. To do that, randomly choose a signal from 0 to 9% and add it to a randomly chosen signal from 0 to 90% (counting by tens), then add 1%. The added 1% moves the range from [0,99] to [1,100]

N.B. You can also use methods of stacking percentages by simply adding together one or more of the "powerup" signals. You guys are all good with addition by now, right?
2011-12-27 23:13:00

Author:
comphermc
Posts: 5338


If you mean you compare your 'set' luck level (which is still a variable via more powerups) at 42% to a secondary random value and discard (fail) amounts over 42%. The secondary number is no longer probability itself... But rather a trigger to check if it will pass.

Then Ummm my Christmas brain says I'll have to get back to you... I have to look at my greater/than less than logic. I know I use it for regen of health to 80% but it's a static 80% but that is set by a battery and not a sequencer... So a signal strength sensor could slot in.

EDIT: actually it does accept variable damage via tags. By changing the tag output from a static battery to the random probability and having this to hit a greater than check it might do something...
2011-12-28 07:03:00

Author:
Mr_Fusion
Posts: 1799


i made a rig for my rpg, its not as complicated but works fine.the rig blocks about 50% of the strikes you make if your lucky maybe it wont block at all. i dont think ill try your way(too complicated) sorry2012-01-30 13:52:00

Author:
wheelbbase911
Posts: 54


i made a rig for my rpg, its not as complicated but works fine.the rig blocks about 50% of the strikes you make if your lucky maybe it wont block at all. i dont think ill try your way(too complicated) sorry

Can you explain how your solution works? Else your comment does not add much to the discussion.
2012-01-30 14:15:00

Author:
Antikris
Posts: 1340


http://i8.lbp.me/img/fs/ca82fa43d396206fe534d88b718179da22a81d82.jpg

The timer changes the input going to the AND gate when the in put is going to the AND gate you will be able to hit the enemy.If there is no input to the AND gate and you hit it, a sound of ringing metal will activate and damage won't be counted.
2012-02-17 22:02:00

Author:
wheelbbase911
Posts: 54


http://i8.lbp.me/img/fs/ca82fa43d396206fe534d88b718179da22a81d82.jpg

The timer changes the input going to the AND gate when the in put is going to the AND gate you will be able to hit the enemy.If there is no input to the AND gate and you hit it, a sound of ringing metal will activate and damage won't be counted.

That's less complicated? I mean, it's fewer pieces of logic, but the point of the tutorial was to enable the player to change a stat during the game by collecting an object or leveling up. "Luck" is just an example. This could be applied to other stats and applications as well. The logic in your image appears to be static, so while it may be simpler, it does not achieve the same effect.

Also it's not so much random as based on the length of time your timer is set to. I'm assuming it's .1 sec, but there's other ways to get 50/50 probability.
2012-02-20 13:58:00

Author:
shane_danger
Posts: 283


LBPCentral Archive Statistics
Posts: 1077139    Threads: 69970    Members: 9661    Archive-Date: 2019-01-19

Datenschutz
Aus dem Archiv wurden alle persönlichen Daten wie Name, Anschrift, Email etc. - aber auch sämtliche Inhalte wie z.B. persönliche Nachrichten - entfernt.
Die Nutzung dieser Webseite erfolgt ohne Speicherung personenbezogener Daten. Es werden keinerlei Cookies, Logs, 3rd-Party-Plugins etc. verwendet.