[Tutorial] [Beginners Tutorial] Making a Suggest Command
#1

Making a Suggest Command


Today, I am making a tutorial on how to create a /suggest command. Through this command, Players can send you suggestions directly from the server and all suggestions will be saved in a file.

Lets Start !

First Step

1st step is to creating a file in which all suggestion will be saved. To make a folder we have to define the location of the folder. So make a folder in script files.

pawn Код:
#define suggestPATH "Suggestions/SuggestLog.txt"
Explanation

The suggestPATH define that where the folder and the log is located. Before testing this system, you must create a file in the script files. You can change the folder name to whatever you want but the folder name should be correct and should match the suggestPATH.

Second Step

2nd step is to creating a command which will make players able to send their suggestions. And for this I am using Zcmd.

pawn Код:
COMMAND:suggest(playerid, params[])
{
    new string[128],suggestion[128],pName[MAX_PLAYER_NAME];
    new File:Log = fopen(suggestPATH, io_append);
    new logData[128];
    if(sscanf(params,"s[128]",suggestion)) return SendClientMessage(playerid, COLOR_WHITE,"USAGE: /suggest [suggestion]");
    GetPlayerName(playerid,pName,MAX_PLAYER_NAME);
    SendClientMessage(playerid, COLOR_LIGHTGREEN, "Your suggestion report has been saved in a file. Thankyou!");
    format(logData, sizeof logData, "%s has sent a suggestion: %s \r\n",pName,suggestion);
    fwrite(Log, logData);
    fclose(Log);
    format(string,sizeof string,"[Suggestion] - Your Suggestion has been sent..",);
    SendClientMessage(playerid,COLOR_GREEN,string);
    return 1;
}
Explanation

pawn Код:
new File:Log = fopen(suggestPATH, io_append);
This feature will open the suggestion log to save the suggestion of the player.

pawn Код:
if(sscanf(params,"s[128]",suggestion)) return SendClientMessage(playerid, COLOR_WHITE,"USAGE: /suggest [suggestion]");
This feature will tell the usage of command, if a player not use it perfectly.

pawn Код:
format(logData, sizeof logData, "%s has sent a suggestion: %s \r\n",pName,suggestion);
    fwrite(Log, logData);
This is the format of the text. This format will be saved in the log with the player name and his suggestion. You can set it to your own but don't remove "%s" from the format.

pawn Код:
fclose(Log);
After being sent of suggestion. This feature will close the log.

pawn Код:
format(string,sizeof string,"[Suggestion] - Your Suggestion has been sent..",);
    SendClientMessage(playerid,COLOR_GREEN,string);
This message will noticfy the player that your suggestion has been sent.

______________________________________________

Hope you have enjoyed the tutorial.
Thank You,
Champ.

Reply
#2

Awesome tutorial,
Nicely Explained
1+
Reply
#3

Thanks for you nice feedback. Sshady.
Reply
#4

No More feedbacks ??
Reply
#5

pawn Код:
new string[128],suggestion,pName[MAX_PLAYER_NAME]; //You must put suggestion[128]
So it must be like this
pawn Код:
new string[128],suggestion[128],pName[MAX_PLAYER_NAME];
Reply
#6

[D]ry[D]esert
We are not using suggestion as a string.
pawn Код:
(string,sizeof string,
We are using suggestion to show the text of the player.
pawn Код:
pName,suggestion);
Reply
#7

DryDesert is right. Did you even test this before writing a tutorial on it?
Reply
#8

SuperViper, I have tested this many times. It is working good.
Reply
#9

Champ he is right
Reply
#10

Thanks for noticing. Any other errors?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)