Raised This Month: $ Target: $400
 0% 

Math Equation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-01-2015 , 22:12   Re: Math Equation
Reply With Quote #1

Quote:
Originally Posted by jimaway View Post
earnedpoints = maxjumps / jumpsmade * maxpoints
if (earnedpoints > maxpoints) earnedpoints = maxpoints
if (earnedpoints < 1) earnedpoints = 1
This does not work for me, did you test this?

I made an attempt and I think it gives what you want:
PHP Code:
#include <amxmodx>

public plugin_init() 
{
    const 
MinPoints 1;
    const 
MaxPoints 20;
    const 
MaxJumps 4;
    
    new 
earnedPoints;
    
    for ( new 
iJumps iJumps <= 20 iJumps++ )
    {
        
earnedPoints clampfloatround( ( float( ( MaxJumps ) - iJumps ) / MaxJumps ) * floatMaxPoints ) ) , MinPoints MaxPoints );
        
server_print"%d Jumps = %d points" iJumps earnedPoints );
    }

Output
Code:
1 Jumps = 20 points
2 Jumps = 20 points
3 Jumps = 20 points
4 Jumps = 20 points
5 Jumps = 18 points
6 Jumps = 15 points
7 Jumps = 13 points
8 Jumps = 10 points
9 Jumps = 8 points
10 Jumps = 5 points
11 Jumps = 3 points
12 Jumps = 1 points
13 Jumps = 1 points
14 Jumps = 1 points
15 Jumps = 1 points
16 Jumps = 1 points
17 Jumps = 1 points
18 Jumps = 1 points
19 Jumps = 1 points
20 Jumps = 1 points
What jimaway posted:
PHP Code:
#include <amxmodx>

public plugin_init() 
{
    const 
MinPoints 1;
    const 
MaxPoints 20;
    const 
MaxJumps 4;
    
    new 
earnedPoints;
    
    for ( new 
iJumps iJumps <= 20 iJumps++ )
    {
        
earnedPoints clampMaxJumps iJumps MaxPoints MinPoints MaxPoints );
        
server_print"%d Jumps = %d points" iJumps earnedPoints );
    }

Output
Code:
1 Jumps = 20 points
2 Jumps = 20 points
3 Jumps = 20 points
4 Jumps = 20 points
5 Jumps = 1 points
6 Jumps = 1 points
7 Jumps = 1 points
8 Jumps = 1 points
9 Jumps = 1 points
10 Jumps = 1 points
11 Jumps = 1 points
12 Jumps = 1 points
13 Jumps = 1 points
14 Jumps = 1 points
15 Jumps = 1 points
16 Jumps = 1 points
17 Jumps = 1 points
18 Jumps = 1 points
19 Jumps = 1 points
20 Jumps = 1 points
__________________
Bugsy is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 12-02-2015 , 00:30   Re: Math Equation
Reply With Quote #2

It works, but you have to turn them into floats like you did in your method. But hey the more methods the better.

Quote:
Originally Posted by ot_207 View Post
When you use 50 and 100 simply without dots the compiler uses them as integers.

So basically when you do this
50/100 you will do a integer division and the result will be 0
To fix the float problem you need all the numbers to have dots in order to count as floats.
In your situation the code should be:

(50.0/100.0)*100.0
PartialCloning is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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