Raised This Month: $ Target: $400
 0% 

Cleaning code


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
BunnYboiii
Senior Member
Join Date: Jul 2011
Old 10-05-2011 , 12:37   Cleaning code
Reply With Quote #1

Hi i need some help to clean this code if there is any mess.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <engine>
#include <colorchat>
#include <fakemeta>

#define PLUGIN "HideNSeek Market"
#define VERSION "1.0.5"
#define AUTHOR "BunnYboii"

new g_szPrefix[] = "^04[HideNSeek Market]^01"

new const gszTransformSound[] =     "zombie_plauge/zombie_infec3.wav"
new VIEW_MODEL[] = "models/v_zombieknife.mdl"
new WORLD_MODEL[] = "models/v_zombieknife.mdl"

new ZOMBIE[] = "models/player/shop/bg_zombie.mdl"
new CTs[] = "models/player/shop/ct.mdl"
new Ts[] = "models/player/shop/t.mdl"

new pScoutpDeaglepAwppFiveSeven

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /market""mod_menu")
    
register_clcmd("say /shop""mod_menu")
    
register_clcmd("say /hm""mod_menu")
    
register_clcmd("say /info""show_info")
    
    
// Amount of ammo on weapons
    
pScout register_cvar("s_scout_ammo""0")
    
pDeagle register_cvar("s_dgl_ammo""1")
    
pAwp register_cvar("s_awp_ammo""1")
    
pFiveSeven register_cvar("s_fs_ammo""2")
    
    
register_event("CurWeapon""Event_CurWeapon""be","1=1")
    
register_forward(FM_SetModel"fw_setModel")
}

public 
show_info(id)
{
    
ColorChat(idTEAM_COLOR"%s This plugin is made by BunnYboii ^x03[Version: 1.0.5]^x01"g_szPrefix)
}

public 
plugin_precache()
{
    
precache_model(VIEW_MODEL)
    
precache_model(WORLD_MODEL)
    
precache_model(ZOMBIE)
    
precache_model(CTs)
    
precache_model(Ts)
    
precache_sound(gszTransformSound)
}
public 
mod_menu(id)
{
    if(
get_user_flags(id) & ( ADMIN_ADMIN ADMIN_KICK ) )
    {
        
        new 
menu menu_create("\w[HideNSeek \yMarket\w]""menu_handler");
        
        
menu_additem(menu"\wHE Grenade [\r300$\w]""1"0)
        
menu_additem(menu"\wFlashbang [\r400$\w]""2"0)
        
menu_additem(menu"\wFrost Nade [\r600$\w]""3"0)
        
menu_additem(menu"\wScout [\r800$\w]""4"0)
        
menu_additem(menu"\wDeagle [\r1000$\w]""5"0)
        
menu_additem(menu"\wAWP [\r1400$\w]""6"0)
        
menu_additem(menu"\wFiveseven [\r700$\w]""7"0)
        
menu_additem(menu"\yZombie class \w[\r1500$\w]""8"0)
        
menu_additem(menu"\yCT class \w[\r1700$\w]""9"0)
        
menu_additem(menu"\yT class \w[\r1900$\w]""10"0)
        
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
menu_display(idmenu0)
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You have no ^04access^01 this menu."g_szPrefix)
    }
}
public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
key str_to_num(data)
    new 
