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

[FUNCTION] roundOff()

broken avatar :(
Created 9 years ago
by daedra descent
0 Members and 1 Guest are viewing this topic.
6,464 views
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
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
Code Snippet
Plaintext
/*
--SCRIPT DOC BEGIN--

Purpose: to round a uneven integer(int) to a even number based off of the given mod(mod) and using the provided middle integer(mid) to determine if the integer should be incremented positively or negatively.

Variables:
-int = Any number.
-mod = the modulus number to use.
-mid = the value to compare to determine if the function should add or subtract.

Example Usage:
iprintln(roundOff(375, 20, 10));

Example Usage Result:
360

--SCRIPT DOC END--
*/

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

while(int % mod != 0)
{
if(int % mod >= mid)
int++;
else
int--;
}
return int;
}
Credit me if used.
Last Edit: October 02, 2015, 10:32:53 pm by daedra descent
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 30 December 2012
Last active: 8 months ago
Posts
577
Respect
Forum Rank
Zombie Enslaver
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Signature
My preferred name is "xSanchez78".
Check me out here: www.steamcommunity.com/id/xSanchez78
×
alaurenc9's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
alaurenc9's Contact & Social LinksxSanchez78xSanchez78xSanchez78xSanchez78xSanchez78xSanchez78
cool. very simple, with script documentation just like treyarch's utility functions. can you teach me what the % symbol does again?
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
cool. very simple, with script documentation just like treyarch's utility functions. can you teach me what the % symbol does again?

Modulus? Its the remainder when dividing.

