View Single Post
Lolz0r
Veteran Member
Join Date: Nov 2010
Location: Balgaria
Old 03-24-2015 , 11:58   Re: [Request] Report system
Reply With Quote #20

Okay HamletEagle, I understood.

Try this, with color :

PHP Code:
/*
    Copyleft 2015 @ HamletEagle

    ReportsSystem is free software;
    you can redistribute it and/or modify it under the terms of the
    GNU General Public License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ReportsSystem; if not, write to the
    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.
*/

#include <amxmodx>
#include <amxmisc>
#include <chatcolor>

#define PluginName    "Reports System"
#define PluginVersion "1.0"
#define PluginAuthor  "HamletEagle"

enum _:ReportData
{
    
ReporterName[32],
    
ReportedName[32],
    
Reason[128]
}

enum _:Mode
{
    
ModeReasons,
    
ModeReports
}

const 
AdminFlag ADMIN_BAN

new Array:ArrayReasons
new Array:ArrayReports

new ReportedPlayer[33]
new 
ConfigsDirPath[80]
new 
ConfigFilePath[128]

public 
plugin_init()
{
    
register_plugin
    

        .
plugin_name PluginName,
        .
version     PluginVersion,
        .
author      PluginAuthor
    
)
    
    
register_clcmd("say /report""ClientCommand_Report")
    
register_clcmd("say_team /report""ClientCommand_Report")
    
register_concmd("amx_showreports""ClientCommand_ShowReports"AdminFlag)
    
register_concmd("amx_solvereport""ClientCommand_SolveReport"AdminFlag)
    
register_concmd("amx_clearreports""ClientCommand_ClearReports"AdminFlag)
    
    
ArrayReasons ArrayCreate(128)
    
ArrayReports ArrayCreate(ReportData)
    
    
get_configsdir(ConfigsDirPathcharsmax(ConfigsDirPath))
    
ParseReasonsFile()
    
ParseReportsFile()
}

public 
plugin_end()
{
    
AddReportsToFile()
    
ArrayDestroy(ArrayReasons)
    
ArrayDestroy(ArrayReports)
}

ParseReasonsFile()
{
    new const 
ReasonsFile[] = "report_reasons.ini"
    
formatex(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigsDirPathReasonsFile)
    
ReadFile(ConfigFilePathModeReasons)
}

ParseReportsFile()
{
    new const 
ReportsFile[] = "reports_list.ini"
    
formatex(ConfigFilePathcharsmax(ConfigFilePath), "%s/%s"ConfigsDirPathReportsFile)
    
ReadFile(ConfigFilePathModeReports)
}

AddReportsToFile()
{
    if(
file_exists(ConfigFilePath))
    {
        
delete_file(ConfigFilePath)
    }
    
    
server_print("Path: %s"ConfigFilePath)
    new 
FilePointer fopen(ConfigFilePath"wt"), Data[ReportData]
    if(
FilePointer)
    {
        new 
Size ArraySize(ArrayReports)
        for(new 
iSizei++)
        {
            
ArrayGetArray(ArrayReportsiData)
            
server_print"Get: %s %s %s"Data[ReporterName], Data[ReportedName], Data[Reason])
            
fprintf(FilePointer"%s %s %s^n"Data[ReporterName], Data[ReportedName], Data[Reason])
        }
        
fclose(FilePointer)
    }
}

ReadFile(File[], Mod)
{
    new 
FilePointer fopen(File"rt")
    if(
FilePointer)
    {
        new 
FileData[128], Data[ReportData]
        while(!
feof(FilePointer))
        {
            
fgets(FilePointerFileDatacharsmax(FileData))
            
trim(FileData)
            
            if(!
FileData[0] || FileData[0] == ';' || FileData[0] == '#' || FileData[0] == '/')
            {
                continue
            }
           
server_print("Reading from file: %s"FileData)
            switch(
Mod)
            {
                case 
ModeReasons:
                {
                    
server_print("Pushing to array")
                    
ArrayPushString(ArrayReasonsFileData)
                }
                case 
ModeReports:
                {
                    
parse
                    
(
                        
FileData
                        
Data[ReporterName], charsmax(Data[ReporterName]), 
                        
Data[ReportedName], charsmax(Data[ReportedName]),
                        
Data[Reason      ], charsmax(Data[Reason      ])
                    )
                    
                    
ArrayPushArray(ArrayReportsData)
                }
            }
        }
    }    
}

public 
ClientCommand_Report(id)
{
    new 
ReportMenu menu_create("Report:""HandleReportMenu")

    new 
Players[32], PlayersNumindex
    get_players
(PlayersPlayersNum)

    new 
PlayerName[32], UserId[6]
    for(new 
i<= PlayersNumi++)
    {
        
index Players[i]
        
get_user_name(indexPlayerNamecharsmax(PlayerName))
        
num_to_str(get_user_userid(index), UserIdcharsmax(UserId))

        
menu_additem(ReportMenuPlayerNameUserId0)
    }

    
menu_display(idReportMenu0)
}

