Solved How To Create A Chance Code In Batch/Script File

March 8, 2017 at 21:23:48
Specs: Windows 10
Hello! I am creating a batch file RPG game and I'm trying to figure out how to create a "Chance" batch code.

Purpose:

Character Level 1-15 has 80% chance of forging a Bronze Bar successfully.

Character Level 16-30 has 50% chance of forging an Iron Bar successfully.

etc....

Need to figure this out ASAP.


See More: How To Create A Chance Code In Batch/Script File

Report •

#1
March 8, 2017 at 22:58:12
Not obvious what you want

=====================

M2 Get custom script or take private lessons


Report •

#2
March 9, 2017 at 13:10:36
✔ Best Answer
Get a random number that ranges between 0 and 100 (could be any number, but 100 is easier because percentages)
set /a chance=%random% %% 101

Then do some logic to decide whether the forge should be a success or not
if %level% LEQ 15 (
        if %chance% LSS 80 (
                echo forge successful
        ) else (
                echo forge failed
        )
) else (
        if %level% LEQ 30 (
                if %chance% LSS 50 (
                        echo forge successful
                ) else (
                        echo forge failed
                )
        )
)

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)


Report •

#3
March 9, 2017 at 13:36:56
Thank you so much! This is exactly what I needed!

Report •
Related Solutions


Ask Question