[Tutorial] Report Sytem with report calling
#1

Introduction
You might wonder why is this different than any other system? Well simply because this system allows administrators to call the actual report and see the pending reports with remaining time and so on.

Stuff Needed
Now as we have created the basics of our tutorial lets move on. For this tutorial I strongly recommend you to use ZCMD which can be found here https://sampforum.blast.hk/showthread.php?tid=91354
Besides that you will have to download sscanf https://sampforum.blast.hk/showthread.php?tid=570927
You will also need foreach https://sampforum.blast.hk/showthread.php?tid=570868


Coding
Id like to skip few lines here and jump straight to coding the system. This system is not recommended for newbie scripters but if you are one, Ill do my best to explain this entirely. For this tutorial we will use "IsPlayerAdmin" (default SA:MP administrator detection for RCON admins) if you have your own admin system or simply you dont use RCON administrator just change the lines of IsRconAdmin to your admin variables.


Before we even start coding this, we need some basic code stocks so we can check for stuff easier way.

PHP код:
stock GetName(playerid//we are creating a stock function which we will use to get player name
{
    new 
szName[MAX_PLAYER_NAME]; //we are creating new varliable where we will store the name
    
GetPlayerName(playeridszNamesizeof(szName)); //We are getting the player name
    
return szName//we will return the player name when this is called
}
stock SendAdminMessage(message[]) //We are creating a stock function which we will use later on to send message to all administrators
{
    foreach(new 
iPlayer//We are going thru ALL online players to find matching one
    
{
        if(
IsPlayerAdmin(playerid)) //if they are Admin they match what we are looking for
        
{
            
SendClientMessage(i,ORANGES,message); //If there is a match for what we are looking for, we will send them an admin message
        
}
    }
    return 
1;


On the very top of your script where you define everything add this code.
PHP код:
new ReportText[MAX_PLAYERS][180], //We will use this to store the playerid who made the report and also the report text.
    
CreatedReport[MAX_PLAYERS]; //We are using this to check later on if the player made the report. We will store playerid inside MAX_PLAYERS 
Now we want to add the command (read the comments tag for explanation)
PHP код:
CMD:report(playerid,params[]) //We are defining our command name and its parameters.
//opening the code
    
new text[128], //now we are making 2 variables, 1 is text which we will need to detect players input for the text, to check if the command has any parameters
        
string[128]; //We are using the string to store their report message, aka their input/parameters from this comman
    
if(sscanf(params,"s[128]",text)) //Now we are checking if their command is empty or not. They have to enter the text of their message
        
return SendClientMessage(playerid,COLOR_RED,"Usage: /report [playerid] [reason]"); //Now if they have entered wrong parameters, we will tell them what parameters they have to enter into the command
        
    
if(CreatedReport[playerid] == 1//We are checking if they have already made the report
        
return SendClientMessage(playerid,COLOR_RED,"You can only create 1 report at the time!"); //we are telling the player that they have already made a report and they cannot make another one.
    
CreatedReport[playerid] = 1//We are saving CreatedReport to 1 so we know that that player made a report
    
format(string,sizeof(string),"Report from (ID:%d)%s: %s",playerid,GetName(playerid),text); //We are formating a string that we want to send to all of our administrators
    
SendAdminMessage(string); //We are sending the message to all administrators currently online
    
strcpy(ReportText[playerid],string,180); //Well now this is the hard part. What we are basically doing is that we are storing our string into ReportText so we can later on view it
    
    
SendClientMessage(playerid,COLOR_GREEN,"Your report was sent to the administration team."); //We are informing the player that their report was sucessfull! HOORAY!
    
return true//We are stopping the code here
//We are closing the code 
Now we will create a simple command to call the report
PHP код:
CMD:cr(playerid,params[]) //we are defining our command here, we will call it "cr" short from /callreport
//opening the code
    
new otherplayer//We will use this to check for other player, player that made the report previously aka playerid of some another player
        
string[128]; //we are making a string so we can later on inform administrators that someone made a report
        
    
if(!IsPlayerAdmin(playerid)) //This is reverse from IsPlayerAdmin, so we are basically checking If they are not admin by inserting ! at the beggining of the code
        
return SendClientMessage(playerid,COLOR_RED,"You are not an admin"); //We are informing the player that they are not a administrator and that they cannot use this command
    
if(sscanf(params,"u",otherplayer)) //We are checking if our administrator inserted ID/Part of their name of the person of which their report they want to call
        
return SendClientMessage(playerid,COLOR_RED,"Usage: /cr [playerid]"); //If they havent inserted the ID or used wrong parameters, we will tell them how to use the command
        
    
if(otherplayer != INVALID_PLAYER_ID//we are checking if the other player is even connected!
        
return SendClientMessage(playerid,COLOR_RED,"Invalid player. Try again"); //We are letting the player know that the person that they are trying to call report from is not online/connected
    
if(CreatedReport[otherplayer] == 0//Now we will simply check if the player that they are trying to call report from is even online.
        
return SendClientMessage(playerid,COLOR_RED,"That player havent created any reports"); //If the other player is not online we will let them know
        
    
CreatedReport[otherplayer] = 0//Now, they have entered the right id of the player, and they are calling their report, but first we want to let the script know that we have called their report and they no longer have a create report
    
format(string,sizeof(string),"{E81CC9}[Admin Warning] %s has just called %s's report",GetName(playerid),GetName(otherplayer)); //We are formating a string in which we will tell all other administrators that we have called someones report
    
SendAdminMessage(string); //Sending a message to all online administrators
    
    
format(string,sizeof(string),"%s %s has called your report. Please wait until he contacts you",GetName(playerid)); //we are letting the player know that someone called their report and someone will help them soon
    
SendClientMessage(otherplayer,COLOR_GREEN,string); //We are letting that player know that we called their report by informing him with a message!
    
return true;//stopping the code
}//Closing the code 


Now lets make a simple command to view all reports!
PHP код:
CMD:repq(playerid,params[]) //we are formating our command and naming it "Repq" which should show us all reports that are avalaible at the moment
//opening the code
    
if(!IsPlayerAdmin(playerid)) //If they are not an admin, same like before, reverse checking
        
return SendClientMessage(playerid,COLOR_RED,"You are not an admin"); //Now we will let me know that only admins can use this command
        
    
foreach(new iPlayer//ALready so heavy part, we are looping thru all players until we find all of them who made the report. We will store their ID inside "i"
    
//continuing  the code
        
if(CreatedReport[i] >= 1//if some player made the report we will continue
        
//continung the code
            
SendClientMessage(playerid,COLOR_RED,ReportText[i]); //If there are any playeers that fit our match we will send the administrator a message containing all the reports that have been created!
        
//Closing the code
    
}//Closing the code
    
return true//stopping the code
//closing the code 

Code Efficiency
If you have anything to improve the tutorial or the code itself please let me know. I dont personally worry about the efficiency that much but I appreciate all the help I can get. Thanks!

Credits
Zeex - ZCMD
SSCANF - ******
Foreach - ******
Reply
#2

sorry but you are using old version of foreach and new way is

Код:
foreach(new i: Player)
Quote:
Originally Posted by TwinkiDaBoss
Посмотреть сообщение
I dont personally worry about the efficiency that much
Efficiency matter. It show your skill. I always wonder how I improve my code.


O.T Not Bad. Keep it up.
Reply
#3

Quote:
Originally Posted by Humza
Посмотреть сообщение
sorry but you are using old version of foreach and new way is

Код:
foreach(new i: Player)

Efficiency matter. It show your skill. I always wonder how I improve my code.


O.T Not Bad. Keep it up.
Depends really. Depends what you consider as skill, but to be honest, Ive made many scripts so far, and I dont claim im somewhat great scripter or anything but they all seemed to work with 30-40+ players so yeah.
I agree with you, you should always think about how to improve your code to improve yourself in this way and well thats could be fun. And thanks for reminding me about the foreach version haha, I totally overlooked that! Ill fix it
Reply
#4

Badly to return arrays for the stack!

Код:
stock GetName(playerid)
{ 
    new szName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, szName, sizeof(szName));
    return szName;
}
And

PHP код:
stock SendAdminMessage(message[144]) // why not? :D

    foreach(new 
iPlayer)
        if (
IsPlayerAdmin(i)) // if player is admin
            
SendClientMessage(iORANGESmessage);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)