AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How can I check that? (https://forums.alliedmods.net/showthread.php?t=316984)

EFFx 06-20-2019 14:41

How can I check that?
 
How can I check if a number is approximately equal to the other? I've been searching for 2 days and I didn't find any post that could help me, so either i'm blind or there aren't much topics about that.
I thought about (Z - Y) < 5 but I don't think it's the best way to do that... maybe.

HamletEagle 06-20-2019 15:29

Re: How can I check that?
 
Unless I misunderstand what you mean by "approximately equal", then (Z - Y) < 5 is exactly what you should be doing.

edon1337 06-20-2019 16:03

Re: How can I check that?
 
Quote:

Originally Posted by HamletEagle (Post 2656127)
Unless I misunderstand what you mean by "approximately equal", then (Z - Y) < 5 is exactly what you should be doing.

Approximately equal = almost the same

Someone correct me if I'm wrong but,
PHP Code:

5 Y 3 criteria : < 1

false
= -true 

I think he has to use abs() on X - Y before comparing it.

EFFx 06-20-2019 16:46

Re: How can I check that?
 
Seems that my first idea was correct then, but I think I should make something more "universal". Like: If X value is 90% of the Y value is better, isn't it?

Let's suppose that we have 100 as X and 95 as Y, then we've 95% of the main value, so it's kinda approximated, or is it the same idea as doing X - Y < 5?

OciXCrom 06-20-2019 16:52

Re: How can I check that?
 
Quote:

Originally Posted by EFFx (Post 2656139)
Seems that my first idea was correct then, but I think I should make something more "universal". Like: If X value is 90% of the Y value is better, isn't it?

Let's suppose that we have 100 as X and 95 as Y, then we've 95% of the main value, so it's kinda approximated, or is it the same idea as doing X - Y < 5?

5 - 3 is not the same as 50000 - 30000. Better use a percentage of your choice.

Natsheh 06-20-2019 17:33

Re: How can I check that?
 
What do you mean with the same ? Closer to each other?

Are you using floats ?

Then use floatround..


Can you explain what are you doing this for?

Also pick out a better title for your thing.


Edit : best thing is to use your first thing no need to overcomplicate a simple thing

Bugsy 06-20-2019 18:53

Re: How can I check that?
 
How about this?

This will check if iValueToCheck is >= fVariance percent of iCompareToValue.

PHP Code:

public plugin_init() 
{
    
server_print"Is 95 >= 90%% of 100? = %s" AlmostTheSame100 95 90.0 ) ? "Yes" "No" );
}

bool:AlmostTheSame( const iCompareToValue , const iValueToCheck Float:fVariance )
{
    return 
bool:( ( floatiValueToCheck ) / floatiCompareToValue ) * 100.0 ) >= fVariance );


Code:

Is 95 >= 90% of 100? = Yes

Is 88 >= 90% of 100? = No


EFFx 06-20-2019 21:39

Re: How can I check that?
 
Quote:

Originally Posted by Natsheh (Post 2656152)
What do you mean with the same ? Closer to each other?

Are you using floats ?

Then use floatround..


Can you explain what are you doing this for?

Also pick out a better title for your thing.


Edit : best thing is to use your first thing no need to overcomplicate a simple thing

I was trying to make a compass format which makes the directions in a 2D format "rotates" in the hud message, so I was calculing the direction I'm looking at and then add + 15 to the next ones, with that, I would show the hud like this:

v
76
15 30 NE 60 75 E 105 120 SE


So, I asked that because if i'm looking at the direction 76, the next ones will be 91, 106, 121, etc... so with the approximate value, I could change the 91 or 106 to 90 and 105, y'know?


Quote:

Originally Posted by Bugsy (Post 2656166)
How about this?

This will check if iValueToCheck is >= fVariance percent of iCompareToValue.

PHP Code:

public plugin_init() 
{
    
server_print"Is 95 >= 90%% of 100? = %s" AlmostTheSame100 95 90.0 ) ? "Yes" "No" );
}

bool:AlmostTheSame( const iCompareToValue , const iValueToCheck Float:fVariance )
{
    return 
bool:( ( floatiValueToCheck ) / floatiCompareToValue ) * 100.0 ) >= fVariance );


Code:

Is 95 >= 90% of 100? = Yes

Is 88 >= 90% of 100? = No


I will roger that.


Edit:


Worked, thank you guys, specially Bugsy.

klippy 06-21-2019 03:14

Re: How can I check that?
 
In that case you just should align your current angle to an increment of 15.
Code:

new const alignedAngle = (floatround(currentAngle + 7.5) / 15) * 15;
Then you can just add or sub 15 a couple of times to get 90, 105 etc.

And please set a proper title.

EFFx 06-23-2019 19:43

Re: How can I check that?
 
I'm not bumping, since I already solved it, I'm just answering KliPPy's reply:

That's what I'm doing:

PHP Code:

    iLocationNumber[0] = iCurrentAngle
    iLocationNumber
[1] = iLocationNumber[0] + 15
    iLocationNumber
[2] = iLocationNumber[1] + 15
    iLocationNumber
[3] = iLocationNumber[2] + 15
    iLocationNumber
[4] = iLocationNumber[3] + 15
    iLocationNumber
[5] = iLocationNumber[4] + 15
    iLocationNumber
[6] = iLocationNumber[5] + 15
    iLocationNumber
[7] = iLocationNumber[6] + 15
    iLocationNumber
[8] = iLocationNumber[7] + 15
    iLocationNumber
[9] = iLocationNumber[8] + 15 

Also, isn't your formula wrong? Like, lets say that currentAngle is 175, so it'll be:

floatround(175.0 + 7.5) = 182.0
182.0 / 15 = 12.13
12.13 * 15 = 182.0 ??

Did I misunderstand it?


All times are GMT -4. The time now is 04:18.

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