public 
ClientCommand_ShowReports(idlevelcid)
{
    if(!
cmd_access(idlevelcid0))
    {
        return 
1
    
}
    
    new 
Size ArraySize(ArrayReports), Data[ReportData]
    if(!
Size)
    {
        
console_print(id"There are no reports open")
    }
    else
    {
        for(new 
iSizei++)
        {
            
ArrayGetArray(ArrayReportsiData)
            
console_print(id"[ %i ]Reporter: %s^nReported: %s^nReason:%s",iData[ReporterName], Data[ReportedName], Data[Reason])
            
console_print(id"=========================================")
        }
        
console_print(id"Write amx_solvereport report_number to close it")
    }
    return 
1
}

public 
ClientCommand_SolveReport(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
    {
        return 
1
    
}
    
    new 
Argument[5], Data[ReportData], ArrayEntrySize ArraySize(ArrayReports)
    
read_argv(1Argumentcharsmax(Argument))
    
    
ArrayEntry str_to_num(Argument)
    if(
ArrayEntry >= Size || ArrayEntry 0)
    {
        
console_print(id"Report number is invalid. Valid range: 0 - %i"Size)
    }
    else
    {
        
ArrayGetArray(ArrayReportsArrayEntryData)
        
console_print(id"You closed the report with number %i"ArrayEntry)
        
client_print_color(00"^4[Darknezz-zone] ^3%s ^1reported ^3%s ^1for ^3%s. ^1Report is now closed."Data[ReporterName], Data[ReportedName], Data[Reason])
    
        
ArrayDeleteItem(ArrayReportsArrayEntry)
    }
    return 
1
}

public 
ClientCommand_ClearReports(idlevelcid)
{
    if(!
cmd_access(idlevelcid1))
    {
        return 
1
    
}
    
    
ArrayClear(ArrayReports)
    
console_print(id"You cleared all the reports")
    return 
1
}

public 
HandleReportMenu(idReportMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(ReportMenu)
        return 
    }

    new 
UserId[6], Name[32], AccessCallBack
    menu_item_getinfo
(ReportMenuitemAccessUserIdcharsmax(UserId), Namecharsmax(Name), CallBack)

    new 
IntUserId str_to_num(UserId)
    new 
Target find_player("k"IntUserId//get reported player index

    
if(Target)
    {
        
ReportedPlayer[id] = Target
        BuildReasonsMenu
(id)
    }
    else
    {
        
client_print_color(idid"^4[Darknezz-zone] ^1Target could not be found ^3%s."Name)
    }

    
menu_destroy(ReportMenu)
}

BuildReasonsMenu(id)
{
    new 
ReasonsMenu menu_create("Select a reason""HandleReasonsMenu")
    
    new 
Size ArraySize(ArrayReasons), HandleReason[128]
    for(new 
iSizei++)
    {
        
ArrayGetString(ArrayReasonsiHandleReasoncharsmax(HandleReason))
        
menu_additem(ReasonsMenuHandleReason""0)
    }
    
menu_display(idReasonsMenu0)
}

public 
HandleReasonsMenu(idReasonsMenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(ReasonsMenu)
        return 
    }
    
    
//Get the reason for reporting
    
new HandleReason[128]
    
ArrayGetString(ArrayReasonsitemHandleReasoncharsmax(HandleReason))
    
    
AddReport(idReportedPlayer[id], HandleReason)
    
    
client_print_color(idid"^4[Darknezz-zone] ^1Report was succesfully sent.")
    
menu_destroy(ReasonsMenu)
}

AddReport(idTarget, const HandleReason[])
{
    new 
Data[ReportData]
    
get_user_name(idData[ReporterName], charsmax(Data[ReporterName]))
    
get_user_name(TargetData[ReportedName], charsmax(Data[ReportedName]))
    
copy(Data[Reason], charsmax(Data[Reason]), HandleReason)
    
ArrayPushArray(ArrayReportsData)
    
    new 
Players[32], Numindex
    get_players
(PlayersNum"c")
    for(new 
iNumi++)
    {
        
index Players[i]
        if(
get_user_flags(index) & AdminFlag)
        {
            
client_print_color(indexindex"^4[Darknezz-zone] ^1A new report was send.")
        }
    }

I use only this for color chat messages :
https://forums.alliedmods.net/showthread.php?t=94960

just install the plugin.

Last edited by Lolz0r; 03-24-2015 at 11:59.
Lolz0r is offline