UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

[Tutorial] Giving a player a random amount of points using roundOff()

broken avatar :(
Created 11 years ago
by daedra descent
0 Members and 1 Guest are viewing this topic.
2,059 views
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 10 years ago
Posts
2,789
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
Signature
Let's keep this thread on topic from here on in. -DBZ

+1 to off-topic reply -DBZ

lmao. Too funny.

Goliath Script Placer: http://ugx-mods.com/forum/index.php/topic,11234.msg125257/topicseen.html#new

"...Christ, people. Learn C, instead of just stringing random characters
together until it compiles (with warnings)..."

-Linus Torvalds
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
This tutorial will show you how to give a player a random amount of points using roundOff (avoiding the inaccurate HUD).

First thing you'l need is my roundOff() function here: http://ugx-mods.com/forum/index.php/topic,8679.0.html

I recommend pasting that in root/raw/maps/_utility.gsc, as it is a utility function, but you can just paste it in the bottom of whatever script your going to use it in(wouldn't recommend it though).

Next, copy this:

Code Snippet
Plaintext
<player> maps\_zombiemode_score::add_to_player_score(roundOff(randomIntRange(10, 2000), 10, 5));

to wherever you need it. Make sure to change <player> to whatever the script needs.

Finally, adjust the parameters of randomIntRange to return the random integer(number) that you want.



If the compressed version is too hard to read, you can also use this longer form:

Code Snippet
Plaintext
	int = randomIntRange(10, 4000);
int = roundOff(int, 10, 5)
maps\_zombiemode_score::add_to_player_score(int);



Want to verify that its working correctly? Use this version of the function to see what the original integer is and how its rounding:

Code Snippet
Plaintext
roundOff(int, mod, mid)
{
if(!isDefined(int) || !isDefined(mod) || !isDefined(mid))
return undefined;

while(int % mod != 0)
{
iprintln(int);
if(int % mod >= mid)
int++;
else
int--;
}
return int;
}

First integer it prints is the original that randomIntRange returns.

 
Loading ...