SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/11/2019, 11:50 PM   #1
Mobtiesgangsa
Big Clucker
 
Join Date: Oct 2016
Posts: 139
Reputation: 16
Default code usage and organizing

Hello guy's i have wrote some basic code and added some define naming to the source should i incorporate the code into filterscript or stick with a gamemode management variant?

pawn Code:
#include    <a_samp>

//  Null terminated\escape string
#define     NULL                    ("\1")

//  add-define for missing features
#define     INVALID_DIALOG_ID       (-1)
#define     DIALOG_STYLE_INVALID    (-1)

//  Global timers variant position
#define     GLOBAL_TIMERS_INVALID   (-1)
#define     GLOBAL_TIMERS_ON        (1)
#define     GLOBAL_TIMERS_OFF       (0)

//  Seconds in defines
#define     ONE_SEC                 (1)


//  Pre-Hook Define for callbacks public functions
#define     callback%0(%1)          forward%0(%1);          public%0(%1)


/*#if !defined _whirlpool_included
    #include    <whirlpool>
#endif*/


#include    <izcmd>
//#include    <sscanf2>



enum // un-signet array "enumerator"
{
    DIALOG_NET_STATS,   // server-type dialogs
   
    DIALOG_PLAYER_NET_STATS, // player-type dialogs
}

enum E_PLAYER_TIMERS
{
    pnetstats,
}

new player_timers[MAX_PLAYERS][E_PLAYER_TIMERS];

//  global signet array "enumerators" for timers
enum E_GLOBAL_TIMERS
{
    netstats,
}

new timers[E_GLOBAL_TIMERS];
new netstats_playerid = INVALID_PLAYER_ID;

//----------------------------------------------------------------------------------------------------

main()
{

}

//----------------------------------------------------------------------------------------------------

public OnGameModeInit()
{
    new server_port = GetServerVarAsInt("port");
    printf("server port: %d", server_port);


    //      *   timers
    //-----------------------------
    //  (-1) into invalid timers
   
    timers[netstats] = GLOBAL_TIMERS_INVALID;

    UsePlayerPedAnims();
    DisableInteriorEnterExits();
   
    ShowPlayerDialog(INVALID_PLAYER_ID, INVALID_DIALOG_ID, DIALOG_STYLE_MSGBOX, NULL, NULL, NULL, NULL);
    return 1;
}

//----------------------------------------------------------------------------------------------------

public OnGameModeExit()
{
    if(timers[netstats] == GLOBAL_TIMERS_ON || timers[netstats] == GLOBAL_TIMERS_INVALID)
    {
        timers[netstats] = GLOBAL_TIMERS_OFF;
    }
    return 1;   // Indicates that this callback will be passed to the next filterscript.
}

//----------------------------------------------------------------------------------------------------

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(success == CMD_FAILURE) SendClientMessage(playerid, -1, "SERVER: Unknown command.");
    return CMD_SUCCESS;
}

//----------------------------------------------------------------------------------------------------

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch(dialogid)
    {
        case DIALOG_NET_STATS:
        {
            if(response == 1)
            {
                if(timers[netstats])
                {
                    KillTimer(timers[netstats]);
                    timers[netstats] = GLOBAL_TIMERS_INVALID;
                }
            }
            else
            {
                if(timers[netstats])
                {
                    KillTimer(timers[netstats]);
                    timers[netstats] = GLOBAL_TIMERS_INVALID;
                }
            }
        }
        case DIALOG_PLAYER_NET_STATS:
        {
            if(response == 1)
            {
                if(player_timers[playerid][pnetstats])
                {
                    KillTimer(player_timers[playerid][pnetstats]);
                    player_timers[playerid][pnetstats] = GLOBAL_TIMERS_INVALID;
                }
            }
            else
            {
                if(player_timers[playerid][pnetstats])
                {
                    KillTimer(player_timers[playerid][pnetstats]);
                    player_timers[playerid][pnetstats] = GLOBAL_TIMERS_INVALID;
                }
            }
        }
        default: return 0; // passed cb to other scripts (filterscripts)
    }
    return 1;   // non-passing cb to other scripts (mainly for gamemode)
}

//----------------------------------------------------------------------------------------------------

CMD:playerstats(playerid, params[])
{
    if(isnull(params))
    {
        OnPlayerStats(playerid);
        player_timers[playerid][pnetstats] = SetTimerEx("OnPlayerStats", ONE_SEC * 1000, 1, "d", playerid);
    }
    return CMD_SUCCESS;
}

CMD:serverstats(playerid, params[])
{
    if(isnull(params))
    {
        netstats_playerid = playerid;
       
        OnServerStats();
        timers[netstats] = SetTimer("OnServerStats", ONE_SEC * 1000, 1);
    }
    return CMD_SUCCESS;
}

//----------------------------------------------------------------------------------------------------

callback OnServerStats()
{
    new n_Stats[400 + 1];
    GetNetworkStats(n_Stats, 400);
    ShowPlayerDialog(netstats_playerid, DIALOG_NET_STATS, DIALOG_STYLE_MSGBOX, "Server Network", n_Stats, "Close", "");
}

//----------------------------------------------------------------------------------------------------

callback OnPlayerStats(playerid)
{
    new n_pStats[2048 + 1];
    GetPlayerNetworkStats(playerid, n_pStats, 2048);
    ShowPlayerDialog(playerid, DIALOG_PLAYER_NET_STATS, DIALOG_STYLE_MSGBOX, "Player Network", n_pStats, "close", "");
}

//----------------------------------------------------------------------------------------------------
Mobtiesgangsa is offline   Reply With Quote
Old 19/11/2019, 11:23 PM   #2
MrAuto
Little Clucker
 
Join Date: Sep 2019
Posts: 8
Reputation: 2
Default Re: code usage and organizing

It's kind of a weird question

gamemode is the main script on your server and it is required for the server to run
filterscript is part of code that you can load and unload at will, you can also have couple of them loaded in given time

also
Code:
//  Null terminated\escape string
#define     NULL                    ("\1")
this is bad practice as Null should always be 0 (\0 not \1)
MrAuto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Organizing Inventory Items MafiaOink Scripting Help 3 16/03/2018 11:40 PM
[Tutorial] SA:MP Images usage, list and usage. Partner Tutorials 23 26/03/2016 11:00 PM
Organizing The Script - Optimal Solution? RedFusion Scripting Help 2 15/10/2014 06:47 AM
How to make when using pawno and type part of the code, to show the full code ? bustern Scripting Help 10 28/08/2013 10:10 AM
[Tool/Web/Other] Code Highlighter - Highlight code to find brackets, organize code, ... Sinner Tools and Files 8 09/03/2012 02:28 PM


All times are GMT. The time now is 03:49 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.