Raised This Month: $75 Target: $400
 18% 

Scripting Forum


Post New Thread Reply   
 
Thread Tools Display Modes
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 06:11   Re: Scripting Forum
Reply With Quote #21

need help adding comma separator between digits to number, displaying in chat

want chat to display player's points on infected death with comma after thousand, for instance:
stupid (10,222) got 1 point for killing infected
can't get 10222 number with comma
what doI do with this:
PrintToChat(i, "%s (%i) got point for killing Infected", Name, (ClientPoints[i] + CurrentPoints[i]));

was advised to go
http://forums.alliedmods.net/showpos...45&postcount=5
but that requires amxmod. what's the way for sourcemod?
mehelp is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-19-2011 , 10:55   Re: Scripting Forum
Reply With Quote #22

Quote:
Originally Posted by mehelp View Post
need help adding comma separator between digits to number, displaying in chat

want chat to display player's points on infected death with comma after thousand, for instance:
stupid (10,222) got 1 point for killing infected
can't get 10222 number with comma
what doI do with this:
PrintToChat(i, "%s (%i) got point for killing Infected", Name, (ClientPoints[i] + CurrentPoints[i]));

was advised to go
http://forums.alliedmods.net/showpos...45&postcount=5
but that requires amxmod. what's the way for sourcemod?
You really should post this as its own thread.

Having said that, here's a quick and completely untested port of the AddCommas function to SourceMod. SourceMod only has a float absolute value function, so I did a two's complement to swap the sign.

PHP Code:
stock AddCommasiNumString:szOutput[] , iLen )
{
    new 
String:szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum = ~iNum 1// Two's complement conversion
    
}
    
    
iNumLen IntToStringiNumszTmpsizeof(szTmp));
    
    if ( 
iNumLen <= )
    {
        
iOutputPos += strcopyszOutputiOutputPos ] , iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) )
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            if ( ( 
iNumLen iNumPos ) && !( (iNumLen iNumPos ) % ) )
            {
                
szOutputiOutputPos++ ] = ',';
            }
        }
        
        
szOutputiOutputPos ] = '\0';
    }
    
    return 
iOutputPos;

__________________
Am I back? Well, we'll see.
Powerlord is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 12:27   Re: Scripting Forum
Reply With Quote #23

Quote:
Originally Posted by Powerlord View Post
You really should post this as its own thread.

Having said that, here's a quick and completely untested port of the AddCommas function to SourceMod. SourceMod only has a float absolute value function, so I did a two's complement to swap the sign.
well, I kinda did post it as a thread at first, but occasionally at 'amxmod scripting help'. that was my first post and already turned out to be a spam, so didn't want to multiply threads.

thank you for your peace of code, it' just doesn't seem like I'm capable of inserting it properly to plugin). if I put it before the block, responsible for displaying client points on infected death, plugin compiles perfectly, but there's no effect - numbers are still displayed in gamechat with no comma between digits. and when I tried to put indicated code directly in the block , I couldn't compile a thing- got like undefined symbols.. pretty sure I'm doing something wrong)).
here's where I tried to insert it, but failed (peace of [L4D & L4D2] Custom Player Stats v1.4B105 by muukis, just attempting to adopt to how I'd like stats to be displayed):

PHP Code:
// Display common Infected scores to each player.

public Action:timer_ShowTimerScore(Handle:timerHandle:hndl)
{
    if (
StatsDisabled())
        return;

    new 
Mode GetConVarInt(cvar_AnnounceMode);
    
decl String:Name[MAX_LINE_WIDTH];
    
    new 
maxplayers GetMaxClients();
    for (new 
1<= maxplayersi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && !IsClientBot(i))
        {
            
// if (CurrentPoints[i] > GetConVarInt(cvar_MaxPoints))
            //     continue;
            
            
            
TimerPoints[i] = GetMedkitPointReductionScore(TimerPoints[i]);
            
            if (
TimerPoints[i] > && TimerKills[i] > 0)
            {
                if (
Mode == || Mode == 2)
                {
                    
GetClientName(iNamesizeof(Name));
                    
CPrintToChat(i"{blue}%s \x01(%i) got points for killing Infected"Name, (ClientPoints[i] + CurrentPoints[i]));
                }
                else if (
Mode == 3)
                {
                    
GetClientName(iNamesizeof(Name));
                    
StatsPrintToChatAll("\x05%s \x01has earned \x04%i \x01points for killing \x05%i \x01Infected!"NameTimerPoints[i], TimerKills[i]);
                }
            }

            
InterstitialPlayerUpdate(i);
        }

        
TimerPoints[i] = 0;
        
TimerKills[i] = 0;
        
TimerHeadshots[i] = 0;
    }


