Page 1 of 1

Challenge System For Ren'Py

Posted: Thu Apr 11, 2019 10:52 am
by ThePyromancer23
This may be a really obvious type of thing for some people, but I have been lurking here for so long that I feel the need to actually contribute so this is something I came up with. This is based on the challenge system that StoryNexus uses, as I switched from that program to this one.

Code: Select all

    #Challenge variables
    srate = 0
    difscale = 0.60 
    success = 0
    r = 0
    sdisplay = 0

    #Challenge functions
    def chaldiff(stat, dif):
        global difscale
        global srate
        global sdisplay
        srate = (stat/dif) * difscale
        sdisplay = srate * 100
    def challenge(stat, dif):
        import random
        global difscale
        global srate
        global success
        global r
        r = random.random()
        srate = (stat/dif) * difscale
        if srate >= r:
            success = 1
        else:
            success = 0
It's super basic, but I find the formula used to work in many cases. If the value of your stat and the difficulty of the challenge are equal, you will have a difscale percent chance of succeeding. If that rate doesn't suit you, just change the difscale.

Here is a test/example of the functions in use:

Code: Select all

#Jump to this to check challenge difficulty and stuff.
init python:
    strength = 10
label challengetest:
    scene black
    $ chaldiff(strength, 10)
    "Make a strength check and see if you succeed.
    {color=#00ff00}You have a [sdisplay]%% chance to succeed.{/color}"
    menu:
        "Make check.":
            $ challenge(strength, 10)
            if success == 1:
                scene black
                "Success."
                "Info: srate = [srate], r = [r]."
                return
            else:
                scene black
                "Fail."
                "Info: srate = [srate], r = [r]."
                return
        "No.":
            return
Anyway, maybe someone will find good use out of this. Cheers!

Re: Challenge System For Ren'Py

Posted: Tue Apr 23, 2019 3:36 am
by isak grozny
Oh, excellent, I can make use of this!

Incidentally, you might want to use

Code: Select all

renpy.random.random()
instead of importing

Code: Select all

random.random()
.

Re: Challenge System For Ren'Py

Posted: Mon May 13, 2019 3:01 pm
by ThePyromancer23
isak grozny wrote: Tue Apr 23, 2019 3:36 am Oh, excellent, I can make use of this!

Incidentally, you might want to use

Code: Select all

renpy.random.random()
instead of importing

Code: Select all

random.random()
.
Glad you are able to use it! I had only been working on Renpy for a couple of weeks at that point, so I didn't realize Renpy.random was a thing. Thank you.