kn4tseb
Master
Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0
|
RE: How to compare random values
i know what you mean Extreme, its almost like that but you said it yourself, it could take infinite loops till it gets true so loop stops.... xD
what about this
local.total 15
EDITED
never mind, wont work xddd
what i want knowing this is that i could apply it to gold, damage, and multiple systems so there would be an equality distribution of something depending on chance.
(This post was last modified: 06-18-2014 07:56 AM by kn4tseb.)
|
|
06-18-2014 07:51 AM |
|
|
Extreme
Grandmaster Poster
Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20
SphereCommunity
|
RE: How to compare random values
Well, in my opinion, you have to specify better the things, both players A, B and C are equals?
If yes, my code is the right thing to use, even it make you freeze.
If A is better and it have more chance or something else, it can have first try...
You can try this:
PHP Code:
LOCAL.A <R1,20> IF <dLOCAL.A> < 20 DORAND 2 BEGIN LOCAL.B <R1,<EVAL 20-<dLOCAL.A>>> LOCAL.C <EVAL 20-<dLOCAL.A>-<dLOCAL.B>> END BEGIN LOCAL.C <R1,<EVAL 20-<dLOCAL.A>>> LOCAL.B <EVAL 20-<dLOCAL.A>-<dLOCAL.C>> END ENDDO ENDIF
STEPS BEFORE CREATE A THREAD
- Check the revisions log;
- Use the search button and use the keywords of your problem;
- Check the WIKI;
- Create a thread.
(This post was last modified: 06-18-2014 08:02 AM by Extreme.)
|
|
06-18-2014 07:59 AM |
|
The following 1 user Likes Extreme's post:1 user Likes Extreme's post
kn4tseb (06-18-2014)
|
Skul
Master
Posts: 413
Likes Given: 0
Likes Received: 19 in 15 posts
Joined: Jun 2012
Reputation: 9
|
RE: How to compare random values
local.total can work, let's say you're using this on an npc to divvy gold at death, here's an example:
Code:
on=@death
local.total=<eval {1 15}> //example amount
if (<attackers>)
local.divvy=<eval <local.total> /<local.attackers>> //divvy between all attackers
for x 0 <eval <attackers> +-1>
uid.<attacker.<local.x>.uid>.newgold <local.divvy> //give divided gold to the attacker
endfor
endif
This event would be placed on the monster, or all monsters, however u choose to use it.
"I ask a question to the answer I already know."
Marchadium :: http://www.marchadium.ca/ :: Join us!
|
|
06-18-2014 08:00 AM |
|
|
kn4tseb
Master
Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0
|
RE: How to compare random values
one last thing,
<R20> returns a number between 0 and 19?
what about rand(20)? it is the same?
what if i want a number between 0 and 20
<r0,20>??
EDIT:
well here it is in case in the future someone as new as me needs it
a + b + c + d + e = 20
local.a <eval 20-<r0,20>>
local.b <eval <r0,<eval 20-<local.a>>>>
local.c <eval <r0,<eval 20-<local.a>+<local.b>>>>
local.d <eval <r0,<eval 20-<local.a>+<local.b>+<local.c>>>>
local.e <eval 20-<eval <local.a>+<local.b>+<local.c>+<local.d>>>
(This post was last modified: 06-18-2014 09:50 AM by kn4tseb.)
|
|
06-18-2014 09:12 AM |
|
|
XuN
Sphere Developer
Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30
|
RE: How to compare random values
<R20> returns a random number between 1 and 20 (a total of 20 possibilities), <r0,20> returns a random number between 0 and 20 (21 numbers in total).
BTW, now that you realised to do it, and learned in the proccess i'll show you a function I had for this:
Code:
[function GetRandomsFromTotal] //GetRandomsFromTotal 5,100 returns 5 random* numbers wich sum 100. The random is calculated this way: BaseNum=(100/5), Result=RAND(BaseNum - argv[0],Basenum + argv[0])
local.amount=<argv[0]>
local.total=<argv[1]>
local.max=<qval (<isempty <argv[2]>>==0)?<argv[2]>:<eval (<argv[1]>/<argv[0]>)+<argv[0]>>>
local.min=<qval (<isempty <argv[3]>>==0)?<argv[3]>:<eval (<argv[1]>/<argv[0]>)-<argv[0]>>>
if (<local.min><0)
local.min=0
endif
local.res=0
for 1 <local.amount> // Here the results are created, nothing is checked so all of then can be the max <local.max> or the min... shit happens?
local.ret_<dlocal._for>=<r<local.min>,<local.max>>
local.res +=<local.ret_<dlocal._for>>
endfor
local.pointer=1
while <local.res>><local.total> // So this is a check preventing the total result being higher than <argv[1]> and any result to be lower than <local.min>
if (<local.ret_<dlocal.pointer>>><local.min>)
local.ret_<dlocal.pointer> -=1
local.res --
endif
local.pointer ++ // local.pointer is just going throught all the results decreasing (in this case) or increasing (in the next while) all the values by 1 until the requirements are done.
if (<local.pointer>><local.amount>)
local.pointer=1
endif
endwhile
while <local.res><<local.total> // and this one prevents anyone being lower than <argv[1]>
if (<local.ret_<dlocal.pointer>><<local.max>)
local.ret_<dlocal.pointer> +=1
local.res ++
endif
local.pointer ++
if (<local.pointer>><local.amount>)
local.pointer=1
endif
endwhile
//so with these 2 whiles Sphere ensured that all the values does sum the total of <argv[1]> we create the return value.
local.ret=0 //first value will be a 0 so we don't check in every for loop if the local is empty to create it or not.
for 1 <local.amount>
local.ret=<local.ret>,<dlocal.ret_<dlocal._for>>
endfor
return <streat <local.ret>> // so here we remove the first value (the 0) and return the rest.
This will return the values separated with commas, ie: local.res=<GetRandomsFromTotal 5,20> will return a total of 5 random values which, in total, do not pass from 20. It also applies some logic to the calcs... numbers have a minimum value and a maximum value: in this case min value would be (20/5)-5=-1 and it will be fixed to 0 if that happens, the max would be (20/5)+5=9. This is done to create values between some certain range that let Sphere do its calcs easier. It won't be nice if the first random is 20 and the rest have to be 0 IMO.
(This post was last modified: 06-18-2014 07:28 PM by XuN.)
|
|
06-18-2014 07:19 PM |
|
The following 1 user Likes XuN's post:1 user Likes XuN's post
kn4tseb (06-19-2014)
|