mehelp is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-19-2011 , 13:09   Re: Scripting Forum
Reply With Quote #24

Quote:
Originally Posted by mehelp View Post
well, I kinda did post it as a thread at first, but occasionally at 'amxmod scripting help'. that was my first post and already turned out to be a spam, so didn't want to multiply threads.

thank you for your peace of code, it' just doesn't seem like I'm capable of inserting it properly to plugin). if I put it before the block, responsible for displaying client points on infected death, plugin compiles perfectly, but there's no effect - numbers are still displayed in gamechat with no comma between digits. and when I tried to put indicated code directly in the block , I couldn't compile a thing- got like undefined symbols.. pretty sure I'm doing something wrong)).
here's where I tried to insert it, but failed (peace of [L4D & L4D2] Custom Player Stats v1.4B105 by muukis, just attempting to adopt to how I'd like stats to be displayed):

PHP Code:
// Display common Infected scores to each player.

public Action:timer_ShowTimerScore(Handle:timerHandle:hndl)
{
    if (
StatsDisabled())
        return;

    new 
Mode GetConVarInt(cvar_AnnounceMode);
    
decl String:Name[MAX_LINE_WIDTH];
    
    new 
maxplayers GetMaxClients();
    for (new 
1<= maxplayersi++)
    {
        if (
IsClientConnected(i) && IsClientInGame(i) && !IsClientBot(i))
        {
            
// if (CurrentPoints[i] > GetConVarInt(cvar_MaxPoints))
            //     continue;
            
            
            
TimerPoints[i] = GetMedkitPointReductionScore(TimerPoints[i]);
            
            if (
TimerPoints[i] > && TimerKills[i] > 0)
            {
                if (
Mode == || Mode == 2)
                {
                    
GetClientName(iNamesizeof(Name));
                    
CPrintToChat(i"{blue}%s \x01(%i) got points for killing Infected"Name, (ClientPoints[i] + CurrentPoints[i]));
                }
                else if (
Mode == 3)
                {
                    
GetClientName(iNamesizeof(Name));
                    
StatsPrintToChatAll("\x05%s \x01has earned \x04%i \x01points for killing \x05%i \x01Infected!"NameTimerPoints[i], TimerKills[i]);
                }
            }

            
InterstitialPlayerUpdate(i);
        }

        
TimerPoints[i] = 0;
        
TimerKills[i] = 0;
        
TimerHeadshots[i] = 0;
    }


You need to actually call it. For instance, to format the points in the modes 1 and 2 block above:
PHP Code:
new String:szPoints[15];
GetClientName(iNamesizeof(Name));
AddCommas((ClientPoints[i] + CurrentPoints[i]), szPointssizeof(szPoints));
CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"NameszPoints); 
__________________
Am I back? Well, we'll see.
Powerlord is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 13:59   Re: Scripting Forum
Reply With Quote #25

got it now. thank you for pointing. did as you recommended
PHP Code:
new String:szPoints[15];
GetClientName(iNamesizeof(Name));
AddCommas((ClientPoints[i] + CurrentPoints[i]), szPointssizeof(szPoints)); CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"NameszPoints); 
got following:
name(1) got points for killing infected
name(1)got points for killing infected
"1" value never changed.
is this because there's sum of clientPoints+current , maybe it'll display properly if referred to some separate value, like just client points or only current (but need some time to earn 1000 currentpoints to see if there's comma)?
or should I install whole piece of code before the block correctly ( I did try that and nothing compiled because of: "AddCommas" already defined)
also I tried
PHP Code:
new String:szPoints[15];
GetClientName(iNamesizeof(Name));
AddCommas((ClientPoints[i] + CurrentPoints[i]), szPointssizeof(szPoints));
CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"Name, (ClientPoints[i] + CurrentPoints[i])); 
and got:
name (t)) got points for killing Infected
name(v)) got points for killing Infected
nema (x)) got points for killing Infected
and lots of other different symbols))
mehelp is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 14:19   Re: Scripting Forum
Reply With Quote #26

