Raised This Month: $51 Target: $400
 12% 

replace_all question


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-10-2013 , 19:53   replace_all question
Reply With Quote #1

hi again xD i came this time with one question

is it bad for my plugin to use "this stock" like 3 times in a function ?

PHP Code:
MakeNameSafeid )
{
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"#""%23" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"?""%3F" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1":""%3A" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1";""%3B" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"/""%2F" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1",""%2C" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"$""%24" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"@""%40" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"+""%2B" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"=""%3D" );
    
replace_allg_szNameid ], sizeofg_szName[ ] ) -1"®""®" );

what any method can i use.
red_bull2oo6 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-10-2013 , 19:59   Re: replace_all question
Reply With Quote #2

If you need to use your custom function 3 times inside the same function then you are likely doing something wrong unless you are doing it on three different players. You should show your whole code so we can give you the best advice.
__________________
fysiks is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-11-2013 , 05:49   Re: replace_all question
Reply With Quote #3

thanks, that helped.
and yes i use it on 3 different players.
red_bull2oo6 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-11-2013 , 13:53   Re: replace_all question
Reply With Quote #4

Quote:
Originally Posted by red_bull2oo6 View Post
thanks, that helped.
and yes i use it on 3 different players.
Well, now that I think of it, you are still doing something wrong based on the fact that the names are are being stored in global variable and you should only need to do it once for each player.

Can you show your code? Attach your plugin as an attachment.
__________________
fysiks is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-11-2013 , 15:23   Re: replace_all question
Reply With Quote #5

well i modified it and now it looks like this:

PHP Code:
/* Plugin generated by AMXX-Studio */

#include < amxmodx >
#include < amxmisc >

#define PLUGIN "GT Played Time"
#define VERSION "1.1.5"

new const g_szGameTracker[ ] = "http://www.gametracker.com/player";

new 
g_szServerIp32 ];
new 
g_szCustomUrl128 ];

public 
plugin_init( )
{
    
//--|Credits to Laurr for his idea. ( https://forums.alliedmods.net/showthread.php?t=220727 ).
    
register_pluginPLUGINVERSION"Askhanar" );
    
    
register_clcmd"say""HookClCmdSayOrSayTeam" );
    
register_clcmd"say_team""HookClCmdSayOrSayTeam" );
    
    
register_clcmd"gt_playedtime""ClCmdPlayedTime" );
    
//register_clcmd( "say /playedtime", "ClCmdSayPlayedTime" );
    
    
get_user_ip0g_szServerIpsizeof g_szServerIp ) -1); //--| Ii luam ip la sv cu tot cu port!
    // Add your code here...
}

public 
HookClCmdSayOrSayTeamid )
{
    static 
szArgs192 ], szCommand192 ];
    
read_argsszArgssizeof szArgs ) -);
    
    if( !
szArgs] )
        return 
PLUGIN_CONTINUE;
    
    
remove_quotesszArgs );
    
    if( 
equalszArgs,  "/playedtime"strlen(  "playetime" ) ) )
    {
        
replaceszArgssizeof szArgs ) -1"/"""  );
        
formatexszCommandsizeof szCommand ) -1"gt_%s"szArgs );
        
client_cmdidszCommand );
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
ClCmdPlayedTimeid )  
{
    
    new 
szFirstArg32 ];
        
read_argv1szFirstArgsizeof szFirstArg ) -);

    if( 
equaliszFirstArg"" ) ) 
        
DisplayPlayedTimeidid );
    
    else
    {
        
    
        new 
iPlayer cmd_targetidszFirstArg);
        if(!
iPlayer || iPlayer == id )
            return 
PLUGIN_CONTINUE;
    
        
DisplayPlayedTimeidiPlayer );
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
DisplayPlayedTimeidiPlayer )
{
    new 
szName32 ];
    
get_user_nameiPlayerszNamesizeof szName ) -);
    
MakeNameSafeszNamesizeofszName ) -);
    
    
formatexg_szCustomUrlsizeof g_szCustomUrl ) -1"%s/%s/%s/",
        
g_szGameTrackerszNameg_szServerIp );
        
    
show_motdidg_szCustomUrl );
    
}

MakeNameSafeszName[ ], iLen )
{
    
replace_allszNameiLen"#""%23" );
    
replace_allszNameiLen"?""%3F" );
    
replace_allszNameiLen":""%3A" );
    
replace_allszNameiLen";""%3B" );
    
replace_allszNameiLen"/""%2F" );
    
replace_allszNameiLen",""%2C" );
    
replace_allszNameiLen"$""%24" );
    
replace_allszNameiLen"@""%40" );
    
replace_allszNameiLen"+""%2B" );
    
replace_allszNameiLen"=""%3D" );
    
replace_allszNameiLen"®""®" );
    

red_bull2oo6 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-11-2013 , 16:08   Re: replace_all question
Reply With Quote #6

It will probably be much more efficient to use this.

Also, I didn't think a non-ascii character was allowed in URLs. Are you sure that actually works?
__________________

Last edited by fysiks; 08-11-2013 at 16:10.
fysiks is offline
red_bull2oo6
Senior Member
Join Date: Mar 2012
Location: Braila, Romania
Old 08-11-2013 , 17:22   Re: replace_all question
Reply With Quote #7

yes i`m sure i tested it.

thanks again but i think i`ll stay to replace_all
i think its solved by now.

LE: @that encode method, i'll give it a try to see with my own eyes.

Last edited by red_bull2oo6; 08-11-2013 at 17:25.
red_bull2oo6 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-11-2013 , 17:27   Re: replace_all question
Reply With Quote #8

Quote:
Originally Posted by red_bull2oo6 View Post
yes i`m sure i tested it.

thanks again but i think i`ll stay to replace_all
i think its solved by now.

LE: @that encode method, i'll give it a try to see with my own eyes.
There are no non-ascii characters in that URL. I was referring to you replacing the registered trade mark symbol by two non-ascii characters.

Also, your question implied you were asking about efficiency and hence why I suggested the encode URL function.
__________________

Last edited by fysiks; 08-11-2013 at 17:28.
fysiks 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 04:58.


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