![]() |
Random function - Printable Version +- SphereCommunity (https://forum.spherecommunity.net) +-- Forum: Sphere 0.56d (/Forum-Sphere-0-56d) +--- Forum: Script Help (/Forum-Script-Help) +--- Thread: Random function (/Thread-Random-function) |
Random function - Lazarus - 07-11-2012 05:49 AM Hi! First: Sry for my english. Me and my developer are doing some new special moves. I've do ALL, the script works but I need a help in the random. I want to hit someting when I have 100 fencing and do a random of 10 [10% chance] and i want to change everytime i need. It's in a IF. I have this and I should work IF ((<FENCING> =100.0) && (RAND(10)=1) RAND(10)=1 IS RLY 10%? RAND(2)=1 IS 50%? It's okay the IF? what do you exchange in? what function I can use for RANDOM's? rly thanks ^_^ RE: Random function - RanXerox - 07-11-2012 06:14 AM Comparisons for equality require two equal signs. RE: Random function - darksun84 - 07-11-2012 07:07 AM IF ((<FENCING> == 100.0) && (<EVAL RAND(10)> == 1) The rightmost statement can be written in this way : (<R(10)> == 1) So you can skip to write "eval" before random everytime! RE: Random function - Lazarus - 07-11-2012 07:24 AM (07-11-2012 06:14 AM)RanXerox Wrote: Comparisons for equality require two equal signs. That's sure? I can use 1 only and works too ^_^ in all my scripts. A friend that's studing programation tells me that and works fine because Sphere it's a old system... o.o thanks ^_ ^ Thanks darksun! i'll try the R(10) ^_^ RE: Random function - RanXerox - 07-11-2012 07:44 AM Regarding the single versus double equal sign... If you don't want to follow my advice and script properly then feel free to ignore my advice. Following the advice of people who do not know sphere programming seems foolish. R(10) produces a random number between 0 and 10 does it not? In which case a single match is more like 9%... to be certain you can do <R1,10> RE: Random function - Anarch Cassius - 07-11-2012 07:45 AM "A friend that's studing programation tells me that and works fine because Sphere it's a old system... o.o" Yeah, most of the time. Point is its not a habit you want to get in to. RE: Random function - darksun84 - 07-11-2012 07:47 AM http://wiki.sphere.torfo.org/index.php/Common_Mistakes ![]() RE: Random function - Extreme - 07-11-2012 09:38 AM Rand(10) can be 0 1 2 3 4 5 6 7 8 9 10 Rand(2) can be 0 1 2 <R10> = Rand(10) But <R1,10> can be 1 2 3 4 5 6 7 8 9 10 RE: Random function - Lazarus - 07-11-2012 12:39 PM (07-11-2012 07:07 AM)darksun84 Wrote: IF ((<FENCING> == 100.0) && (<EVAL RAND(10)> == 1) What is the EVAL used for? Ok Extreme, Rand(9) = 1 it's 10% chance, rly? ![]() Thanks to all! ; ![]() RE: Random function - Extreme - 07-11-2012 01:05 PM EVAL works to make strings become numbers, calculations etc... Like this: Code: LOCAL.EXP += <EVAL (<FAME>*10)/100> // It will ADD 10% of the FAME to LOCAL.EXP If you try Code: IF RAND(10) == 1 // Wrong, will not work. Code: IF STRLEN(<SRC.NAME>) // Wrong, will not work too. You should use <R1,10> instead <EVAL RAND(9)> Edit: use <R1,10> == 1 // 10% |