AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Higher cvar (https://forums.alliedmods.net/showthread.php?t=163576)

RuleBreaker 07-31-2011 18:40

Higher cvar
 
I have 3 cvars, how to see whitch one is higher?
here`s example what i want to do
new cvar1
new cvar2
new cvar3

if cvar1 == higher
function1
if cvar2 == higher
function2
if cvar3 == higher
function3
if cvar1, cvar2, cvar3 == 0
function4
if cvar1, cvar2 == higher
function5
......

You get it? :)

OvidiuS 07-31-2011 18:58

Re: Higher cvar
 
higher than what?

Hunter-Digital 07-31-2011 19:02

Re: Higher cvar
 
Why do you need this exacly ?

But to answer your question... if you want to know which cvar is higher:
Code:

new highestCvar = 0

if(cvar1 > cvar2 && cvar1 > cvar3)
    highestCvar = 1

else if(cvar2 > cvar1 && cvar2 > cvar3)
    highestCvar = 2

else if(cvar3 > cvar2 && cvar3 > cvar1)
    highestCvar = 3

... but I think there's a better way for it.

Or if you just want the highest value of the three cvars:
Code:

new highestValue = max(max(cvar1, cvar2), cvar3)
Quote:

Originally Posted by OvidiuS (Post 1522965)
higher than what?

Higher than themselves I guess, he's making a bad code example.

RuleBreaker 07-31-2011 19:17

Re: Higher cvar
 
I meant the highest :)
@hunter thanks, but how to make statment "if" if they`re all 0 and if there`s 2 equal?:)

Exolent[jNr] 07-31-2011 19:51

Re: Higher cvar
 
Code:
new values[/* how many cvars you have */] values[0] = get_pcvar_num(/* 1st cvar */) values[1] = get_pcvar_num(/* 2nd cvar */) // etc new highestIndex, highestVal = values[0] for(new i = 1, val, highestVal = values[0]; i < sizeof(values); i++) {     if((val = values[i]) > highestVal)     {         highestVal = val         highestIndex = i     } } switch(highestIndex) {     case 0: function1()     case 1: function2()     // etc. }


All times are GMT -4. The time now is 03:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.