AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Optimizing small code. Days Changer. (https://forums.alliedmods.net/showthread.php?t=195780)

Mrki_Drakula 09-11-2012 11:38

[HELP] Optimizing small code. Days Changer.
 
Hello folks,
Here's my code.

PHP Code:


#include <amxmodx>
#include <amxmisc>
#include <colorchat>

#define PLUGIN "Jailbreak Day Plugin"
#define VERSION "0.1"
#define AUTHOR "Mrki_Drakula"

new g_Day                    // Which Day is today?
new g_MondayType                // Which Day Type is today?

public plugin_init()
 {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_logevent("round_start"2"0=World triggered""1=Round_Start")
    
    
register_clcmd("say /days""Server_Days")
}

public 
round_start()
{
    
g_Day++; 
    if(
g_Day == 7)
    {
        
g_Day 0
    
}
}

public 
Server_Days(id)
{
    if(
is_user_admin(id))
    {
        static 
Item[64]
        
        new 
Menu menu_create("Edit Days:""Sub_Days")
        
        if(
g_MondayType == 0)
        {
            
formatex(Itemcharsmax(Item),"Monday - Normal Day" )
            
menu_additem(MenuItem"1")
        }
        if(
g_MondayType == 1)
        {
            
formatex(Itemcharsmax(Item),"Monday - Free Day" )
            
menu_additem(MenuItem"1")
        }
    }
}

public 
Sub_Days(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            if(
g_Day == 0)
            {
                
ColorChat(idTEAM_COLOR"^4Today ^3is ^4Monday^1! ^3You are not allowed to change it^1, ^3until it ends^1!")
            }
            else
            {
                
Server_ChangeMonday(id)
                return 
PLUGIN_HANDLED;
            }
        }
    }
    return 
PLUGIN_CONTINUE
}

public 
Server_ChangeMonday(id)
{
    if(!
is_user_connected(id))
        return 
PLUGIN_HANDLED
    
    
new Menu menu_create("Change Monday Day Type:""Sub_ChangeMonday")
    
    
menu_additem(Menu"Normal Day""1")
    
    
menu_additem(Menu"Free Day""2")
    
    
menu_display(idMenu)
    
    return 
PLUGIN_CONTINUE
}

public 
Sub_ChangeMonday(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            if(
g_MondayType == 0)
            {
                
ColorChat(idTEAM_COLOR"^4Monday^3 is already set as a ^4Normal Day^1!")
            }
            else
            {
                
g_MondayType 0
                ColorChat
(idTEAM_COLOR"^3You just set ^4Monday^3 as a ^4Normal Day^1!")
                return 
PLUGIN_HANDLED;
            }
        }
        case 
2:
        {
            if(
g_MondayType == 1)
            {
                
ColorChat(idTEAM_COLOR"^4Monday^3 is already set as a ^4Free Day^1!")
            }
            else
            {
                
g_MondayType 1
                ColorChat
(idTEAM_COLOR"^3You just set ^4Monday^3 as a ^4Free Day^1!")
                return 
PLUGIN_HANDLED;
            }
        }
    }
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE;


I've got just one simple question. Is there any different way, to code this, since i need to redo this for every day, and its going to take a lot of space. Note, this works (probably), but i need to ask you, is there any way to optimize this code?

Mrki_Drakula 09-12-2012 13:41

Re: [HELP] Optimizing small code. Days Changer.
 
Also, is there any way, to use arrays as a public variable, that can be edited through others plugins?

Liverwiz 09-12-2012 14:15

Re: [HELP] Optimizing small code. Days Changer.
 
Quote:

Originally Posted by Mrki_Drakula (Post 1797638)
Also, is there any way, to use arrays as a public variable, that can be edited through others plugins?

Natives with set/get functions.


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

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