AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Mistake in log system (https://forums.alliedmods.net/showthread.php?t=308639)

PurposeLessx 06-28-2018 06:30

Mistake in log system
 
Hey, I made a log system for people attacking server. I will use "amx_cvar log_kontrol 1"
and everyone's commands will be logged. But not logged.

Spoiler

fysiks 06-28-2018 21:38

Re: Mistake in log system
 
Quote:

Originally Posted by PurposeLessx (Post 2599676)
But not logged.

You should probably elaborate on what exactly that means. Did you try to do any debugging yourself?

PurposeLessx 06-29-2018 04:02

Re: Mistake in log system
 
I am explaining how this plugin works. I will use amx_log purposeless or amx_cvar log_kontrol "1"
and the commands of purposeless or each person will be seen in the
"addons/amxmodx/purpo_attack_log/%s.log" but there is a mistake and not seen

Kushfield 06-30-2018 04:14

Re: Mistake in log system
 
I see 2 things wrong here, perhaps that's why:
PHP Code:

        new tarih[64];
        
get_time("%m/%d/%Y"tarihcharsmax(tarih));
        
log_to_file("addons/amxmodx/purpo_attack_log/%s.log""%s"tariharg); 

1. You're trying to use slashes in filename, which is not possible, since they are used for separating directories.
2. You're trying to format both the file name and the message in log_to_file (?), although it's possible only for the message.

Try replacing it with this:
PHP Code:

        new tarih[64];
        
get_time("addons/amxmodx/purpo_attack_log/%Y-%m-%d.log"tarihcharsmax(tarih));
        
log_to_file(tariharg); 


fysiks 06-30-2018 11:35

Re: Mistake in log system
 
Quote:

Originally Posted by PurposeLessx (Post 2599809)
I am explaining how this plugin works.

I wasn't asking what you are trying to do. I was asking you to explain what part isn't working. That means you need to tell us what exactly is happening when you run your plugin. Is there any errors in the logs? Does the file get created? Does it write anything to the file? etc.

Quote:

Originally Posted by Kushfield (Post 2600008)
1. You're trying to use slashes in filename, which is not possible, since they are used for separating directories.

That is wrong. The function requires the full filepath relative to the root of the server. So, having slashes in there is correct for any file that is not at the root.

PurposeLessx 06-30-2018 11:42

Re: Mistake in log system
 
Can you correct my plugin? I am not pretty sure where is mistake. I did what Kushfield say but not working.
Not logging in file.

fysiks 06-30-2018 11:55

Re: Mistake in log system
 
Quote:

Originally Posted by PurposeLessx (Post 2600110)
Can you correct my plugin?

No. This is the Scripting Help section therefore, I'm trying to help you fix your own plugin. However, you are not answering my questions so I can't really help you that much.

Since you are very inexperienced, you need to start by testing smaller parts of your code by itself. First test being able to write to a file using log_to_file() to make sure that you can write to the file. Then, once you've verified that you can successfully do that, add some more complicated parts.

Kushfield 06-30-2018 15:20

Re: Mistake in log system
 
Quote:

Originally Posted by fysiks (Post 2600104)
That is wrong. The function requires the full filepath relative to the root of the server. So, having slashes in there is correct for any file that is not at the root.

That's what I was saying - slashes are for separating directories (to define the path to the file), but he was trying to use slashes in the name of the file itself, not just the path to it. Unless of course the intention was to have a log named according to current year in a directory named after the current day which is in another directory named after the current month. This, however, makes no sense, at least not in that order, and AFAIK, you'd need to separately create each directory before you can create files in it.

EDIT:
This reminds me: PurposeLessx, have you created the directory "addons/amxmodx/purpo_attack_log/" ?
Other than that, I'm afraid I'm all out of ideas, at least until you answer the questions fysiks asked you.

maqi 06-30-2018 15:33

Re: Mistake in log system
 
He needs to learn to debug code instead of asking "code not work" every time.


I don't think this works like that, i might be wrong
Code:
log_to_file("addons/amxmodx/purpo_attack_log/%s.log", "%s", name, arg)

PurposeLessx 07-01-2018 08:45

Re: Mistake in log system
 
I changed it but still no log anywhere.

PHP Code:

#include <amxmodx>
#include <amxmisc>

new log_kontrol;
new 
bool:g_kontrol[33];

public 
plugin_init() {
    
register_plugin("log""1.0""PurposeLess");
    
    
bind_pcvar_num(create_cvar("log_kontrol""0"), log_kontrol);
    
    
register_concmd("amx_log""admin_log"ADMIN_RCON"<nick> <[0-1]>");
}

public 
client_command(id)
{
    if(
g_kontrol[id])
    {
        new 
arg[32];
        
read_argv(1argcharsmax(arg));
        
        if(
equali(arg" ") || equali(arg"") || is_str_num(arg))
        {
            
read_args(argcharsmax(arg));
            
            if(
equali(arg" ") || equali(arg"")) return;
        }
        
        new 
name[32], tarih[64];
        
get_user_name(idnamecharsmax(name));
        
get_time("addons/amxmodx/purpo_attack_log/%Y-%m-%d.log"tarihcharsmax(tarih));
        
log_to_file(tarih"[%s] - %s"namearg);
        return;
    }

    if(
log_kontrol)
    {
        new 
arg[32];
        
read_argv(1argcharsmax(arg));
        
        if(
equali(arg" ") || equali(arg"") || is_str_num(arg))
        {
            
read_args(argcharsmax(arg));
            
            if(
equali(arg" ") || equali(arg"")) return;
        }

        new 
tarih[64];
        
get_time("addons/amxmodx/purpo_attack_log/%Y-%m-%d.log"tarihcharsmax(tarih));
        
log_to_file(tariharg);  
    }
}

public 
admin_log(idlevelcid)
{
    if(!
cmd_access(idlevelcid2))
    {
        return 
PLUGIN_HANDLED;
    }
    new 
arg[32], arg2[32];
    
read_argv(1argcharsmax(arg));
    
read_argv(2arg2charsmax(arg2));
    
    new 
player cmd_target(idarg);
    if(!
player) return PLUGIN_HANDLED;
    
    switch(
str_to_num(arg2))
    {
        case 
0: { g_kontrol[player] = false;}
        case 
1: { g_kontrol[player] = true;}
    }
    
    
console_print(id"Kontrol : %s"g_kontrol[player] ? "on":"off");
    return 
PLUGIN_HANDLED;




All times are GMT -4. The time now is 12:33.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.