Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Specific Random Numbers [dbpro]

Author
Message
Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 22nd Feb 2006 05:22
In my RPG battle engine, I want there to be an Accurary stat and the higher the Accuracy, the greater the chance of an attack hitting. I am trying to make it random so that the user does not know exactly what's going to happen, but not too random to the point where the user doesn't have a clue.

I was thinking of making a function for attacking and at the beginning, have it check to see if the attack will hit by choosing between numbers (on a sort of PH base scale [1 -14] for laughs and gigles) that I define like so:

PSUEDO CODE:



this will be like a 2/4 or 50 % chance of hitting. theoretically, half the time the user will miss and half the time he will hit.

as experience grows, the amount of numbers above seven will grow



this will be like a 3/5 or 60% chance of hitting. theoretically, 40% of the time the user will miss and 60% of the time he will hit.

How would you guys go about choosing a random number between specific numbers that are previously defined that are not necessarily consecutive or chronological?
SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 22nd Feb 2006 08:34 Edited at: 22nd Feb 2006 08:43


Krimzon DestinE
19
Years of Service
User Offline
Joined: 18th Sep 2005
Location:
Posted: 22nd Feb 2006 16:01
duh, why didn't i think of that. thank you.
SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 23rd Feb 2006 00:03

[/url]

Steve Fash
21
Years of Service
User Offline
Joined: 31st Dec 2002
Location: Doncaster, UK
Posted: 25th Feb 2006 19:24 Edited at: 25th Feb 2006 19:26
Is there an easier way to get a random number between a start and end number, say 60 and 600, rather than the normal rnd command that starts at 0 (eg rnd (600)) or would a similar principle apply ? In blitz you could do rnd 60,600 which would do what I'm trying to achieve in dbp
thanks in advance

For game/demo music for YOUR PC productions visit:-www.futuredevelopments.org.uk
SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 25th Feb 2006 19:35
a=60+rnd(540)



Lame Brain
19
Years of Service
User Offline
Joined: 28th Apr 2005
Location: Portland, OR
Posted: 25th Feb 2006 19:41
How I would do this is a bit different I think. I would give the target a defense number(armor, dodging, whatever...) and the attacker a offense number (accuracy.)

Then you treat the offense number as the minimum of your random range, and the defense as your target.

Something like this:


that isn't actual code, but you get the idea. The attack is a random number between accuracy and the weapon's maximum accuracy, then you check to see if the result is greater than the target's defense.

Anyway, just how I do it.
If code = helpful then use code
if code <> helpful then ignore code



Another hair-brained idear from... LAME BRAIN!
Steve Fash
21
Years of Service
User Offline
Joined: 31st Dec 2002
Location: Doncaster, UK
Posted: 25th Feb 2006 19:44
quality, nice one mate....
I was doing the rnd then checking if it was less than 60 and if it was re-randomising it again....
doh!

For game/demo music for YOUR PC productions visit:-www.futuredevelopments.org.uk
SirFire
19
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 25th Feb 2006 20:55
You've almost got it...


Like that?

Me!
19
Years of Service
User Offline
Joined: 26th Jul 2005
Location:
Posted: 25th Feb 2006 20:58 Edited at: 25th Feb 2006 20:59
you can just make a simple function to do ranges, it`s the sort of thing that comes in handy and wastes time if keep typing it over and over (in other words it`s what functions where made for)

function random_range(a,b)
number=rnd(b-a)+a
endfunction number

then all you need to do is

a=random_range(30,200)

just make sure you put the numbers in the order from/to



Windows: 32 bit extension/graphical shell for a 16bit patch to an 8bit OS originally coded for a 4bit CPU, written by a 2bit company that can't stand 1bit of competition, now available in 64bits.

Login to post a reply

Server time is: 2024-09-24 17:34:11
Your offset time is: 2024-09-24 17:34:11