ok tried displaying currentPoints only:

PHP Code:
AddCommas((CurrentPoints[i]), szPointssizeof(szPoints));
CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"NameszPoints); 
until (999) points been displaying correctly, then it became (1) and steady

Last edited by mehelp; 07-19-2011 at 14:22.
mehelp is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-19-2011 , 14:22   Re: Scripting Forum
Reply With Quote #27

Likely the problems are being caused by SourceMod storing strings differently than AMX Mod X does. I'll have to check what needs to be changed to get this working like it should.
__________________
Am I back? Well, we'll see.
Powerlord is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-19-2011 , 14:29   Re: Scripting Forum
Reply With Quote #28

Here's a new version with a few string handling functions changed around to use the ones that deal with bytes rather than cells (which are 4 bytes each).

PHP Code:
stock AddCommasiNumString:szOutput[] , iLen )
{
    new 
String:szTmp15 ] , iOutputPos iNumPos iNumLen;
    
    if ( 
iNum )
    {
        
szOutputiOutputPos++ ] = '-';
        
iNum = ~iNum 1// Two's complement conversion
    
}
    
    
IntToStringiNumszTmpsizeof(szTmp));
    
iNumLen strlen(szTmp);
    
    if ( 
iNumLen <= )
    {
        
iOutputPos += StrCatszOutput iLen szTmp );
    }
    else
    {
        while ( ( 
iNumPos iNumLen ) && ( iOutputPos iLen ) )
        {
            
szOutputiOutputPos++ ] = szTmpiNumPos++ ];
            
            if ( ( 
iNumLen iNumPos ) && !( (iNumLen iNumPos ) % ) )
            {
                
szOutputiOutputPos++ ] = ',';
            }
        }
        
        
szOutputiOutputPos ] = '\0';
    }
    
    return 
iOutputPos;

__________________
Am I back? Well, we'll see.
Powerlord is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 14:32   Re: Scripting Forum
Reply With Quote #29

Quote:
Originally Posted by Powerlord View Post
Likely the problems are being caused by SourceMod storing strings differently than AMX Mod X does. I'll have to check what needs to be changed to get this working like it should.
thank you, Powerlord, you so fine. even if it won't work, it's nice to try
mehelp is offline
mehelp
Junior Member
Join Date: Jul 2011
Old 07-19-2011 , 14:50   Re: Scripting Forum
Reply With Quote #30

Quote:
Originally Posted by Powerlord View Post
Likely the problems are being caused by SourceMod storing strings differently than AMX Mod X does. I'll have to check what needs to be changed to get this working like it should.
ok tried
PHP Code:
new String:szTmp15 ];
GetClientName(iNamesizeof(Name));
AddCommas((ClientPoints[i] + CurrentPoints[i]), szTmpsizeof(szTmp));
CPrintToChat(i"{blue}%s \x01(%s) got points for killing Infected"NameszTmp); 
same result : name (1) got points... but trying new version made me feel happy somehow lol

btw, there is another shtick about displaying stats - when it's about special infected, for exapmple:
"Name(1,111) got points for (1)Boomer" , boomer is shown with number if there's few of them currently spawned on the map; like when you look at players list thru adminmenu - it says 1. Hunter, 2. (1)hunter, when there's couple of infected of the same tipe. but when you killed (1)Boomer, you can assume there's more nearby, which should be a surprise I suppose. got no clue how to deal with this characters in front of infected name..

Last edited by mehelp; 07-19-2011 at 22:06.
mehelp is offline
Reply


Thread Tools
Display Modes

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 02:40.


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