SA-MP Forums Archive
No removing underscore. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: No removing underscore. (/showthread.php?tid=597204)



No removing underscore. - Alex_T - 27.12.2015

Hello so I am confused as to why my GiveNameSpace is not removing the underscore. Thanks for the replys.







Код:
stock GetPlayerNameEx(playerid,ENameType:type) {
	new name[MAX_PLAYER_NAME+1];
	//SetPVarString(playerid,"CharUsername",id_string);
	if(IsPlayerConnected(playerid)) {
		switch(type) {
			case ENameType_AccountName: {
				GetPVarString(playerid,"AccountName",name,MAX_PLAYER_NAME);
			}
			case ENameType_RPName: {
				new maskid = GetPVarInt(playerid, "MaskID");
				if(GetPVarInt(playerid, "MaskOn") != 1) {				
					GetPVarString(playerid,"CharUsername",name,MAX_PLAYER_NAME);
				} else {
					format(name, sizeof(name), "Stranger_%d",maskid);
				}
				GiveNameSpace(name);
			}
			case ENameType_CharName: {
				GetPVarString(playerid,"CharUsername",name,MAX_PLAYER_NAME);
			}
			case ENameType_RPName_NoMask: {
				GetPVarString(playerid,"CharUsername",name,MAX_PLAYER_NAME);
				GiveNameSpace(name);
			}
			case ENameType_Phone_Name: {
				GetPVarString(playerid,"CharUsername",name,MAX_PLAYER_NAME);
				if(GetPVarInt(playerid, "PhoneStatus") == 1) {
					strmid(name,"Anonymous",0,9,MAX_PLAYER_NAME);
				}
				if(GetPVarInt(playerid, "PhoneStatus") == 3) {
					strmid(name,"Payphone",0,9,MAX_PLAYER_NAME);
				}
				GiveNameSpace(name);			
			}
		}
		if(strlen(name) < 1) { //null name(either not logged in or a bug happend to them
			GetPlayerName(playerid, name, sizeof(name));
		}
	} else {
		GetPlayerName(playerid, name, sizeof(name));
	}
	return name;
}
Код:
GiveNameSpace(str[])
{
    new strl;
    strl=strlen(str);
    while(strl--) {
    if(str[strl]=='_')	str[strl]=' ';
    }
    return 0;
}



Re: No removing underscore. - SickAttack - 27.12.2015

We already went through this:
pawn Код:
// ** INCLUDES

#include <a_samp>

// ** MAIN

main()
{
    print("Loaded \"replace_underscore_with_space.amx\".");

    new source[20] = "CaNDy_Boy_Mr Sr_Hey";
    ReplaceUnderscoreWithSpace(source);

    printf("%s", source);
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock ReplaceUnderscoreWithSpace(source[])
{
    for(new i = 0, j = strlen(source); i < j; i ++)
    {
        if(source[i] == '_')
        {
            source[i] = ' ';
        }
    }
    return 1;
}
pawn Код:
// ** INCLUDES

#include <a_samp>

// ** MAIN

main()
{
    print("Loaded \"replace_string.amx\".");

    new source[20] = "CaNDy_Boy_Mr Sr_Hey";
    ReplaceString(source, "_", " ");

    printf("%s", source);
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock ReplaceString(source[], const search[], const replace[], size_of = sizeof(source))
{
    new search_length = strlen(search), temp, last_pos;
    for(;;)
    {
        temp = strfind(source, search, false, last_pos);

        if(temp != -1)
        {
            strdel(source, temp, (temp + search_length));
            strins(source, replace, temp, size_of);

            last_pos = (temp + search_length);
        }
        else
        {
            break;
        }
    }
    return 1;
}



Re: No removing underscore. - Vince - 27.12.2015

Uh, just read the last 7 lines of that code:
Quote:
PHP код:
        if(strlen(name) < 1) { //null name(either not logged in or a bug happend to them
            
GetPlayerName(playeridnamesizeof(name));
        }
    } else {
        
GetPlayerName(playeridnamesizeof(name));
    }
    return 
name
Then notice that in both cases it does exactly the same thing: overriding the name and then immediately returning it. This obviously makes all code above totally useless.


Re: No removing underscore. - Alex_T - 28.12.2015

Thank you for replys. The code I posted works actually, I was using the wrong PVar in my GetPlayerNameEx code. Thanks for replys.