Challenge System For Ren'Py

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
ThePyromancer23
Newbie
Posts: 10
Joined: Thu Apr 11, 2019 10:42 am
Projects: GFHS
Contact:

Challenge System For Ren'Py

#1 Post 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!

User avatar
isak grozny
Regular
Posts: 46
Joined: Mon Apr 11, 2016 10:17 am
Projects: The Bitter Drop [Modern Fantasy][Gay Romance][BxB]
itch: grrozny
Location: Edinburgh, UK
Contact:

Re: Challenge System For Ren'Py

#2 Post 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()
.

ThePyromancer23
Newbie
Posts: 10
Joined: Thu Apr 11, 2019 10:42 am
Projects: GFHS
Contact:

Re: Challenge System For Ren'Py

#3 Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users