• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Help with chance system

Status
Not open for further replies.
Level 3
Joined
May 22, 2007
Messages
30
I want to make a chance system for my game for a job in it (Mining).
Is there any way to make a chance system where there's a ##%/100% chance of getting something? (Ex- 47%/100%, 1%/100%,etc)
I want it to be able to randomly choose an item but have some items rarer than others, such as a regular crystal being easier to find than a diamond, for example. I think I've got the system of using the mining pick right (Unit uses an item, Conditions are that item being manipulated is a Mining Pick and in the Mining Area) but now I just need the actions for the chance system. And I have no idea how to use JASS eaither so don't recomend JASS triggers to me :sad:.
Thanks in advance
 
Level 2
Joined
Nov 8, 2007
Messages
19
im not sure but this isnt hard!!

you just need an integer variable that gets a random value between 1 and 100.
so.
and then just check if the value is between (in your example=47%/100%)
1 and 47 (chance of 47%) and if it is call your actions.

whats the problem?
 
Level 3
Joined
May 22, 2007
Messages
30
<--- Variable noob
Just starting to really try to understand variables :confused: lol
thanks for the help though. I was trying to use a Real variable before but couldn't figure out how to get it to check for the %s.

I know it will need an If/Then/Else action; which condition/action would get it to check the %/change the value?
And will I need the Integer to start at 0 or 100?

I tried this, wondering if it will work-
If Mining equal to (Random integer between 1 and 47) then do (Item- Create Crystal at (Position of (Triggering unit))) else do (Do Nothing)? Thanks!
 
Level 5
Joined
Oct 27, 2007
Messages
158
I want to make a chance system for my game for a job in it (Mining).
Is there any way to make a chance system where there's a ##%/100% chance of getting something? (Ex- 47%/100%, 1%/100%,etc)
I want it to be able to randomly choose an item but have some items rarer than others, such as a regular crystal being easier to find than a diamond, for example. I think I've got the system of using the mining pick right (Unit uses an item, Conditions are that item being manipulated is a Mining Pick and in the Mining Area) but now I just need the actions for the chance system. And I have no idea how to use JASS eaither so don't recomend JASS triggers to me :sad:.
Thanks in advance


You can also make an item pool and attach weight to an item. Weight is the chance the item will be picked from the pool. Item pools are the easy solution. The other one is doing it with a chance algorithm, like the one that's already mentioned.

You don't need to use percentages. You calculate the chance. So for example 100% is 1. A chance of .01 means the item will be picked 1 out of a 100 picks. .02 is a chance of 1 out of 50 picks.
 
Level 9
Joined
Oct 17, 2007
Messages
547
An easy way to do it without variables would be using a similar condition to this:

(Random integer number between 1 and 100) Less than or equal to 30

For 30% chance of doing something.
 
Level 3
Joined
May 22, 2007
Messages
30
I think I got it. I used the Set Variable trigger to do this:
Set Mining to (Random Integer between 1 and 100) It does this everytime a unit uses the mining item.
Next I have triggers that read If (Mining greater than or equal to ##) and (Mining less than ##)) then do (Item- Create Crystal at (Position of (Triggering Unit)) else do (Do Nothing).
So if Mining was set to Greater than/equal to 41 and Less than/equal to 61 it would create an Emerald if it landed between those numbers for example.
Would that work? :bored:
 
Level 5
Joined
Oct 27, 2007
Messages
158
I think I got it. I used the Set Variable trigger to do this:
Set Mining to (Random Integer between 1 and 100) It does this everytime a unit uses the mining item.
Next I have triggers that read If (Mining greater than or equal to ##) and (Mining less than ##)) then do (Item- Create Crystal at (Position of (Triggering Unit)) else do (Do Nothing).
So if Mining was set to Greater than/equal to 41 and Less than/equal to 61 it would create an Emerald if it landed between those numbers for example.
Would that work? :bored:


Yes that works. That means a miner has a 1 in 5 chance of getting an Emerald. You could do the same by just checking if the mine chance is less or equal to 20
 
Level 3
Joined
May 22, 2007
Messages
30
Yeah just tried it and it works. Thanks all :grin:
The reason it was 41 to 61 was because the most common gem, quartz, is already set for 1-40. Just used emerald, next on the list, for the example. All it would do to check to quartz is Less than/equal to 40, but I wanted to try in between 2 numbers.
 
Level 5
Joined
Oct 27, 2007
Messages
158
Yeah just tried it and it works. Thanks all :grin:
The reason it was 41 to 61 was because the most common gem, quartz, is already set for 1-40. Just used emerald, next on the list, for the example. All it would do to check to quartz is Less than/equal to 40, but I wanted to try in between 2 numbers.

That's why you evaluate the chance for the item that has the least chance of being mined first.

if mining <= 20 then
elseif mining <= 40 then
etc.
 
Status
Not open for further replies.
Top