Gamemode by include
#25

Quote:
Originally Posted by Dayrion
View Post
I've 2 connection's type : when i'm on local (OnTestServer) and when I'm not. I'm using OnTestServer in differents commands like /ban, etc..
For this:
Code:
    - Config ( Core )
        - base.pwn ( Global Definitions, MySQL, Server Settings )
        - macros.pwn ( Global Macros for shortcuts like FUNCTION: and PUBLIC: )
        - plugins.pwn ( Global Plugin Definitions )
I'm doing like this:
"../core/configuration.inc" (GM's inititialization)
"../core/MySQLConnections.inc" (Creating table, connection to mysql, etc...)
"../core/base.inc" (Macros and constants)
That's good?

Annnd..
I'm trying a new thing. It's for creating logs (from configuration.inc):
PHP Code:
new 
    
Log_Level:Log_Server,
    ...;
enum Log_Level:LogType
{
    
NOTHING,
    
COMMANDS,
    
TCHAT,
    
FULL_LOG NOTHING COMMANDS TCHAT
};
stock CreateServerLog(Log_Level:Log_Serv Log_Level:FULL_LOG)
{
    
Log_Server Log_Serv;
    if(
_:Log_Serv == NOTHING)
        return print(
"[SERVER] Aucun log crйй."), 1;
    static
        
string[120],
        
hour,
        
minu,
        
sec,
        
day,
        
month,
        
year;
    
Get@SetWorldTime(hourminusec);
    
getdate(yearmonthday);
    
format(stringsizeof(string), "-------- Dйbut -------- [%02i/%02i/%02i] - %02ih %02imin %02is."daymonthyearhourminusec);
    
WriteLogs("AllCommands.txt"string);
    print(
"[SERVER] Logs configurйs.")
    return 
1;
}
stock Get@SetWorldTime(&hour = -1, &minutes = -1, &seconds = -1)
{
    
gettime(hourminusec);
    
SetWorldTime(hour);

Log_Server is gonna be used when writing logs.

EDIT: Write logs function
PHP Code:
WriteLogs(file[70], const reason[], playerid INVALID_PLAYER_ID)
{
    if(!
_:Log_Server)
        return 
1;
    static     
day,
            
month,
            
hour,
            
minute,
            
seconde,
            
year;
    static    
stringW[190];
    if(
strfind(file".txt"false0) == -1format(filesizeof(file), "%s.txt"file);
    new 
File:pos=fopen(fileio_append);
    if(!
pos)
    {
        
printf("[Server] Write Logs Error | Reason : pos=fopen Error | File : '%s' | Reason: '%s'"filereason);
        
SendMessageToAdmins(RED"[Server] "SAUMON_U" Une erreur est survenue dans les logs. Merci de vйrifier ceux-ci!");
        
SendMessageToAdmins(RED"[Server] "SAUMON_U"Fichier : '%s' | Contenus : '%s'"filereason);
        return 
1;
    } 
    
    
gettime(hourminuteseconde);
    
getdate(yearmonthday);
    if(!
strcmp(file"AllCommands.txt") && _:Log_Server == L_COMMANDS)
        
format(stringW,sizeof(stringW),"\r\n[%i] [%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"CmdID++, daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    else if(!
strcmp(file"AllTChat.txt") && _:Log_Server == L_TCHAT)
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s (Player #%i) » '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"p_NameOff{playerid}, reason);
    else if(
_:Log_Server == L_TCHAT)
        
format(stringW,sizeof(stringW),"\r\n[%02i/%02i/%02i] %02i:%02i:%02i %s | '%s'"daymonthyearhourminutesecondeplayerid != INVALID_PLAYER_ID GetName(playeridtrue) : "ALL"reason);
    
fwrite(pos,stringW);
    
fclose(pos);
    return 
1;

I would keep your structure either camel case, or lowercase as mixing the two is a bad idea ( in your case anyway ).

I prefer lowercase since it just easier to read ( for me anyway ).

As for what you said, If you are able to understand it easily then you can continue the way your doing it, but for the best practices you will need to pretend your not you and you've been given this script by someone else. Then ask yourself questions like does it make sense? is it easy to follow? is it easy to add onto or modifiy?

If I was you I would follow my way, since there literally nothing to be confused about, since every is labeled based on what the file will contain.

I also see, you do not comment your code, which is poor practice, you must always comment your code, even if your the only one modifying it.

If you are having issue finding functions, variables, enums or callbacks. Then your structure is wrong, it must follow a path that is easy to understand.

Also I would add a file in core called database.pwn ( containing the stock functions for connecting to the db ), keep the definitions in base.pwn. Make another file for macros.pwn since these can get messy to look at and also can be long as well as you having many of them. So rename MysqlConnections.pwn (it looks ugly) to database.pwn.
Reply


Messages In This Thread
Gamemode by include - by Dayrion - 22.02.2017, 12:48
Re: Gamemode by include - by jlalt - 22.02.2017, 12:53
Re: Gamemode by include - by Dayrion - 22.02.2017, 13:17
Re: Gamemode by include - by jlalt - 22.02.2017, 13:25
Re: Gamemode by include - by Dayrion - 22.02.2017, 14:52
Re: Gamemode by include - by jlalt - 22.02.2017, 14:57
Re: Gamemode by include - by PrO.GameR - 22.02.2017, 19:44
Re: Gamemode by include - by iKarim - 23.02.2017, 06:13
Re: Gamemode by include - by Sew_Sumi - 23.02.2017, 06:20
Re: Gamemode by include - by Yashas - 23.02.2017, 06:52
Re: Gamemode by include - by iKarim - 23.02.2017, 19:41
Re: Gamemode by include - by Dayrion - 23.02.2017, 23:47
Re: Gamemode by include - by Sew_Sumi - 24.02.2017, 00:50
Re: Gamemode by include - by iKarim - 24.02.2017, 05:17
Re: Gamemode by include - by DRIFT_HUNTER - 24.02.2017, 05:24
Re: Gamemode by include - by Sew_Sumi - 24.02.2017, 05:35
Re: Gamemode by include - by Gammix - 24.02.2017, 07:34
Re: Gamemode by include - by Dayrion - 24.02.2017, 10:21
Re: Gamemode by include - by DRIFT_HUNTER - 24.02.2017, 14:28
Re: Gamemode by include - by patrickgtr - 24.02.2017, 14:32
Re: Gamemode by include - by iKarim - 24.02.2017, 14:59
Re: Gamemode by include - by Dayrion - 01.03.2017, 22:27
Re: Gamemode by include - by azzerking - 01.03.2017, 23:41
Re: Gamemode by include - by Dayrion - 02.03.2017, 12:52
Re: Gamemode by include - by azzerking - 02.03.2017, 18:00
Re: Gamemode by include - by renatog - 02.03.2017, 19:50
Re: Gamemode by include - by Dayrion - 02.03.2017, 20:15
Re: Gamemode by include - by renatog - 02.03.2017, 20:58
Re: Gamemode by include - by Mauzen - 03.03.2017, 03:46
Re: Gamemode by include - by Y_Less - 03.03.2017, 10:25
Re: Gamemode by include - by RyderX - 03.03.2017, 10:49

Forum Jump:


Users browsing this thread: 1 Guest(s)