money cs_get_user_money(id)
    if(
is_user_alive(id))
    {
        switch(
key)
        {
            case 
1:
            {
                if( 
money >= 300 )
                {
                    new 
setmoney money 300
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_hegrenade")
                    
ColorChat(idTEAM_COLOR"%s You bought a HE Grenade."g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }            
            case 
2:
            {
                if( 
money >= 400 )
                {
                    new 
setmoney money 400
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_flashbang")
                    
ColorChat(idTEAM_COLOR"%s You bought a Flashbang."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
3:
            {
                if( 
money >= 600 )
                {
                    new 
setmoney money 600
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_smokegrenade")
                    
ColorChat(idTEAM_COLOR"^%s You bought a Frostnade!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
4:
            {
                if( 
money >= 800 )
                {
                    new 
setmoney money 800
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_scout")
                    new 
weapon_id find_ent_by_owner(-1"weapon_scout"id);
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pScout))
                    
ColorChat(idTEAM_COLOR"%s You bought Scout."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
5:
            {
                if( 
money >= 1000 )
                {
                    new 
setmoney money 1000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_deagle")
                    new 
weapon_id find_ent_by_owner(-1"weapon_deagle"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pDeagle))
                    
ColorChat(idTEAM_COLOR"%s You bought a Deagle."g_szPrefix)
                    
                }
            }
            case 
6:
            {
                if( 
money >= 1400 )
                {
                    new 
setmoney money 1400
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_awp")
                    new 
weapon_id find_ent_by_owner(-1"weapon_awp"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pAwp))
                    
ColorChat(idTEAM_COLOR"%s You bought an AWP."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"^%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
7:
            {
                if( 
money >= 700 )
                {
                    new 
setmoney money -700
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_fiveseven")
                    new 
weapon_id find_ent_by_owner(-1"weapon_fiveseven"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pFiveSeven))
                    
ColorChat(idTEAM_COLOR"%s You bought a FiveSeven."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
8:
            {
                if( 
money >= 1500 )
                {
                    
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_CT)
                        {
                            
set_pev(idpev_viewmodel2VIEW_MODEL)
                            new 
setmoney money 1500
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"zombie")
                            
set_user_gravity(id0.75)
                            
emit_sound(idCHAN_STATICgszTransformSound1.0ATTN_NORM0PITCH_NORM);
                            
ColorChat(idTEAM_COLOR"%s You bought the Zombie class."g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
            
            case 
9:
            {
                if( 
money >= 1700 )
                {
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_CT)
                        {
                            new 
setmoney money 1700
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"CTs")
                            
ColorChat(idTEAM_COLOR"%s You bought the CT's class"g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
            
            case 
10:
            {
                if( 
money >= 1900 )
                {
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_T)
                        {
                            new 
setmoney = - 1900
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"Ts")
                            
ColorChat(idTEAM_COLOR"%s You bougt the T's class"g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03T^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
        }
    }
    return 
PLUGIN_HANDLED

Thanks in advance, want to have a nice clean code.
__________________
School sucks, so much work.
BunnYboiii is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-05-2011 , 13:12   Re: Cleaning code
Reply With Quote #2

You should try to work with consts to create your menu and use formatex. Example:
PHP Code:
new const g_ShopItems[2][] = {
"HE Grenade",
"Smoke Grenade"
}

new const 
g_ShopPrices[2] = {
400,
400

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
BunnYboiii
Senior Member
Join Date: Jul 2011
Old 10-05-2011 , 14:25   Re: Cleaning code
Reply With Quote #3

I need to know how to implent it to the code

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>
#include <engine>
#include <colorchat>
#include <fakemeta>

#define PLUGIN "HideNSeek Market"
#define VERSION "1.0.5"
#define AUTHOR "BunnYboii"

new g_szPrefix[] = "^04[HideNSeek Market]^01"

new const gszTransformSound[] =     "zombie_plauge/zombie_infec3.wav"
new VIEW_MODEL[] = "models/v_zombieknife.mdl"
new WORLD_MODEL[] = "models/v_zombieknife.mdl"

new ZOMBIE[] = "models/player/shop/bg_zombie.mdl"
new CTs[] = "models/player/shop/ct.mdl"
new Ts[] = "models/player/shop/t.mdl"

new pScoutpDeaglepAwppFiveSeven

new const g_ShopItems[10][] =
{
    
"HE Grenade"
    "Flashbang"
    "Frost nade"
    "Scout"
    "Deagle"
    "AWP"
    "Fiveseven"
    "Zombie Class"
    "CT class"
    "T class"
}

new const 
g_ShopPrices[10] =
{
    
300,
    
400,
    
600,
    
800,
    
1000,
    
1400,
    
700,
    
1500,
    
1700,
    
1900
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /market""mod_menu")
    
register_clcmd("say /shop""mod_menu")
    
register_clcmd("say /hm""mod_menu")
    
register_clcmd("say /info""show_info")
    
    
// Amount of ammo on weapons
    
pScout register_cvar("s_scout_ammo""0")
    
pDeagle register_cvar("s_dgl_ammo""1")
    
pAwp register_cvar("s_awp_ammo""1")
    
pFiveSeven register_cvar("s_fs_ammo""2")
    
    
register_event("CurWeapon""Event_CurWeapon""be","1=1")
    
register_forward(FM_SetModel"fw_setModel")
}

public 
show_info(id)
{
    
ColorChat(idTEAM_COLOR"%s This plugin is made by BunnYboii ^x03[Version: 1.0.5]^x01"g_szPrefix)
}

public 
plugin_precache()
{
    
precache_model(VIEW_MODEL)
    
precache_model(WORLD_MODEL)
    
precache_model(ZOMBIE)
    
precache_model(CTs)
    
precache_model(Ts)
    
precache_sound(gszTransformSound)
}
public 
mod_menu(id)
{
    if(
get_user_flags(id) & ( ADMIN_ADMIN ADMIN_KICK ) )
    {
        
        new 
menu menu_create("\w[HideNSeek \yMarket\w]""menu_handler");
        
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
menu_display(idmenu0)
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You have no ^04access^01 this menu."g_szPrefix)
    }
}
public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], szName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
key str_to_num(data)
    new 
money cs_get_user_money(id)
    if(
is_user_alive(id))
    {
        switch(
key)
        {
            case 
1:
            {
                if( 
money >= 300 )
                {
                    new 
setmoney money 300
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_hegrenade")
                    
ColorChat(idTEAM_COLOR"%s You bought a HE Grenade."g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }            
            case 
2:
            {
                if( 
money >= 400 )
                {
                    new 
setmoney money 400
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_flashbang")
                    
ColorChat(idTEAM_COLOR"%s You bought a Flashbang."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
3:
            {
                if( 
money >= 600 )
                {
                    new 
setmoney money 600
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_smokegrenade")
                    
ColorChat(idTEAM_COLOR"^%s You bought a Frostnade!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
4:
            {
                if( 
money >= 800 )
                {
                    new 
setmoney money 800
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_scout")
                    new 
weapon_id find_ent_by_owner(-1"weapon_scout"id);
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pScout))
                    
ColorChat(idTEAM_COLOR"%s You bought Scout."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
5:
            {
                if( 
money >= 1000 )
                {
                    new 
setmoney money 1000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_deagle")
                    new 
weapon_id find_ent_by_owner(-1"weapon_deagle"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pDeagle))
                    
ColorChat(idTEAM_COLOR"%s You bought a Deagle."g_szPrefix)
                    
                }
            }
            case 
6:
            {
                if( 
money >= 1400 )
                {
                    new 
setmoney money 1400
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_awp")
                    new 
weapon_id find_ent_by_owner(-1"weapon_awp"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pAwp))
                    
ColorChat(idTEAM_COLOR"%s You bought an AWP."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"^%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
7:
            {
                if( 
money >= 700 )
                {
                    new 
setmoney money -700
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_fiveseven")
                    new 
weapon_id find_ent_by_owner(-1"weapon_fiveseven"id)
                    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pFiveSeven))
                    
ColorChat(idTEAM_COLOR"%s You bought a FiveSeven."g_szPrefix)
                    
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
                }
            }
            case 
8:
            {
                if( 
money >= 1500 )
                {
                    
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_CT)
                        {
                            
set_pev(idpev_viewmodel2VIEW_MODEL)
                            new 
setmoney money 1500
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"zombie")
                            
set_user_gravity(id0.75)
                            
emit_sound(idCHAN_STATICgszTransformSound1.0ATTN_NORM0PITCH_NORM);
                            
ColorChat(idTEAM_COLOR"%s You bought the Zombie class."g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
            
            case 
9:
            {
                if( 
money >= 1700 )
                {
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_CT)
                        {
                            new 
setmoney money 1700
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"CTs")
                            
ColorChat(idTEAM_COLOR"%s You bought the CT's class"g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
            
            case 
10:
            {
                if( 
money >= 1900 )
                {
                    if(
is_user_alive(id))
                    {
                        if(
cs_get_user_team(id) == CS_TEAM_T)
                        {
                            new 
setmoney = - 1900
                            cs_set_user_money
(idclamp(setmoney016000))
                            
cs_set_user_model(id"Ts")
                            
ColorChat(idTEAM_COLOR"%s You bougt the T's class"g_szPrefix)
                        }
                        else
                        {
                            
ColorChat(idTEAM_COLOR"%s You need to be a ^03T^01 to buy this!"g_szPrefix)
                        }
                    }
                }
            }
        }
    }
    return 
PLUGIN_HANDLED

Check this, what should i do next?
I removed the other things in the other menu, i also need to add formatex.
__________________
School sucks, so much work.
BunnYboiii is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 10-05-2011 , 14:36   Re: Cleaning code
Reply With Quote #4

PHP Code:
new getmoney cs_get_user_money(id)
new 
menu menu_create("\w[HideNSeek \yMarket\w]""menu_handler");
        
        new 
szTemp[500], Key[6]; 
        
        for(new 
010i++) {
            
formatex(szTempcharsmax(szTemp), "%s%s\d [\y$%i\d]", (getmoney >= g_ShopItems[i]) ? "\r" "\d"g_ShopItems[i], g_ShopPrices[i])
            
num_to_str(iKeycharsmax(Key))
            
menu_additem(menuszTempKey)
        }
        
menu_setprop(menuMPROP_EXITMEXIT_ALL)
        
menu_display(idmenu0)
    }
    return 
PLUGIN_CONTINUE

Something like this should work
__________________

Last edited by Napoleon_be; 10-05-2011 at 14:58.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-05-2011 , 14:59   Re: Cleaning code
Reply With Quote #5

Just because I was bored. There are several other optimizations that can be made, but did a few for you. Note that I also changed the model path for the player models in order for them to work correctly.

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <engine>
#include <colorchat>
#include <fakemeta>

#define PLUGIN "HideNSeek Market"
#define VERSION "1.0.5"
#define AUTHOR "BunnYboii"

new g_szPrefix[] = "^04[HideNSeek Market]^01"

new const gszTransformSound[] =     "zombie_plauge/zombie_infec3.wav"
new VIEW_MODEL[] = "models/v_zombieknife.mdl"
new WORLD_MODEL[] = "models/v_zombieknife.mdl"

new ZOMBIE[] = "models/player/bg_zombie/bg_zombie.mdl"
new CTs[] = "models/player/ct/ct.mdl"
new Ts[] = "models/player/t/t.mdl"

enum _:Item
{
    
HE,
    
Flash,
    
Frost,
    
Scout,
    
Deagle,
    
AWP,
    
Fiveseven,
    
Zombie,
    
CT,
    
T
};

new const 
NameItem ][ ] =
{
    
"HE Grenade",
    
"Flashbang",
    
"Frost Nade",
    
"Scout",
    
"Deagle",
    
"AWP",
    
"Fiveseven",
    
"Zombie Class",
    
"CT Class",
    
"T Class"
};

new const 
CostItem ] =
{
    
300,
    
400,
    
600,
    
800,
    
1000,
    
1400,
    
700,
    
1500,
    
1700,
    
1900
};

new 
pScoutpDeaglepAwppFiveSeven

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /market""mod_menu")
    
register_clcmd("say /shop""mod_menu")
    
register_clcmd("say /hm""mod_menu")
    
register_clcmd("say /info""show_info")
    
    
// Amount of ammo on weapons
    
pScout register_cvar("s_scout_ammo""0")
    
pDeagle register_cvar("s_dgl_ammo""1")
    
pAwp register_cvar("s_awp_ammo""1")
    
pFiveSeven register_cvar("s_fs_ammo""2")
    
    
register_event("CurWeapon""Event_CurWeapon""be","1=1")
    
register_forward(FM_SetModel"fw_setModel")
}

public 
show_info(id)
{
    
ColorChat(idTEAM_COLOR"%s This plugin is made by BunnYboii ^x03[Version: 1.0.5]^x01"g_szPrefix)
}

public 
plugin_precache()
{
    
precache_model(VIEW_MODEL)
    
precache_model(WORLD_MODEL)
    
precache_model(ZOMBIE)
    
precache_model(CTs)
    
precache_model(Ts)
    
precache_sound(gszTransformSound)
}
public 
mod_menu(id)
{
    if(
get_user_flags(id) & ( ADMIN_ADMIN ADMIN_KICK ) )
    {      
        new 
menu menu_create("\w[HideNSeek \yMarket\w]""menu_handler");
        
        new 
Text128 ], Num];
        for( new 
IndexIndex ItemIndex++ )
        {
            
num_to_strIndexNumcharsmaxNum ) );
        
            
formatexTextcharsmaxText ), "\w%s [\r%i$\w]"NameIndex ], CostIndex ] );
            
            
menu_additemmenuTextNum );
        }
        
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
menu_display(idmenu0)
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You have no ^04access^01 this menu."g_szPrefix)
    }
}
public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    if(!
is_user_alive(id))
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[2];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), __callback);
    
    new 
key str_to_num(data)
    new 
money cs_get_user_money(id)
    if( 
money >= Costkey ] )
    {
        switch( 
key )
        {
            case 
ZombieCT:
            {
                if( 
cs_get_user_teamid ) != CS_TEAM_CT )
                {
                    
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                    
                    return 
PLUGIN_HANDLED;
                }
            }
            case 
T:
            {
                if( 
cs_get_user_teamid ) != CS_TEAM_T )
                {
                    
ColorChat(idTEAM_COLOR"%s You need to be a ^03T^01 to buy this!"g_szPrefix)
                    
                    return 
PLUGIN_HANDLED;
                }
            }
        }
        
        new 
setmoney money Costkey ]
        
cs_set_user_money(idclamp(setmoney016000))
        
        
Giveidkey );
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
    }
    
    return 
PLUGIN_HANDLED;
}

Giveiditem )
{
    switch( 
item )
    {
        case 
HE:
        {
            
give_item(id"weapon_hegrenade")
            
ColorChat(idTEAM_COLOR"%s You bought a HE Grenade."g_szPrefix)
        }        
        case 
Flash:
        {
            
give_item(id"weapon_flashbang")
            
ColorChat(idTEAM_COLOR"%s You bought a Flashbang."g_szPrefix)
        }
        case 
Frost:
        {
            
give_item(id"weapon_smokegrenade")
            
ColorChat(idTEAM_COLOR"^%s You bought a Frostnade!"g_szPrefix)
        }
        case 
Scout:
        {
            new 
weapon_id give_item(id"weapon_scout");
            
cs_set_weapon_ammo(weapon_idget_pcvar_num(pScout))
            
ColorChat(idTEAM_COLOR"%s You bought Scout."g_szPrefix)
        }
        case 
Deagle:
        {
            new 
weapon_id give_item(id"weapon_deagle");
            
cs_set_weapon_ammo(weapon_idget_pcvar_num(pDeagle))
            
ColorChat(idTEAM_COLOR"%s You bought a Deagle."g_szPrefix)
        }
        case 
AWP:
        {
            new 
weapon_id give_item(id"weapon_awp");
            
cs_set_weapon_ammo(weapon_idget_pcvar_num(pAwp))
            
ColorChat(idTEAM_COLOR"%s You bought an AWP."g_szPrefix)
        }
        case 
Fiveseven:
        {
            new 
weapon_id give_item(id"weapon_fiveseven");
            
cs_set_weapon_ammo(weapon_idget_pcvar_num(pFiveSeven))
            
ColorChat(idTEAM_COLOR"%s You bought a FiveSeven."g_szPrefix)
        }
        case 
Zombie:
        {
            
set_pev(idpev_viewmodel2VIEW_MODEL)
            
cs_set_user_model(id"bg_zombie")
            
set_user_gravity(id0.75)
            
emit_sound(idCHAN_STATICgszTransformSound1.0ATTN_NORM0PITCH_NORM);
            
ColorChat(idTEAM_COLOR"%s You bought the Zombie class."g_szPrefix)
        }
        case 
CT:
        {
            
cs_set_user_model(id"ct")
            
ColorChat(idTEAM_COLOR"%s You bought the CT's class"g_szPrefix)
        }
        case 
T:
        {
            
cs_set_user_model(id"t")
            
ColorChat(idTEAM_COLOR"%s You bougt the T's class"g_szPrefix)
        }
    }

__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
BunnYboiii
Senior Member
Join Date: Jul 2011
Old 10-05-2011 , 15:34   Re: Cleaning code
Reply With Quote #6

Thank you man xtellah

Now i can use that for fixing my code, thank you so much im gonna put you at credits.
__________________
School sucks, so much work.
BunnYboiii is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-05-2011 , 15:40   Re: Cleaning code
Reply With Quote #7

Don't bother releasing that as a new plugin submission, there are tons of shops, markets and whatnot plugins already. This is just another one in the crowd. Nothing new. And on top of that, not very well coded.
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
BunnYboiii
Senior Member
Join Date: Jul 2011
Old 10-05-2011 , 16:03   Re: Cleaning code
Reply With Quote #8

Ive already created this plugin, but i need to fix some code and add other things to learn and so on..

Im getting some errors when i edit your code, i rewrote the whole plugin.

Check this please

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <engine>
#include <colorchat>
#include <fakemeta>

#define PLUGIN "HideNSeek Market"
#define VERSION "1.0.5"
#define AUTHOR "BunnYboii"

new g_szPrefix[] = "^04[HideNSeek Market]^01"

new const gszTransformSound[] =     "zombie_plauge/zombie_infec3.wav"
new VIEW_MODEL[] = "models/v_zombieknife.mdl"
new WORLD_MODEL[] = "models/v_zombieknife.mdl"

new ZOMBIE[] = "models/player/shop/bg_zombie/bg_zombie.mdl"
new CTs[] = "models/player/shop/ct/ct.mdl"
new Ts[] = "models/player/shop/t/t.mdl"

enum _:Item {
    
HE,
    
Flash,
    
Frost,
    
Scout,
    
Deagle,
    
AWP,
    
Fiveseven,
    
Zombie,
    
CT,
    
T
}

new const 
NameItem ][ ] = {
    
"HE Grenade",
    
"Flashbang",
    
"Frost Nade",
    
"Scout",
    
"Deagle",
    
"AWP",
    
"Fiveseven",
    
"Zombie Class",
    
"CT Class",
    
"T Class"
};

new const 
CostItem ] = {
    
300,
    
400,
    
600,
    
800,
    
1000,
    
1400,
    
700,
    
1500,
    
1700,
    
1900
};

new 
pScoutpDeaglepAwppFiveSeven

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /market""mod_menu")
    
register_clcmd("say /shop""mod_menu")
    
register_clcmd("say /hm""mod_menu")
    
register_clcmd("say /info""show_info")
    
    
// Amount of ammo on weapons
    
pScout register_cvar("s_scout_ammo""0")
    
pDeagle register_cvar("s_dgl_ammo""1")
    
pAwp register_cvar("s_awp_ammo""1")
    
pFiveSeven register_cvar("s_fs_ammo""2")
    
    
register_event("CurWeapon""Event_CurWeapon""be","1=1")
    
register_forward(FM_SetModel"fw_setModel")
}

public 
show_info(id)
{
    
ColorChat(idTEAM_COLOR"%s This plugin is made by BunnYboii ^x03[Version: 1.0.5]^x01"g_szPrefix)
}

public 
plugin_precache()
{
    
precache_model(VIEW_MODEL)
    
precache_model(WORLD_MODEL)
    
precache_model(ZOMBIE)
    
precache_model(CTs)
    
precache_model(Ts)
    
precache_sound(gszTransformSound)
}

public 
mod_menu(id)
{
    if(
get_user_flags(id) & ( ADMIN_ADMIN ADMIN_KICK ) )
    {      
        new 
menu menu_create("\w[HideNSeek \yMarket\w]""menu_handler");
        
        new 
Text128 ], Num];
        for( new 
IndexIndex ItemIndex++ )
        {
            
num_to_strIndexNumcharsmaxNum ) );
            
            
formatexTextcharsmaxText ), "\w%s [\r%i$\w]"NameIndex ], CostIndex ] );
            
            
menu_additemmenuTextNum );
        }
        
        
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
menu_display(idmenu0)
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You have no ^04access^01 this menu."g_szPrefix)
    }
    
}

