| 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(PLUGIN, VERSION, AUTHOR) 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(Item, charsmax(Item),"Monday - Normal Day" ) menu_additem(Menu, Item, "1") } if(g_MondayType == 1) { formatex(Item, charsmax(Item),"Monday - Free Day" ) menu_additem(Menu, Item, "1") } } }
public Sub_Days(id, menu, item) { if( item == MENU_EXIT ) { menu_destroy(menu); return PLUGIN_HANDLED; } new data[6], iName[64]; new access, callback; menu_item_getinfo(menu, item, access, data,5, iName, 63, callback); new key = str_to_num(data); switch(key) { case 1: { if(g_Day == 0) { ColorChat(id, TEAM_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(id, Menu) return PLUGIN_CONTINUE }
public Sub_ChangeMonday(id, menu, item) { if( item == MENU_EXIT ) { menu_destroy(menu); return PLUGIN_HANDLED; } new data[6], iName[64]; new access, callback; menu_item_getinfo(menu, item, access, data,5, iName, 63, callback); new key = str_to_num(data); switch(key) { case 1: { if(g_MondayType == 0) { ColorChat(id, TEAM_COLOR, "^4Monday^3 is already set as a ^4Normal Day^1!") } else { g_MondayType = 0 ColorChat(id, TEAM_COLOR, "^3You just set ^4Monday^3 as a ^4Normal Day^1!") return PLUGIN_HANDLED; } } case 2: { if(g_MondayType == 1) { ColorChat(id, TEAM_COLOR, "^4Monday^3 is already set as a ^4Free Day^1!") } else { g_MondayType = 1 ColorChat(id, TEAM_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?
|