28.08.2012, 21:16
(
Last edited by MarkoN; 01/09/2012 at 12:27 AM.
Reason: indentation removal
)
Bug reporting + log
IntroHi, 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 needed
- a_samp
- sscanf2 - https://sampforum.blast.hk/showthread.php?tid=120356
- zcmd - https://sampforum.blast.hk/showthread.php?tid=91354
First we will need to add the zcmd header.
pawn Code:
CMD:reportbug(playerid, params[])
{
return 1;
}
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;
}
- 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
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;
}
- 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...
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;
}
- GetPlayerName(playerid, name, sizeof(name)); - Gets the players name (finished)
- GetPlayerPos(playerid, x, y, z); - Gets the players position (finished)
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;
}
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;
}
- 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
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;
}
Code:
Marko repoted a bug. Description : test, on coordinates : X:1958.378295, Y:1343.613891, Z:15.374607
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.