The following warnings occurred:
Warning [2] Use of undefined constant SAPI_NAME - assumed 'SAPI_NAME' (this will throw an Error in a future version of PHP) - Line: 3388 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3388 errorHandler->error
/showthread.php 116 build_archive_link
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/inc/functions.php 3324 build_forum_breadcrumb
/showthread.php 195 build_forum_breadcrumb
Warning [2] Use of undefined constant IN_ARCHIVE - assumed 'IN_ARCHIVE' (this will throw an Error in a future version of PHP) - Line: 3331 - File: inc/functions.php PHP 7.4.33-nmm7 (Linux)
File Line Function
/inc/functions.php 3331 errorHandler->error
/showthread.php 195 build_forum_breadcrumb






Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare random values
Author Message
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #11
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 Confused

Confused
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
Find all posts by this user Like Post Quote this message in a reply
Extreme
Grandmaster Poster
***

Posts: 1,141
Likes Given: 217
Likes Received: 90 in 77 posts
Joined: May 2012
Reputation: 20

SphereCommunity

Post: #12
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.<R1,20>
IF <
dLOCAL.A> < 20
 DORAND 2
 BEGIN
  LOCAL
.<R1,<EVAL 20-<dLOCAL.A>>>
  
LOCAL.<EVAL 20-<dLOCAL.A>-<dLOCAL.B>>
 
END
 BEGIN
  LOCAL
.<R1,<EVAL 20-<dLOCAL.A>>>
  
LOCAL.<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
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Extreme's post
Skul
Master
**

Posts: 413
Likes Given: 0
Likes Received: 19 in 15 posts
Joined: Jun 2012
Reputation: 9



Post: #13
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
Visit this user's website Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #14
RE: How to compare random values
What about this xDDD

local.a <eval 20-<r20>>

local.b <eval <r(20-<local.a>)>>

local.c <eval <20-(<local.a>+<local.b>)>>

//local.d <eval <20-(<local.a>+<local.b>+<local.c>)>>

i will try what You guys say now... i got so confused with those evals xddd
(This post was last modified: 06-18-2014 08:12 AM by kn4tseb.)
06-18-2014 08:08 AM
Find all posts by this user Like Post Quote this message in a reply
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #15
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 Smile

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
Find all posts by this user Like Post Quote this message in a reply
XuN
Sphere Developer
*****

Posts: 852
Likes Given: 102
Likes Received: 156 in 119 posts
Joined: Jul 2013
Reputation: 30



Post: #16
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
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes XuN's post
Coruja
Sphere Developer
*****

Posts: 987
Likes Given: 5
Likes Received: 226 in 187 posts
Joined: Jul 2012
Reputation: 7

Dimension Shard

Post: #17
RE: How to compare random values
Code:
REF1=<char1>
REF2=<char2>
REF3=<char3>
REF4=<char4>
REF5=<char5>
FOR 20
  LOCAL.Gold<R1,5> ++
  //If this line doesn't work, try using this workaround:
  //LOCAL.N=<R1,5>
  //LOCAL.Gold<dLOCAL.N> = <eval <LOCAL.Gold<dLOCAL.N>>+1>
ENDFOR
FOR 1 5
  REF<LOCAL._FOR>.NEWGOLD <LOCAL.Gold<dLOCAL._FOR>>
ENDFOR
just set all chars that will receive the gold on REF[x] and then start giving 1gp to random chars until it reach 20gp
(This post was last modified: 06-19-2014 12:50 AM by Coruja.)
06-19-2014 12:49 AM
Find all posts by this user Like Post Quote this message in a reply
[+] 1 user Likes Coruja's post
kn4tseb
Master
**

Posts: 392
Likes Given: 45
Likes Received: 10 in 10 posts
Joined: May 2014
Reputation: 0



Post: #18
RE: How to compare random values
wow, okey, thank you very much!!!!
(This post was last modified: 06-19-2014 01:40 PM by kn4tseb.)
06-19-2014 01:33 PM
Find all posts by this user Like Post Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)