AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Negative Sign on Needed Amount (https://forums.alliedmods.net/showthread.php?t=133478)

infek 07-25-2010 20:34

Negative Sign on Needed Amount
 
This is really bothering me I have a XP Mod and Im trying to set up how much XP they need to get an item and this is how i have it set up and for some reason this damn negative sign shows up

PHP Code:

CvarHere register_cvar("blah""500" 

PHP Code:

new exp points[id]
new 
cost get_pcvar_numCvarHere )
new 
left exp cost;
 
if( 
exp cost )
{
    
ColorChatidGREEN"[%s]^x01 You need %i more XP to buy this item!"TITLEleft);
    return 
PLUGIN_HANDLED;
   }
  } 

Well heres what i mean This is what will show up
You need -200 more XP to buy this item, lets just say it cost 500 and i have 300 it says i need -200 more

GXLZPGX 07-25-2010 20:40

Re: Negative Sign on Needed Amount
 
Quote:

Originally Posted by infek (Post 1251482)
This is really bothering me I have a XP Mod and Im trying to set up how much XP they need to get an item and this is how i have it set up and for some reason this damn negative sign shows up

PHP Code:

CvarHere register_cvar("blah""500" 

PHP Code:

new exp points[id]
new 
cost get_pcvar_numCvarHere )
new 
left exp cost;
 
if( 
exp cost )
{
    
ColorChatidGREEN"[%s]^x01 You need %i more XP to buy this item!"TITLEleft);
    return 
PLUGIN_HANDLED;
   }
  } 

Well heres what i mean This is what will show up
You need -200 more XP to buy this item, lets just say it cost 500 and i have 300 it says i need -200 more

< is less than
> is greater than

Also, you want to allow them to buy it if their XP is equal to the cost.

So,

PHP Code:

if( exp cost 

->
PHP Code:

if( exp >= cost 


infek 07-25-2010 20:42

Re: Negative Sign on Needed Amount
 
Thanks, alot. I Already know < is less than but
PHP Code:

if( exp >= cost 
   {
    if( 
is_user_aliveid ) )
    {
     if( !
ItemUsed[id] )
     {
      
ColorChatidGREEN"[%s]^x01 You have purchased^x03 This item!"TITLE );
      
pointsid ] -= cost
      ItemUsed
[id] = true

other part
PHP Code:

   else if( exp cost )
   {
    
ColorChatidGREEN"[%s]^x01 You need %i more XP to buy This Item"TITLEleft);
    return 
PLUGIN_HANDLED;
   }
  } 

thats why i have exp < cost so if they have a less amount it'll show them they how much they need left the problem is it shows You need -Numberhere to buy this item

Bugsy 07-25-2010 22:58

Re: Negative Sign on Needed Amount
 
You made a simple mistake with your math, chief.

You should be using ( cost - exp ) to determine xp needed.

Example:

Cost = 500
Exp = 300

500 - 300 = 200

What you are doing:

Exp - cost

300 - 500 = -200

nikhilgupta345 07-25-2010 23:05

Re: Negative Sign on Needed Amount
 
Exactly bugsy. Lol, common sense, the only thing that would make it negative is the subtraction. Changing the > sign won't change the value of it, it would just change who it's showed to.

infek 07-25-2010 23:16

Re: Negative Sign on Needed Amount
 
holy, i didnt think of the subtraction. >_< Well thanks bugsys.


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

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