Raised This Month: $ Target: $400
 0% 

[HELP] Optimizing small code. Days Changer.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Mrki_Drakula
Senior Member
Join Date: Jun 2011
Location: Serbia
Old 09-11-2012 , 11:38   [HELP] Optimizing small code. Days Changer.
Reply With Quote #1

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?

Last edited by Mrki_Drakula; 09-12-2012 at 06:38. Reason: Grammar...
Mrki_Drakula is offline
Send a message via MSN to Mrki_Drakula Send a message via Skype™ to Mrki_Drakula
 



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

Forum Jump


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


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