public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    if(!
is_user_alive(id))
    {
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[2];
    new 
accesscallback;
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), __callback);
    
    new 
key str_to_num(data)
    new 
money cs_get_user_money(id)
    if( 
money >= Costkey ] )
        
    switch( 
key )
    {
        case 
ZombieCT:
        {
            if( 
cs_get_user_teamid ) != CS_TEAM_CT )
            {
                
ColorChat(idTEAM_COLOR"%s You need to be a ^03CT^01 to buy this!"g_szPrefix)
                
                return 
PLUGIN_HANDLED;
            }
        }
        
        case 
T:
        {
            if( 
cs_get_user_teamid ) != CS_TEAM_T )
            {
                
ColorChat(idTEAM_COLOR"%s You need to be a ^03T^01 to buy this!"g_szPrefix)
                
                return 
PLUGIN_HANDLED;
            }
        }
    }
    
    new 
setmoney money Costkey ]
    
cs_set_user_money(idclamp(setmoney016000))
    
    
Giveidkey );
}
else
{
    
ColorChat(idTEAM_COLOR"%s You have insufficient funds!"g_szPrefix)
}
return 
PLUGIN_HANDLED;
}

Giveiditem )
{
switch( 
item )
{
case 
HE:
{
    
give_item(id"weapon_hegrenade")
    
ColorChat(idTEAM_COLOR"%s You bought a HE Grenade."g_szPrefix)
}        
case 
Flash:
{
    
give_item(id"weapon_flashbang")
    
ColorChat(idTEAM_COLOR"%s You bought a Flashbang."g_szPrefix)
}
case 
Frost:
{
    
give_item(id"weapon_smokegrenade")
    
ColorChat(idTEAM_COLOR"^%s You bought a Frostnade!"g_szPrefix)
}
case 
Scout:
{
    new 
weapon_id give_item(id"weapon_scout");
    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pScout))
    
ColorChat(idTEAM_COLOR"%s You bought Scout."g_szPrefix)
}
case 
Deagle:
{
    new 
weapon_id give_item(id"weapon_deagle");
    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pDeagle))
    