Code Snippet
Plaintext
13 %  10 = 3
broken avatar :(
×
broken avatar :(
Location: nlThe Netherlands
Date Registered: 23 November 2013
Last active: 2 years ago
Posts
331
Respect
Forum Rank
Perk Hacker
Primary Group
Donator ♥
My Groups
More
My Contact & Social Links
More
Personal Quote
Zombie Slayer Elite
×
Gabrielle's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Gabrielle's Contact & Social LinksTutorialZoneNL
cool. very simple, with script documentation just like treyarch's utility functions. can you teach me what the % symbol does again?

It returns the modulo of the division. So for example:

10 % 2 returns 0 (as 10/2=5, not a double/float but an integer)
9 % 2 returns 1 (as 9/2 returns a double/float, 8/2 doesn't. 9-8 = 1, so 1 is the answer)

19 % 4 returns 3 (as 19/4 returns a double/float, 16/4 doens't. 19-16=3, so 3 is the answer)

Bad explaination but it works this way. It'll check how much times the number after the % can be in the number before the %, and it'll return the rest (the number before the % minus the number of the last time the number after % could be inserted)
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 30 December 2012
Last active: 8 months ago
Posts
577
Respect
Forum Rank
Zombie Enslaver
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
×
alaurenc9's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
alaurenc9's Contact & Social LinksxSanchez78xSanchez78xSanchez78xSanchez78xSanchez78xSanchez78
Modulus? Its the remainder when dividing.

Code Snippet
Plaintext
13 %  10 = 3

OOOOOOOOOOOOOO that makes sense. thank you for telling me this.

It returns the modulo of the division. So for example:

10 % 2 returns 0 (as 10/2=5, not a double/float but an integer)
9 % 2 returns 1 (as 9/2 returns a double/float, 8/2 doesn't. 9-8 = 1, so 1 is the answer)

19 % 4 returns 3 (as 19/4 returns a double/float, 16/4 doens't. 19-16=3, so 3 is the answer)

Bad explaination but it works this way. It'll check how much times the number after the % can be in the number before the %, and it'll return the rest (the number before the % minus the number of the last time the number after % could be inserted)

yeah i get it. not really that bad of an explanation. thanks guys for teaching me this, ive been wondering for so long....
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
Modulus? Its the remainder when dividing.

Code Snippet
Plaintext
13 %  10 = 3
ive always thought that modulus (%) wasnt in GSC well now i know it is :D
broken avatar :(
×
broken avatar :(
[UGX] Documentation Writer & Programmer
Location: usLos Angeles, CA
Date Registered: 23 August 2013
Last active: 6 months ago
Posts
1,322
Respect
Forum Rank
Zombie Colossus
Primary Group
UGX Team Member
My Groups
More
My Contact & Social Links
More
Personal Quote
(ง º ω º )ง u wont sum m8y?
Signature
Do not take life too seriously. You will never get out of it alive.
×
DidUknowiPwn's Groups
UGX Team Member
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
Maybe should just cast the int as an actual int.

int = int(int);
10/10 variable names by the way.

(Just in case someone passes a double.)
broken avatar :(
×
broken avatar :(
RadihaX
Location: caCanada
Date Registered: 2 September 2012
Last active: 3 years ago
Posts
978
Respect
Forum Rank
The Decider
Primary Group
Community Mapper Elite
My Groups
More
My Contact & Social Links
More
Signature
Overrun
Lockdown
Overrun (Black Ops Mod)
Snowglobe
Leviathan
Abandoned School
Ski Resort
Leviathan Redux
×
JBird632's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
UGX V.I.P.
UGX V.I.P.
Community Mapper Elite Has shown excellence and experience in the area of custom mapping in the UGX-Mods community.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
JBird632's Contact & Social LinksJBird632JBird632JBird632JBird632JBird632Mapper
10/10 variable names by the way.
Haha ya, nothing like using keywords as your own variables.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Maybe should just cast the int as an actual int.

int = int(int);

I personally don't think its necessary to check for all input cases just so the function would work or return if the person couldn't be bothered to check the function args.

Quote
10/10 variable names by the way.

(Just in case someone passes a double.)

Well, it is meant to round off integers.

Haha ya, nothing like using keywords as your own variables.

To my knowledge, int is not a keyword in GSC. The reason its highlighted in the code box is probably because its set to highlight C language keywords, which GSC is based off of.
broken avatar :(
×
broken avatar :(
RadihaX
Location: caCanada
Date Registered: 2 September 2012
Last active: 3 years ago
Posts
978
Respect
Forum Rank
The Decider
Primary Group
Community Mapper Elite
My Groups
More
My Contact & Social Links
More
×
JBird632's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
UGX V.I.P.
UGX V.I.P.
Community Mapper Elite Has shown excellence and experience in the area of custom mapping in the UGX-Mods community.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
JBird632's Contact & Social LinksJBird632JBird632JBird632JBird632JBird632Mapper
To my knowledge, int is not a keyword in GSC. The reason its highlighted in the code box is probably because its set to highlight C language keywords, which GSC is based off of.
You would be correct, but it is still bad practice to do so.
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
You would be correct, but it is still bad practice to do so.

First off, what is consider 'bad practice'(aka Coding conventions) depends entirely on the language. GSC != C(or other languages) and therefor may not abide by the same 'practices'. Especially since GSC is so straightforward and doesn't even need you to declare what a variable type actually is before using it, which most languages require.

Secondly, with Leviathan released in the state that it was, like if conditions using undefined variables, who are you to question what is or isn't 'good practice'? And don't even try to say running code on undefined variables is OK in any shape or form. World at War in developer mode practically screams 'YOU SHOULDN'T BE RUNNING CODE ON UNDEFINED VARIABLES' every other developer error on Leviathan.
broken avatar :(
×
broken avatar :(
RadihaX
Location: caCanada
Date Registered: 2 September 2012
Last active: 3 years ago
Posts
978
Respect
Forum Rank
The Decider
Primary Group
Community Mapper Elite
My Groups
More
My Contact & Social Links
More
×
JBird632's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
UGX V.I.P.
UGX V.I.P.
Community Mapper Elite Has shown excellence and experience in the area of custom mapping in the UGX-Mods community.
Community Scripter Elite Has shown excellence and experience in the area of custom scripting in the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
JBird632's Contact & Social LinksJBird632JBird632JBird632JBird632JBird632Mapper
Woah dude, why are you attacking Leviathan? Why would you run it in developer mode in the first place? I couldn't care less what happens in developer mode as long as it runs fine for everyone - besides Awesome Pieman did the majority of scripting for Leviathan and he doesn't know proper scripting practices since he is self taught.

I would also like to counter your argument with why would Treyarch allow you to use undefined variables in the first place (ie the isDefined function, which is quite handy) without them actually working.
Last Edit: October 04, 2015, 06:07:55 am by JBird632
broken avatar :(
×
broken avatar :(
☭ Soviet Commander ☭
Location: us
Date Registered: 13 August 2012
Last active: 8 years ago
Posts
2,790
Respect
Forum Rank
King of the Zombies
Primary Group
Community Daedra
My Groups
More
My Contact & Social Links
More
×
daedra descent's Groups
Community Daedra
Community Daedra
daedra descent's Contact & Social LinksBlueSoviet
Woah dude, why are you attacking Leviathan?

Because its a good example(or the scripts it uses rather).

Quote
I couldn't care less what happens in developer mode as long as it runs fine for everyone

My car makes a bunch of funny noises but it runs!

Alright that was a bit dickheadish, but really just because you are given the option to ignore script screwups doesn't mean you should. While many of World at War's developer errors might seem trivial, they do matter. For instance, if for whatever reason, a function isn't able to delete the zombie's glowing eye model thing because the way the code tried to get the model returned undefined, developer WILL point that out.

Quote
e - besides Awesome Pieman did the majority of scripting for Leviathan and he doesn't know proper scripting practices since he is self taught.

So was i. When i started out i didn't even know what a integer, boolean, double, etc was let alone running code on specific players but eventually i learned about developer which made debugging almost painless(in SP anyway).

Quote
I would also like to counter your argument with why would Treyarch allow you to use undefined variables in the first place (ie the isDefined function, which is quite handy) without them actually working.

If i had to guess it was due to keeping the language as simple and straightforward as possible.
broken avatar :(
×
broken avatar :(
OnionmanVere Bo21
Location: ieu dnt wnt 2 no
Date Registered: 27 September 2013
Last active: 1 year ago
Posts
1,864
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Mapper
My Groups
More
Personal Quote
ok
Signature
Aye mate you don't know me so y don't you shut tf up ok buddy :)

×
Scobalula's Groups
Donator ♥ Benevolent Soul who has our eternal gratitude and exclusive access to betas and the donator section of the forum.
Box Mappers Elite
Box Mappers Elite
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
Scobalula's Contact & Social Links
Only recently found out about modulus in JS while learning it, didn't know you could use it in GSC, cool none the less, I know I some people will have good use for this.

 
Loading ...