Raised This Month: $ Target: $400
 0% 

How to add comma ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GreenZombie
Junior Member
Join Date: Aug 2015
Old 08-05-2015 , 17:24   How to add comma ?
Reply With Quote #1

Hi, for example some zombie class have 4000 HP, i want to write 4,000
I try this - https://forums.alliedmods.net/showthread.php?t=267049 but not work... I copy this code:

PHP Code:
#include <amxmodx> 

new iMin = -2147483648
new 
iMax 2147483647

public 
plugin_init()  

    new 
szNum15 ]; 
     
    
AddCommasiMin szNum charsmaxszNum ) ); 
    
server_print"%d = %s" iMin szNum ); 
     
    
AddCommasiMax szNum charsmaxszNum ) ); 
    
server_print"%d = %s" iMax szNum ); 


public 
AddCommasiNum szOutput[] , iLen 

    new 
szTmp15 ] , iOutputPos iNumPos iNumLen
     
    if ( 
iNum 
    { 
        
szOutputiOutputPos++ ] = '-'
        
iNum absiNum ); 
    } 
     
    
iNumLen num_to_striNum szTmp charsmaxszTmp ) ); 

    if ( 
iNumLen <= 
    { 
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp ); 
    } 
    else 
    { 
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) )  
        { 
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ]; 
         
            if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) )  
                
szOutputiOutputPos++ ] = ','
        } 
         
        
szOutputiOutputPos ] = EOS
    } 
     
    return 
iOutputPos

and i created .sma file and i post this code in the .sma file after his i compiled the file, copy the .amxx file and paste .amxx file in folder :plugins" after this i write the .amxx file name in plugins.ini and not work
GreenZombie is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-05-2015 , 18:13   Re: How to add comma ?
Reply With Quote #2

I wrote that function. Show me how you're using it
__________________
Bugsy is offline
Old 10-17-2015, 07:14
Depresie
This message has been deleted by Depresie. Reason: pff
Nano x
Member
Join Date: Feb 2014
Location: Lebanon, beirut
Old 11-21-2015 , 14:34   Re: How to add comma ?
Reply With Quote #3

how can i add comma to this plugin
Attached Files
File Type: sma Get Plugin or Get Source (Health_Sniper.sma - 568 views - 1.1 KB)
Nano x is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 11-21-2015 , 15:34   Re: How to add comma ?
Reply With Quote #4

Quote:
Originally Posted by Nano x View Post
how can i add comma to this plugin
This is not your theead, wait for the answer for OP and you can do it with your plugin
redivcram is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2015 , 16:00   Re: How to add comma ?
Reply With Quote #5

It's already done for you. Look at the OP's code in plugin_init().

AddCommas( the number , the string , max chars ).

PHP Code:
new iNumber 100000;
new 
szNumberWithCommas15 ];
AddCommasiNumber szNumberWithCommas charsmaxszNumberWithCommas )
server_print"%d with commas is %s" iNumber szNumberWithCommas 
__________________

Last edited by Bugsy; 11-21-2015 at 16:02.
Bugsy is offline
Nano x
Member
Join Date: Feb 2014
Location: Lebanon, beirut
Old 11-21-2015 , 17:29   Re: How to add comma ?
Reply With Quote #6

but it is not working no comma, here is the original plugin
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <colorchat>
#include <zombie_plague_advance>

#define PLUGIN_NAME "[ZP] Sniper Health"
#define PLUGIN_VERS "1.0"
#define PLUGIN_AUTH "hi!"

#define TASK_HEALTH 1234554321


public plugin_init() 
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSPLUGIN_AUTH)

    
// Fwd's
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1)
    
RegisterHam(Ham_Killed"player""Fwd_PlayerKilled_Pre"0)
}

public 
Fwd_PlayerSpawn_Post(id)
{
    if (
task_exists(id+TASK_HEALTH))
        
remove_task(id+TASK_HEALTH)
}

public 
Fwd_PlayerKilled_Pre(victimattackershouldgib)
{
    if (
task_exists(victim+TASK_HEALTH))
        
remove_task(victim+TASK_HEALTH)
}

public 
zp_round_started(modeid)
{
    if (
mode != MODE_SNIPER)
        return
        
    if (!
zp_get_user_sniper(id))
        return
        
    
set_task(34.0"Task_ShowHealth"id+TASK_HEALTH__"b")

}

