how to change name without tag
#1

i want some like this:

connectname = rocky[KING]

[KING] is clan tag

onplayerconnect i want to change name to rocky


like

SetPlayerName(playername-tag);

i use strfind to find clan tag, how can i remove clan tag from player name?
Reply
#2

Is it about specific tags only (like only [KING] is going to be removed), or all clan tags?

You can use strfind (it returns the index where it was found, eg. 0 if it's at the start, or in your example 5, -1 if it wasn't found).

Then you know where the tag begins in the name, from there you can use strdel to remove it:

Код:
new idx = strfind(name, "[KING]", true);

if(idx != -1)
{
strdel(name, idx, idx + 6); // Deletes characters from (idx) to (idx+6), since 6 is the length of the tag
SetPlayerName(playerid, name);
}
Reply
#3

not work
Код:
new name[30];
GetPlayerName(playerid, name, sizeof name);
for(new clanid; clanid < clanss; clanid++)
    {
        new idx = strfind(name, ClanInfo[clanid][cClanTag], true),
            ctr = strlen(ClanInfo[clanid][cClanTag]);
        if(idx != -1)
        {
            strdel(name, idx, idx + ctr); 
            SetPlayerName(playerid, name);
            break;
        }
    }
not work
Reply
#4

Код:
new search[] = "[tag]", name[] = "dog[tag]test",
	idx = strfind(name, search, true);

if(idx != -1)
{
	print("Found Tag");

	strdel(name, idx, idx + strlen(search));

	printf("New name: \"%s\"", name);
}
This works, the result is "dogtest".

Your code is (except the source of the strings) the same, so the error is either in the ClanInfo array or SetPlayerName.

Print out the result to see what's happening.
If there are uninitialized/invalid clans make sure they are skipped, otherwise it will delete 0 characters as an empty string is 0 characters long and break the loop.

Also make sure the playername remains at least 3 characters as that is the minimum name length.
Reply
#5

not work..
Reply
#6

Quote:
Originally Posted by rockys
Посмотреть сообщение
onplayerconnect i want to change name to rocky


like

SetPlayerName(playername-tag);
Don't use SetPlayerName OnPlayerConnect, the name will not update for the connecting player (other players will see it changed).

Read notes in https://sampwiki.blast.hk/wiki/SetPlayerName
Reply
#7

Use it under OnPlayerSpawn
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)