Welcome, Guest. Please login or register.
Did you miss your activation email?
June 19, 2021, 08:14:15 pm

Login with username, password and session length
Search:     Advanced search
Savage: XR is a new patch for Savage, created by the Newerth.com staff. The XR1.1 Client is out now! Download it now!
190089 Posts in 11011 Topics by 18603 Members
Latest Member: AppleQ
* Home Forum Wiki Help Search Login Register
+  Newerth Forums
|-+  Savage XR
| |-+  Mapping & Modding Forum
| | |-+  SOLVED by Stringer: Script and Mathematic possibility
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Go Down Print
Author Topic: SOLVED by Stringer: Script and Mathematic possibility  (Read 3042 times)
phoenix-3000
Sr. Member
****
Posts: 335



View Profile
« on: October 19, 2013, 08:40:40 am »

...
« Last Edit: March 22, 2014, 05:47:09 pm by phoenix-3000 » Logged

The spirit of the law is more important than the letter of the law.
L'esprit de la loi, est plus important que la lettre de la loi
Stringer
The guy who doesn't know anything
Newerth Council
Full Member
*
Posts: 125



View Profile
« Reply #1 on: October 19, 2013, 10:16:41 am »

What you are searching for is accessible in form of

> set userVar [expression]

for example:
> set userVar1 10
> set userVar2 20
> set userVar3 [userVar1 + userVar2 + 12]
userVar3 will be "42"

Expression is an arithmetic expression containing numbers, variables and some predefined functions.
Note, that you don't have to use "#" symbols inside [], the variables will be recognized automatically.

Operations that are supported (ones that I know of):

Arithmetic operations:
Add: [a + b]
Multiply: [a * b]
Raiser To Power: [a ^ b]
Subtract: [a - b]
Divide: [a / b]
Modulo Division (MOD): [a % b]

Built-in functions:
abs(x): absolute value, makes a number positive: [abs(-10)] = 10
round(x): rounding operation, rounds a floating value to nearest integer: [round(10.4)] = 10
sqrt(x): square root of x: [sqrt(16)] = 4
rand: random number: [rand] = random floating number between 1 and 0. The number is different each time you call it.

Boolean expressions, the value is "1" if condition is true, "0" otherwise:
[a < b] - A less than B
[a > b] - A more than B
[a <= b] - A less or equal B
[a >= b] - A more or equal B
[a == b] - A equal B
[a != b] - A not equal B
[a && b] - both A and B are non-zero
[a || b] - at least one of A and B is non-zero

The result of a boolean expression can be used in "if" command;

To answer some of your requirements:

to subtract numbers in such way that result is positive or zero:
> if [(A - B) > 0] set userVar [A - B]; else set userVar 0;

to get an integer result of division:
> set userVar [round(a / b)];

to get a random integer number between 0 and 100:
> set userVar [round(rand * 100)]
(that's not uniformly random, because "0" and "100" will appear twice less often than other numbers, but it's good enough)

I suspect, that there can be more built-in functions and/or operations, but I don't know them.
« Last Edit: October 19, 2013, 10:30:41 am by Stringer » Logged

Be wise
Precious
Sr. Member
****
Posts: 272



View Profile
« Reply #2 on: October 20, 2013, 01:05:08 am »

wtf...
Logged


OW YEAH BABY LETS SHAKE THAT THING CMON !!!
phoenix-3000
Sr. Member
****
Posts: 335



View Profile
« Reply #3 on: October 20, 2013, 06:22:12 am »

Tanks  Wink
« Last Edit: May 06, 2014, 06:19:03 am by phoenix-3000 » Logged

The spirit of the law is more important than the letter of the law.
L'esprit de la loi, est plus important que la lettre de la loi
Trigardon
Forum Administrator
Legendary Member
****
Posts: 4830


Demonic Monster


View Profile WWW
« Reply #4 on: October 21, 2013, 10:05:59 pm »

I have no idea what you want to do...
Logged

phoenix-3000
Sr. Member
****
Posts: 335



View Profile
« Reply #5 on: October 22, 2013, 09:26:04 am »

...
« Last Edit: March 22, 2014, 05:46:46 pm by phoenix-3000 » Logged

The spirit of the law is more important than the letter of the law.
L'esprit de la loi, est plus important que la lettre de la loi
Pages: [1] Go Up Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2007, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.029 seconds with 20 queries.