SetPlayerName Problem
#1

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;
}
Reply
#2

Show your code.
Reply
#3

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

Ups I forgot. Hold on.
Reply
#5

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.
Reply
#6

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?
Reply
#7

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.
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)