AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Log code fails (https://forums.alliedmods.net/showthread.php?t=162431)

meTaLiCroSS 07-19-2011 02:17

Log code fails
 
PHP Code:

    new iszLogpath[64], szMapname[32], szBuffer[128]
    
get_mapname(szMapnamecharsmax(szMapname))
    
get_time("%Y%m%d"szBuffercharsmax(szBuffer))
    
get_localinfo("amxx_logs"szLogpathcharsmax(szLogpath))
    
    do
    {
        if(
iformatex(g_szMapLogNamecharsmax(g_szMapLogName), "%s/maplogs/%s_%s_%d.log"szLogpathszMapnameszBufferi)
        else  
formatex(g_szMapLogNamecharsmax(g_szMapLogName), "%s/maplogs/%s_%s.log"szLogpathszMapnameszBuffer)
        
        
i++
    }
    while(
file_exists(g_szMapLogName))
    
    
log_to_file(g_szMapLogName"Map Started ^"%s^""szMapname

What's wrong with that code? It doesn't creates the path and the logfile :/ i'm doing this code on plugin_precache, and I don't know which is the trouble..

Arkshine 07-19-2011 04:31

Re: Log code fails
 
Maybe because the path maplogs has to be created before. (either manually, either using mkdir)

meTaLiCroSS 07-19-2011 15:08

Re: Log code fails
 
Quote:

Originally Posted by Arkshine (Post 1513619)
Maybe because the path maplogs has to be created before. (either manually, either using mkdir)

It worked, thanks

For anyone who wants the fixed code:

PHP Code:

    new iszLogpath[64], szMapname[32], szBuffer[128]
    
get_mapname(szMapnamecharsmax(szMapname))
    
get_time("%Y%m%d"szBuffercharsmax(szBuffer))
    
get_localinfo("amxx_basedir"szLogpathcharsmax(szLogpath))
    
add(szLogpathcharsmax(szLogpath), "/maplogs")
    
    if(!
dir_exists(szLogpath)) 
        
mkdir(szLogpath)
    
    do
    {
        if(
iformatex(g_szMapLogNamecharsmax(g_szMapLogName), "%s/%s_%s(%d).log"szLogpathszMapnameszBufferi+1)
        else  
formatex(g_szMapLogNamecharsmax(g_szMapLogName), "%s/%s_%s.log"szLogpathszMapnameszBuffer)
        
        
i++
    }
    while(
file_exists(g_szMapLogName))
    
    
log_to_file(g_szMapLogName"Map Started ^"%s^""szMapname

This will create a log for everymap that you play on your server.

Exolent[jNr] 07-19-2011 15:26

Re: Log code fails
 
Quote:

Originally Posted by meTaLiCroSS (Post 1514027)
This will create a log for everymap that you play on your server.

But nothing is logged to it except that the map started.

meTaLiCroSS 07-19-2011 15:29

Re: Log code fails
 
Quote:

Originally Posted by Exolent[jNr] (Post 1514039)
But nothing is logged to it except that the map started.

That's logic. You can use this for everthing that you want, lol. In my case, I did this for logging certain functions that can crash my server, and do a log before executing it.


All times are GMT -4. The time now is 01:08.

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