writing names to file
#1

Hello, im trying to make a command which shows all the players who posted thier answers for questions and now pending for the accept. However i'm not sure how to save all those players? for example if player gets out of the server and he is still pending for request i want the list to show his name and when he is accpeted to remove his name from the list. Here is some commands i was trying to make to make this system and it didn't work.

This should get the onlinename string and show it (i thought maybe it will work saving strings..)
this is the command:
pawn Код:
COMMAND:passed(playerid, params[])
{
    if(GetPVarInt(playerid, "Admin") >= 1 || GetPVarInt(playerid, "Helper") >= 1 || GetPVarInt(playerid, "RegTeam") >= 1)
    {
        SendClientMessage(playerid, COLOR_WHITE, "__________________________________________________");
        SendClientMessage(playerid, COLOR_WHITE, "      People who are waiting approval:");
        if(onlinename[0] == EOS) return SendClientMessage(playerid, COLOR_WHITE, "None");
        SendClientMessage(playerid, COLOR_WHITE, onlinename);
        SendClientMessage(playerid, COLOR_WHITE, "__________________________________________________");
    }
    else SendClientMessage(playerid, COLOR_LIGHTRED, "You do not have access to this command !");
    return 1;
}
this is the save & loading:
pawn Код:
stock SavePlayerList()
{
    new File: file2, coordsstring[256];
    format(coordsstring, sizeof(coordsstring), "%s", onlinename);
    file2 = fopen("passed.ini", io_append);
    fwrite(file2, coordsstring);
    fclose(file2);
}

stock LoadPlayerList()
{
    new arrCoords[34][64], strFromFile2[256];
    new File: file = fopen("passed.ini", io_read);
    if(file)
    {
        fread(file, strFromFile2);
        split(strFromFile2, arrCoords, '\n');
        strmid(onlinename, arrCoords[0], 0, strlen(arrCoords[0]), 24);
    }
    fclose(file);
    return 1;
}
this is the way im trying to add player name to the string
pawn Код:
format(online, sizeof(online), "%s\r\n", PlayerName(playerid));
        strcat(onlinename, online, sizeof(onlinename));
I would be happy if this was variables instead of string. however this is the closest i got to make this work..
Please help me get this command work.
Reply
#2

*Bump* please help!
Reply
#3

It's hard to understand with what you want halp with. You said it doesn't work. Okay, what does not work - I mean, what happens and what you wanted to happen would be helpful.

I can see, you store eveything in a (very long) string + saving it to a file, what is good choice if you ask me. Alternativly you could save it only in file and every time you need string you read it from file, parse it and display it.

I am not sure I understood what you want this system to do. something like this: PlayerOne asks a question (or admin - main point a question is asked). Then, other players can answer them and their answers need to accepted. So, somehow answers (and names of the players that gave answers) need to be saved when players disconnect, or even when server is down.
For that reason you choosed to use file.
But can a single player respond to more questions, and how do you save answers? maybe this will direct you to right way of thinking.
Reply
#4

Quote:
Originally Posted by Roko_foko
Посмотреть сообщение
It's hard to understand with what you want halp with. You said it doesn't work. Okay, what does not work - I mean, what happens and what you wanted to happen would be helpful.

I can see, you store eveything in a (very long) string + saving it to a file, what is good choice if you ask me. Alternativly you could save it only in file and every time you need string you read it from file, parse it and display it.

I am not sure I understood what you want this system to do. something like this: PlayerOne asks a question (or admin - main point a question is asked). Then, other players can answer them and their answers need to accepted. So, somehow answers (and names of the players that gave answers) need to be saved when players disconnect, or even when server is down.
For that reason you choosed to use file.
But can a single player respond to more questions, and how do you save answers? maybe this will direct you to right way of thinking.
Alright, here is what should happen: there is a new connected player, I want him to fill quiz, however to get passed, the admins needs to approve his quiz answers. everything works great, only one problem. I want that the command /passed will display all the players (applications) waiting to get accpeted, so admins will know which one to check, players can be offline and admins still may check thier application status. So, basically i need to check offline/online players who are waiting to get accepted to the server with the command /passed. Enough explained?
I just can't create that command. What should i save to a file and how I'm using a loop on the command to show this?
Reply
#5

*bump* please help.
Reply
#6

I would do it like this (you have a lot of it done):
Add one player variable called QuizPassed and put 0 as it's initial value. (0 didn't take the quiz, 1 filled the quiz, 2 passed the quiz)
On player registration set the value to 0, again and give player the quiz.
When quiz is filled up save his name in the file, just add it in the end of the file. io_append -> to start writing at the end. Set the QuizPassed = 1
Make sure you save the variable with other player statistics.

On player login get player variables and check if the quiz is passed:
Код:
load_stats(playerid);
if(playerinfo[QuizPassed] == 0) {
    give to player the quiz;
}
else if(playerinfo[QuizPassed] == 1) {
    list_of_names = read_file();
    if(playername in list_of_names) {
        // player filled the quiz but didn't get response of the admin
        // ...
        return 1;
    }
    else {
        // player passed the quiz
        playerInfo[quiz_passed] = 2;
    }
}
in passed command you need to list all the players, and for each player you need to show the answers (you need to save them somehow -> as player stats or in a specific file)
if admin is happy with the answer he calls the function:
Код:
command SetQuizPass(playerName[MAX_PLAYER_NAME+1]) {
    delete player name from the file (list)
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)