SendClientMessage Issue
#1

So I will explain the issue before I show the code.
I have a file which gets opened and stores a name to an array.
Then I am using a command to show the name up in SendClientMessage and it does but it has letters appearing before it which shouldn't be coming up.
So in my file I have the names printed like this:
pawn Код:
Jaxson Kildra|Thomas_Rein|Leon_Manheart|Clive_Rogers|Jaxson Kildra|Thomas_Rein|Leon_Manheart|Clive_Rogers|
Now they get stored into an array using this code which is in a function:
pawn Код:
if(file)
    {
        print("File Found!");
        fread(file, string);
        new text[128];
        for(new i = 0; i < c; i++)
        {
            split(string, SplitDiv, '|');
            print("In Loop");
            print(SplitDiv[0]);
            strmid(PlayerInfo[playerid][pFriends][i], SplitDiv[0], 0, strlen(SplitDiv[0]));
            strins(PlayerInfo[playerid][pFriends][i], SplitDiv[0], 0);
            format(text, sizeof(text), "PlayerInfo[playerid][pFriends][%d] = %s", i, PlayerInfo[playerid][pFriends][i]);
            print(text);
            strdel(string, -1, strlen(SplitDiv[0]));
        }
        print("Finished Loop");
        fclose(file);
        print("Closed File");
    }
Now when I check console, it prints the text fine.

Now I have only one command to preview the name to test if it works.
pawn Код:
new string[128];
SendClientMessage(playerid, COLOR_WHITE, PlayerInfo[playerid][pFriends][1]);
return 1;
}
But the thing is when I do that, it prints the text as:
pawn Код:
TLCJTLClive_Rogers
Does anyone know how I can fix this?
Reply
#2

Firstly, you should never save the player names like that - it will cause buffer overflows in the long run!

pawn Код:
Save_The
Player_Names
Like_This
Let me know once you've done that.
Reply
#3

As Emmet said, you should save the names like that. Or, even better, try saving it 1 file for a user.

Let's say You would have:
Код:
scriptfiles>Player1
Player2
Player3
Reply
#4

Quote:
Originally Posted by Excelize
Посмотреть сообщение
As Emmet said, you should save the names like that. Or, even better, try saving it 1 file for a user.

Let's say You would have:
Код:
scriptfiles>Player1
Player2
Player3
No, that will just clutter the scriptfiles folder - it's better to save all of the names in one file per player since it's more efficient.
Reply
#5

Well, how do I save it as that?

Using \n? I knew I could seperate names with |. And I need to save all names to an array for the player as it is basicly the friends his added. And the player can then search whether his friends with someone or not.
Reply
#6

Could someone help me with this please?
I've put down my whole script for this.

http://pastebin.com/kEspu3uR
Reply
#7

Quote:
Originally Posted by Deduction
Посмотреть сообщение
Using \n? I knew I could seperate names with |.
Well yes, but the difference is that most of the file functions are geared to reading separate lines. For example:
pawn Код:
new count;
while(fread(file, PlayerInfo[playerid][pFriends][count], MAX_PLAYER_NAME) && count < c)
{
    count++;
}
That would completely eliminate the need for split, strmid and who know whatever else.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Well yes, but the difference is that most of the file functions are geared to reading separate lines. For example:
pawn Код:
new count;
while(fread(file, PlayerInfo[playerid][pFriends][count], MAX_PLAYER_NAME) && count < c)
{
    count++;
}
That would completely eliminate the need for split, strmid and who know whatever else.
So I did exactly that.

pawn Код:
new c = friendly[playerid];
    if(file)
    {
        new count;
        while(fread(file, PlayerInfo[playerid][pFriends][count], MAX_PLAYER_NAME) && count <= c)
        {
            print(PlayerInfo[playerid][pFriends][count]);
            count++;
        }
        fclose(file);
    }
    else
    {
        SendClientMessage(playerid, COLOR_RED, "File: Error Found!");
    }
    fclose(file);
Thats for loading the players. Which it works fine when it prints. Shows name correctly.

But then when I do a command to see the players which is this one:
pawn Код:
CMD:seefriends(playerid, params[])
{
    new c = friendly[playerid];
    for(new i = 0; i < c; i++)
    {
        format(msg, sizeof(msg), "%s", PlayerInfo[playerid][pFriends][i]);
        SendClientMessage(playerid, COLOR_WHITE, msg);
        print(msg);
    }
    return 1;
}
It ends up returning the names like this in console and ingame:
pawn Код:
JLFTAFDS
LFTAFDS
FTAFDS
TAFDS
AFDS
FDS
DS
S
The Names of the Players are in this format in the .ini file.
pawn Код:
Jamie Walker
LOL POP
Franklin Gardener
Tom Frank
AJ Smith
Forrest Gump
Damian Adelaide
Salve Holmes
Here is the PlayerInfo enum:
pawn Код:
enum p_Info
{
    pRegistered,
    pCash,
    pSkin,
    pLevel,
    pExp,,
    pAdmin,
    pInt,
    pWorld,
    pBanned,
    pWarns,
    Float:pPosX,
    Float:pPosY,
    Float:pPosZ,
    Float:pPosA,
    pDied,
    pUpgrade,
    Float:pSHealth,
    pCrashed,
    Float:pArmour,
    pHasArmour,
    pFriends[2000]
};
new PlayerInfo[MAX_PLAYERS][p_Info];
Does anyone have any idea?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)