AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   replace_all question (https://forums.alliedmods.net/showthread.php?t=223197)

red_bull2oo6 08-10-2013 19:53

replace_all question
 
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.

fysiks 08-10-2013 19:59

Re: replace_all question
 
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.

red_bull2oo6 08-11-2013 05:49

Re: replace_all question
 
thanks, that helped.
and yes i use it on 3 different players.

fysiks 08-11-2013 13:53

Re: replace_all question
 
Quote:

Originally Posted by red_bull2oo6 (Post 2010563)
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.

red_bull2oo6 08-11-2013 15:23

Re: replace_all question
 
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"®""®" );
    



fysiks 08-11-2013 16:08

Re: replace_all question
 
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?

red_bull2oo6 08-11-2013 17:22

Re: replace_all question
 
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.

fysiks 08-11-2013 17:27

Re: replace_all question
 
Quote:

Originally Posted by red_bull2oo6 (Post 2011071)
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.


All times are GMT -4. The time now is 15:57.

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