SA-MP Forums Archive
SetPlayerName Problem - 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: SetPlayerName Problem (/showthread.php?tid=597180)



SetPlayerName Problem - Sanady - 27.12.2015

Hello everybody. I have one problem. I don`t understand this problem very well so I am asking for help. I created squad. When leader tries to add squad tag it`s works for first time good. But second tag will doubles, I don`t know why. Here are pictures:





CODE:
pawn Код:
CMD:settag(playerid, params[])
{
    new tag[4], squadid = GetPlayerUniqueSquadID(playerid), string[64];
    if(sscanf(params,"s[4]", tag)) return SendServer(playerid,"/settag [tag]");
   
    format(string, sizeof(string), "[%s]%s", tag, pName[playerid]);
    SetPlayerName(playerid, string);
   
    format(sInfo[squadid][SquadTag], 4, "%s", tag);
   
    SendMessage(playerid, -1,"{BCF562}Squad {FFFFFF}You have set squad tag [%s]!", sInfo[squadid][SquadTag]);
    return 1;
}



Re: SetPlayerName Problem - GeneralAref - 27.12.2015

Show your code.


Re: SetPlayerName Problem - SecretBoss - 27.12.2015

Add a check to check if the tag has been already added, and prevent leader from using it again


Re: SetPlayerName Problem - Sanady - 27.12.2015

Ups I forgot. Hold on.


Re: SetPlayerName Problem - PrO.GameR - 27.12.2015

PHP код:
format(stringsizeof(string), "[%s]"tag);
if(
strfind(pName[playerid],stringtrue)==-1strins(pName[playerid], string0);
SetPlayerName(playerid,pName[playerid]); 
here's the most efficent way to do it.


Re: SetPlayerName Problem - Sanady - 27.12.2015

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
PHP код:
format(stringsizeof(string), "[%s]"tag);
if(
strfind(pName[playerid],stringtrue)==-1strins(pName[playerid], string0);
SetPlayerName(playerid,pName[playerid]); 
here's the most efficent way to do it.
Can you explain me what that code do? What does it checks?


Re: SetPlayerName Problem - PrO.GameR - 27.12.2015

Quote:
Originally Posted by Sanady
Посмотреть сообщение
Can you explain me what that code do? What does it checks?
Strfind returns -1 if the string you want to find is not available in the other string you are checking in, therefore it checks if there is a [MG] tag in your name, if there isn't then it adds it.


Re: SetPlayerName Problem - Sanady - 28.12.2015

Quote:
Originally Posted by patrickgtr
Посмотреть сообщение
Looks like the string aren't getting cleared after you want to use them again, that's why they duplicate. This should work.

pawn Код:
CMD:settag(playerid, params[])
{
    new tag[4], squadid = GetPlayerUniqueSquadID(playerid), string[64];
    if(sscanf(params,"s[4]", tag)) return SendServer(playerid,"/settag [tag]");
   
    format(string, sizeof(string), "[%s]%s", tag, pName[playerid]);
    SetPlayerName(playerid, string);
   
    sInfo[squadid][SquadTag][0] = EOS;
    strcat(sInfo[squadid][SquadTag], tag, 4); //faster than format

    SendMessage(playerid, -1,"{BCF562}Squad {FFFFFF}You have set squad tag [%s]!", sInfo[squadid][SquadTag]);
    return 1;
}
Ye, I wasn`t thinking logically. Maybe that`s why is duplicating, I will try today both codes.