[Tutorial] How to make a bug report command (ZCMD + sscanf + log)
#1

Bug reporting + log
Intro
Hi, this is my first tutorial. I'll try to explain how to make a bug report command with zcmd processor and logging

Lets start
Includes neededCommand (explanation)
First we will need to add the zcmd header.
pawn Code:
CMD:reportbug(playerid, params[])
{

return 1;
}
Now that we made the header we will need to add the variables...
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

return 1;
}
Ok lets explain all that :
  • text - is the text the player is going to input as a description of the bug
  • name - players name (not yet finished)
  • bugstring - the string thats going to be in the .log file
  • float: x, float:y, float:z - position (not yet finished)
  • File:Bugs - variable for files
So now we need to make sure that the player typed it correctly and if the type limit exceeded.
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_RED "• Incorrect fomat. Use /reportbug [description]");
if(strlen(text) > 64) return SendClientMessage(playerid, COLOR_RED,"• Description is too long (Max. 64 letters)");

return 1;
}
Explanation :
  • if(sscanf(params, "s[64]", text)) - we are using sscanf to check if he typed it correct, and if not we are returning a message saying that he didn't input it correct
  • if(strlen(text) > 64) - this checks if he/she typed more than 64 letters, and if the limit is exceeded then it returns a message saying that the description is too long...
Now, we need to get a players name and his position, so...
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_RED "• Incorrect fomat. Use /reportbug [description]");
if(strlen(text) > 64) return SendClientMessage(playerid, COLOR_RED,"• Description is too long (Max. 64 letters)");
   
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);

return 1;
}
Explanation :
  • GetPlayerName(playerid, name, sizeof(name)); - Gets the players name (finished)
  • GetPlayerPos(playerid, x, y, z); - Gets the players position (finished)
Now, we need to format the message thats going to be in the .log file
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_RED "• Incorrect fomat. Use /reportbug [description]");
if(strlen(text) > 64) return SendClientMessage(playerid, COLOR_RED,"• Description is too long (Max. 64 letters)");
   
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);
format(bugstring, sizeof(bugstring), "%s reported a bug. Description : %s, on coordinates : X:%f, Y:%f, Z:%f\r\n", name, text, x, y, z);

return 1;
}
Explanation :
There isnt much to explain, were formatting a string thats going to be in a log...

Ok now we need to open the .log file and write in it... so
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_RED "• Incorrect fomat. Use /reportbug [description]");
if(strlen(text) > 64) return SendClientMessage(playerid, COLOR_RED,"• Description is too long (Max. 64 letters)");
   
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);
format(bugstring, sizeof(bugstring), "%s reported a bug. Description : %s, on coordinates : X:%f, Y:%f, Z:%f\r\n", name, text, x, y, z);

Bugs = fopen("bugs.log", io_append);
fwrite(Bugs, bugstring);
fclose(Bugs);

return 1;
}
Explanation :
  • Bugs = fopen("bugs.log", io_append); - this opens the file called 'bugs.log'
  • fwrite(Bugs, bugstring); - this writes the string in the bugs.log
  • fclose(Bugs); - this closes the bugs.log
Thats all... You can add a message that he successfully reported that bug, so :
pawn Code:
CMD:reportbug(playerid, params[])
{
new text[64], name[MAX_PLAYER_NAME], bugstring[256], Float:x, Float:y, Float:z, File:Bugs;

if(sscanf(params, "s[64]", text)) return SendClientMessage(playerid, COLOR_RED "• Incorrect fomat. Use /reportbug [description]");
if(strlen(text) > 64) return SendClientMessage(playerid, COLOR_RED,"• Description is too long (Max. 64 letters)");
   
GetPlayerName(playerid, name, sizeof(name));
GetPlayerPos(playerid, x, y, z);
format(bugstring, sizeof(bugstring), "%s reported a bug. Description : %s, on coordinates : X:%f, Y:%f, Z:%f\r\n", name, text, x, y, z);

Bugs = fopen("bugs.log", io_append);
fwrite(Bugs, bugstring);
fclose(Bugs);

SendClientMessage(playerid, COLOR_YELLOW, "• Thank you. You successfully reported a bug.");

return 1;
}
bugs.log
Code:
Marko repoted a bug. Description : test, on coordinates : X:1958.378295, Y:1343.613891, Z:15.374607
Ending
Sorry if its too easy to make, since this is my first tutorial i didnt want to try adding something advanced since ill surly mess up something.
Reply
#2

any feedback ? something i should remake or fix some grammar mistakes ?
Reply
#3

You should remake it.
Remake it on scratch indent it properly.

You know why?

There is some beginners reading this.
And they might get loose indentation warning.
So i recommend you to remake it with proper indentation.

Anyway, 5/10
Reply
#4

Good Tutorial ..
Reply
#5

indentations removed
Reply
#6

Quote:
Originally Posted by Romel
View Post
You should remake it.
Remake it on scratch indent it properly.

You know why?

There is some beginners reading this.
And they might get loose indentation warning.
So i recommend you to remake it with proper indentation.

Anyway, 5/10
Why would he completely remake it? The only thing I see wrong indentation wise is his returns, which can be easily tweaked.

OT: Good tutorial, easy, simple and to the point. Here, have some reputation as a gift.
Reply
#7

Wat ??
Reply
#8

Good tut
Reply
#9

Quote:
Originally Posted by 2KY
View Post
OT: Good tutorial, easy, simple and to the point. Here, have some reputation as a gift.
thanks

Quote:
Originally Posted by Jeth
View Post
Good tut
ty
Reply
#10

Code:
'Player has reported a bug. Desc. : {Text } , At the Coordinates of :'
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)