public 
Task_ShowHealth(id)
{
    
id -= TASK_HEALTH
    
    
if (!zp_get_user_sniper(id))
        
remove_task(id+TASK_HEALTH)
    
    
ColorChat(0GREY"^x04[ZP]^x01 A ^x03Rapture^x01 Reminder ^x03@^x01 ^x04Sniper^x01 still has ^3%d ^x04health points!^x01"get_user_health(id))


Nano x is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2015 , 17:31   Re: How to add comma ?
Reply With Quote #7

The function does not exist and is not called in that code
__________________
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 11-21-2015 , 17:32   Re: How to add comma ?
Reply With Quote #8

Post the code that you tried, not the original plugin (you already posted that one).
__________________
fysiks is offline
Nano x
Member
Join Date: Feb 2014
Location: Lebanon, beirut
Old 11-21-2015 , 17:46   Re: How to add comma ?
Reply With Quote #9

here is the one i have tried
PHP Code:
#include <amxmodx>
#include <hamsandwich>
#include <colorchat>
#include <zombie_plague_advance>

#define PLUGIN_NAME "[ZP] Sniper Health"
#define PLUGIN_VERS "1.0"
#define PLUGIN_AUTH "hi!"

#define TASK_HEALTH 1234554321

new iMin = -2147483648;
new 
iMax 2147483647;

public 
plugin_init() 
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSPLUGIN_AUTH)
         new 
szNum15 ];
    
         
AddCommasiMin szNum charsmaxszNum ) );
         
server_print"%d = %s" iMin szNum );
    
         
AddCommasiMax szNum charsmaxszNum ) );
         
server_print"%d = %s" iMax szNum );
    
    
// Fwd's
    
RegisterHam(Ham_Spawn"player""Fwd_PlayerSpawn_Post"1)
    
RegisterHam(Ham_Killed"player""Fwd_PlayerKilled_Pre"0)
}

public 
Fwd_PlayerSpawn_Post(id)
{
    if (
task_exists(id+TASK_HEALTH))
        
remove_task(id+TASK_HEALTH)
}

public 
Fwd_PlayerKilled_Pre(victimattackershouldgib)
{
    if (
task_exists(victim+TASK_HEALTH))
        
remove_task(victim+TASK_HEALTH)
}

public 
zp_round_started(modeid)
{
    if (
mode != MODE_SNIPER)
        return
        
    if (!
zp_get_user_sniper(id))
        return
        
    
set_task(34.0"Task_ShowHealth"id+TASK_HEALTH__"b")

}

public 
Task_ShowHealth(id)
{
    
id -= TASK_HEALTH
    
    
if (!zp_get_user_sniper(id))
        
remove_task(id+TASK_HEALTH)
    
    
ColorChat(0GREY"^x04[ZP]^x01 A ^x03Rapture^x01 Reminder ^x03@^x01 ^x04Sniper^x01 still has ^3%d ^x04health points!^x01"get_user_health(id))

}
public 
AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum absiNum );
    }
    
    
iNumLen num_to_striNum szTmp charsmaxszTmp ) );

    if ( 
iNumLen <= )
    {
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
        
            if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) 
                
szOutputiOutputPos++ ] = ',';
        }
        
        
szOutputiOutputPos ] = EOS;
    }
    
    return 
iOutputPos;

Nano x is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-21-2015 , 17:57   Re: How to add comma ?
Reply With Quote #10

The function definitely worked in the past, but now it's adding two negative signs and trimming off a number on the end. Did the functionality of abs() change or break? It should return the value from 0, but per func wiki:
Code:
Absolute value of x (x if it is greater than 0, -x otherwise).
Which means it essentially does nothing.

Edit: Ok, I was misreading this. -x = -(-1235) and will return a positive and the function is working. But, it does not work on the specific value being used in the test which is the lower boundary of what can be stored in a signed long -2147483648.

There should never be a negative value returned from abs().
Code:
In mathematics, the absolute value or modulus |x| of a real number x 
is the non-negative value of x without regard to its sign. Namely, |x| = x for a 
positive x, |x| = −x for a negative x (in which case −x is positive), and |0| = 0. 
For example, the absolute value of 3 is 3, and the absolute value of −3 is also 3. 
The absolute value of a number may be thought of as its distance from zero.
Use this:
PHP Code:
    
public AddCommasiNum szOutput[] , iLen )
{
    new 
szTmp17 ] , iOutputPos iNumPos iNumLen;
    
    
//if ( iNum < 0 )
    //{
    //    szOutput[ iOutputPos++ ] = '-';
    //    iNum = abs( iNum );
    //}
    
    
iNumLen num_to_striNum szTmp charsmaxszTmp ) );
    
    if ( 
iNumLen <= )
    {
        
iOutputPos += copyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) ) 
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            if( ( 
iNumLen iNumPos ) && !( ( iNumLen iNumPos ) % ) ) 
                
szOutputiOutputPos++ ] = ',';
        }
            
        
szOutputiOutputPos ] = EOS;
    }
    
    return 
iOutputPos;

__________________

Last edited by Bugsy; 11-22-2015 at 06:28.
Bugsy 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 22:36.


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