String formatting and unformatting problem
#1

Hello

I'm making a tiki system, where the player has to find 25 tikis that are hidden in the world.
Now everything works flawless, however I have a problem saving which tikis have already been found by a player and which are yet to be tracked.

Now here's how I want to do this:
pawn Код:
PInfo[MAX_PLAYERS][FoundTiki[MAX_TIKIS]]
That's the array, so when a player picks up a tiki all I do is set
pawn Код:
PInfo[playerid][FoundTiki[FoundTiki]] = 1;
Well this all works perfect however when a player disconnects I'm trying to format wether or not the player has found a tiki in a string, using this code:
pawn Код:
for(new ti; ti < sizeof TIInfo; ti ++)
    {
        format(PInfo[playerid][TikiString], MAX_TIKIS, "%s%d", PInfo[playerid][TikiString], PInfo[playerid][FoundTiki][ti]);
    }
Well this should format the following string when for example a player has found the first and second last tiki: [CODDE]1000..10[/CODE]
1 Saying that the player has found the specific tiki
0 saying that the player hasn't yet found the tiki

But unfortunately this doesn't work, the string is formatted wrong all the time and I don't know why...
Please tell me how to do this correctly :/

Also another thing, when I read the tikistring from the database, I would like to convert the string into values so this:

Код:
100..10
Becomes this:
Код:
PInfo[playerid][FoundTiki][0] = 1; //Tiki id 0 has been found by the player
PInfo[playerid][FoundTiki][1] = 0;  //Tiki id 1 hasn't been found, hence value 0

And so forth
BUt I don't know how I can read wether a player has already found a certain tiki or not from this string

Thanks in advance
Reply
#2

Just so I understand you (and correct me if I'm wrong on any item):

1) If a player picks up a tiki you want to populate a variable as 1.
2) When the player disconnects, you want to save all the tikis they've picked up in to a long string variable of 1's and 0's.
3) Each position of the string should correspond with a picked up tiki.

Are those 3 points correct?
Reply
#3

You can use strcat to split the strings. So it can be easily done throughout a loop. For example,

// loop
pawn Код:
{
    if(TikiInfo[i][foundby] == playerid) strcat(string, sizeof(string), "..%d", i);
}
That would be if you want the number to the tiki ID.

I'd recommend storing the tikis independantly to the database. For instance, you could do something like this,

pawn Код:
if(PlayerTikis[playerid][tikis[i] == true)
{
     // save the tiki in the DB
}
Reply
#4

EDIT: NVM
Reply
#5

Quote:
Originally Posted by nemesis-
Посмотреть сообщение
Just so I understand you (and correct me if I'm wrong on any item):

1) If a player picks up a tiki you want to populate a variable as 1.
2) When the player disconnects, you want to save all the tikis they've picked up in to a long string variable of 1's and 0's.
3) Each position of the string should correspond with a picked up tiki.

Are those 3 points correct?
Yes that's correct



Thank you for the response.
I figured that it would be better to adjust the string whenever a player finds a tiki and then to just save the string in the server database upon disconnecting.

So therefor I used this code:

pawn Код:
strdel(PInfo[playerid][TikiString], ti, ti + 1);
            strins(PInfo[playerid][TikiString], "1", ti);
This happens when the player picks up tiki id "ti"
Well what I'm trying to do here is replacing the 0 with a 1 for a specific tiki so for example when a player finds the third tiki in the server this:
Код:
 00000000..0
Becomes this:
Код:
00100000..0
However the code at first sight seems to work, but everytime I try to update the string fr some reason it also writes the playername in the string...

So this:
Код:
000000..00
Becomes this:
Код:
001000..00 knackworst
Where knackworst is the player who picked up the tiki, is this some sort of bug or?
Because it's very weird because I never call the players name when the player picks up the tiki...

Here's the full code when a player finds a tiki:
pawn Код:
public OnPlayerPickUpDynamicPickup(playerid, pickupid)
{
    for(new ti; ti < sizeof TIInfo; ti++)
    {
        if(pickupid == TIInfo[ti][TikiID])
        {
            if(PInfo[playerid][FoundTiki][ti] == 1) return SendClientMessage(playerid, COLOR_RED, " you have already found this tiki");
            PInfo[playerid][FoundTiki][ti] = 1;
            PInfo[playerid][TotalTikis] ++;
            SendClientMessage(playerid, COLOR_GREEN, "You have found a tiki");
           
            strdel(PInfo[playerid][TikiString], ti, ti + 1);
            strins(PInfo[playerid][TikiString], "1", ti);
            //format(PInfo[playerid][TikiString][ti], MAX_TIKIS, "1");
           
            PlayerStatsUpdate(playerid);
        }
    }
Thanks in advance
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)