ColorChat(idTEAM_COLOR"%s You bought a Deagle."g_szPrefix)
}
case 
AWP:
{
    new 
weapon_id give_item(id"weapon_awp");
    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pAwp))
    
ColorChat(idTEAM_COLOR"%s You bought an AWP."g_szPrefix)
}
case 
Fiveseven:
{
    new 
weapon_id give_item(id"weapon_fiveseven");
    
cs_set_weapon_ammo(weapon_idget_pcvar_num(pFiveSeven))
    
ColorChat(idTEAM_COLOR"%s You bought a FiveSeven."g_szPrefix)
}
case 
Zombie:
{
    
set_pev(idpev_viewmodel2VIEW_MODEL)
    
cs_set_user_model(id"bg_zombie")
    
set_user_gravity(id0.75)
    
emit_sound(idCHAN_STATICgszTransformSound1.0ATTN_NORM0PITCH_NORM);
    
ColorChat(idTEAM_COLOR"%s You bought the Zombie class."g_szPrefix)
}
case 
CT:
{
    
cs_set_user_model(id"ct")
    
ColorChat(idTEAM_COLOR"%s You bought the CT's class"g_szPrefix)
}
case 
T:
{
    
cs_set_user_model(id"t")
    
ColorChat(idTEAM_COLOR"%s You bougt the T's class"g_szPrefix)
}
}

I got some errors i dont know why they appear. Thanks in advance.

EDIT: Lines: 170, 171, 174, 175
__________________
School sucks, so much work.

Last edited by BunnYboiii; 10-05-2011 at 16:06.
BunnYboiii is offline
Xellath
Veteran Member
Join Date: Dec 2007
Location: Sweden
Old 10-05-2011 , 16:17   Re: Cleaning code
Reply With Quote #9

Rewrote the plugin? That's amusing.

You missed a bracket after if( money >= Cost[ key ] ).
__________________
Achievements API - a simple way for you to create your OWN custom achievements!
Xellath is offline
BunnYboiii
Senior Member
Join Date: Jul 2011
Old 10-05-2011 , 16:22   Re: Cleaning code
Reply With Quote #10

I meant i wrote it from the beginning. without using copy paste.
__________________
School sucks, so much work.
BunnYboiii is offline
Reply



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 19:38.


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