Raised This Month: $ Target: $400
 0% 

[Help] Fix my Codes


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
moosewanted
Member
Join Date: May 2009
Old 05-25-2009 , 20:09   Re: [Help] Fix my Codes
Reply With Quote #1

Nothing changed codewise here, I just indented the code to make it easier to read. Hopefully you can continue to do the same with future plugins.

PHP Code:
/* Plugin generated by AMXX-Studio */
#include <amxmodx>
#include <engine>
#include <fakemeta>
#include <fun>
#include <cstrike>
#include <hamsandwich>
#define PLUGIN "CSO Weapon Menu"
#define VERSION "1.0"
#define AUTHOR "Zombie Lurker"
#define CSO_MENUKEYS (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6)|(1<<7)|(1<<8)|(1<<9)

new bool:hasmg3m[32], hasm1887[32], hasxm8[32], hasddeagle[32], hasstrong_knife[32]
new 
CSOmenug_iMaxPlayersg_curWpn[33][2];
new const 
model_mg3m_view[] = "models/zombie_plague/v_mg3m.mdl"
new const model_m1887_view[] = "models/zombie_plague/v_m1887.mdl"
new const model_xm8_view[] = "models/zombie_plague/v_xm8.mdl"
new const model_ddeagle_view[] = "models/zombie_plague/v_ddeagle.mdl"
new const model_strong_knife_view[] = "models/zombie_plague/v_strong_knife.mdl"

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
 
    
register_cvar("mg3m_cost""10000")
    
register_cvar("m1887_cost""10000")
    
register_cvar("xm8_cost""8000")
    
register_cvar("ddeagle_cost""5000")
    
register_cvar("strong_knife_cost""5000")
    
g_iMaxPlayers get_maxplayers()
 
    
register_event("Damage" "event_Damage" "b" "2>0");
    
RegisterHamHam_TakeDamage"player""Player_TakeDamage" );
 
    
register_clcmd("say""handle_say")
    
register_clcmd("say_team""handle_say")
 
    
CSOmenu menu_create("CSO Weapon Menu""do_CSOmenu")
    
menu_additem(CSOmenu"Buy MG3M Cost : $10000""1"ADMIN_ALL)
    
menu_additem(CSOmenu"Buy M1887 Cost : $10000""2"ADMIN_ALL)
    
menu_additem(CSOmenu"Buy XM8 Cost : $8000""3"ADMIN_ALL)
    
menu_additem(CSOmenu"Buy Dual Deagles Cost : $5000""4"ADMIN_ALL)
    
menu_additem(CSOmenu"Buy Strong Knife Cost : $5000""5"ADMIN_ALL)
}

public 
plugin_precache()
{
    
engfunc(EngFunc_PrecacheModelmodel_mg3m_view)
    
engfunc(EngFunc_PrecacheModelmodel_m1887_view
    
engfunc(EngFunc_PrecacheModelmodel_xm8_view)
    
engfunc(EngFunc_PrecacheModelmodel_ddeagle_view)
    
engfunc(EngFunc_PrecacheModelmodel_strong_knife_view)
}

public 
handle_say(id)
{
    new 
command[32]
    
read_argv(1command31)
 
    if (
equal(command"buymenu"))
    {
        if (
is_user_alive(id))
        {
            
Showmenu_CSO(id)
        }
    }
    else
    {
        
client_print(idprint_chat"[ZP] You cannot buy a weapon while you are dead!")
    }
}

public 
Showmenu_CSO(id)
{
    
menu_display(idCSOmenu,0)
    return 
PLUGIN_HANDLED
}

public 
do_CSOmenu(idMenuItem)
{
    new 
szCommand[3], AccesssCallbackECostDCostCCostBCostACost
    ECost 
get_cvar_num("strong_knife_cost")
    
DCost get_cvar_num("ddeagle_cost")
    
CCost get_cvar_num("xm8_cost")
    
BCost get_cvar_num("m1887_cost")
    
ACost get_cvar_num("mg3m_cost")
    
menu_item_getinfo(MenuItemAccesssszCommand2__Callback)
    switch(
szCommand[0])
    {
        case 
'-':
        {
            return 
PLUGIN_HANDLED
        
}
        case 
'1':
        {
            if (
cs_get_user_money(id) >= ACost && !hasmg3m[id])
            {
                
give_item_mg3m(id)
                
cs_set_user_money(idcs_get_user_money(id) - ACost)
                
client_print(idprint_chat"[ZP] You have bought a MG3M.")
            }
            if (
cs_get_user_money(id) < ACost)
            {
                
client_print(idprint_center"[ZP] You need $%i to buy this."ACost)
            }
            if (
hasmg3m[id])
            {
                
client_print(idprint_center"[ZP] You already have a MG3M.")
            }
        }
        case 
'2':
        {
            if (
cs_get_user_money(id) >= BCost && !hasm1887[id])
            {
                
give_item_m1887(id)
                
cs_set_user_money(idcs_get_user_money(id) - BCost)
                
client_print(idprint_chat"[ZP] You have bought a M1887.")
            }
            if (
cs_get_user_money(id) < BCost)
            {
                
client_print(idprint_center"[ZP] You need $%i to buy this."BCost)
            }
            if (
hasm1887[id])
            {
                
client_print(idprint_center"[ZP] You already have a M1887.")
            }
        }
        case 
'3':
        {
            if (
cs_get_user_money(id) >= CCost && !hasxm8[id])
            {
                
give_item_xm8(id)
                
cs_set_user_money(idcs_get_user_money(id) - CCost)
                
client_print(idprint_chat"[ZP] You have bought a XM8.")
            }
            if (
cs_get_user_money(id) < CCost)
            {
                
client_print(idprint_center"[ZP] You need $%i to buy this."CCost)
            }
            if (
hasxm8[id])
            {
                
client_print(idprint_center"[ZP] You already have a XM8.")
            }
        }
        case 
'4':
        {
            if (
cs_get_user_money(id) >= DCost && !hasddeagle[id])
            {
                
give_item_ddeagle(id)
                
cs_set_user_money(idcs_get_user_money(id) - DCost)
                
client_print(idprint_chat"[ZP] You have bought a Dual Deagle.")
            }
            if (
cs_get_user_money(id) < DCost)
            {
                
client_print(idprint_center"[ZP] You need $%i to buy this."DCost)
            }
            if (
hasddeagle[id])
            {
                
client_print(idprint_center"[ZP] You already have a Dual Deagle.")
            }
        }
        case 
'5':
        {
            if (
cs_get_user_money(id) >= ECost && !hasstrong_knife[id])
            {
                
give_item_strong_knife(id)
                
cs_set_user_money(idcs_get_user_money(id) - ECost)
                
client_print(idprint_chat"[ZP] You have bought a Strong Knife.")
            }
            if (
cs_get_user_money(id) < ECost)
            {
                
client_print(idprint_center"[ZP] You need $%i to buy this."ECost)
            }
            if (
hasstrong_knife[id])
            {
                
client_print(idprint_center"[ZP] You already have a Strong Knife.")
            }
        }
    }
    return 
PLUGIN_HANDLED
}

public 
give_item_mg3m(id)
{
    
hasmg3m[id] = true
    
new iWeapon give_item(id"weapon_m249")
    if(
iWeapon)
    {
        
cs_set_weapon_ammo(iWeapon150)
        
cs_set_user_bpammo(idiWeapon300)
    }
}

public 
give_item_m1887(id)
{
    
hasm1887[id] = true
    
new iWeapon2 give_item(id"weapon_m3")
    if(
iWeapon2)
    {
        
cs_set_weapon_ammo(iWeapon28)
        
cs_set_user_bpammo(idiWeapon232)
    }
}

public 
give_item_xm8(id)
{
    
hasxm8[id] = true
    
new iWeapon3 give_item(id"weapon_sg552")
    if(
iWeapon3)
    {
        
cs_set_weapon_ammo(iWeapon340)
        
cs_set_user_bpammo(idiWeapon3120)
    }
}

public 
give_item_ddeagle(id)
{
    
hasddeagle[id] = true
    
new iWeapon4 give_item(id"weapon_elite")
    if(
iWeapon4)
    {
        
cs_set_weapon_ammo(iWeapon414)
        
cs_set_user_bpammo(idiWeapon442)
    }
}

public 
give_item_strong_knife(id)
{
    
hasstrong_knife[id] = true
    give_item
(id"weapon_knife")
}

public 
event_curweapon(id)
{
    new 
weapon read_data(2);
    new 
ammo read_data(3);
    if(
g_curWpn[id][0] != weapon)
    {
        
g_curWpn[id][0] = weapon;
        
g_curWpn[id][1] = ammo;
    }
    if(
g_curWpn[id][1] < ammo)
    {
        
g_curWpn[id][1] = ammo;
    if (
weapon CSW_M249 && is_user_alive(id) && hasmg3m[id])
        
cs_set_weapon_ammo(weapon150)
    else if (
weapon CSW_SG552 && is_user_alive(id) && hasxm8[id])
        
cs_set_weapon_ammo(weapon40)
    else if (
weapon CSW_ELITE && is_user_alive(id) && hasddeagle[id])
        
cs_set_weapon_ammo(weapon14)
}
 

new 
weaponID read_data(2)
if (
weaponID CSW_M249 && is_user_alive(id) && hasmg3m[id])
    
set_pev(idpev_viewmodel2model_mg3m_view)
else if (
weaponID CSW_M3 && is_user_alive(id) && hasm1887[id])
    
set_pev(idpev_viewmodel2model_m1887_view)
else if (
weaponID CSW_SG552 && is_user_alive(id) && hasxm8[id])
    
set_pev(idpev_viewmodel2model_xm8_view)
else if (
weaponID CSW_ELITE && is_user_alive(id) && hasddeagle[id])
    
set_pev(idpev_viewmodel2model_ddeagle_view)
else if (
weaponID CSW_KNIFE && is_user_alive(id) && hasstrong_knife[id])
    
set_pev(idpev_viewmodel2model_strong_knife_view)
}

public 
event_Damage(id)
{
    if(!
is_user_alive(id))
        return 
PLUGIN_CONTINUE;

    new 
weapon attacker get_user_attacker(id weapon);
    if(
weapon == CSW_M3 && is_user_alive(attacker) && hasm1887[attacker])
    {
        new 
Float:vec[3];
        new 
Float:oldvelo[3];
        
get_user_velocity(idoldvelo);
        
create_velocity_vector(id attacker vec);
        
vec[0] += oldvelo[0];
        
vec[1] += oldvelo[1];
        
set_user_velocity(id vec);
    }
    return 
PLUGIN_CONTINUE;
}

stock create_velocity_vector(victim,attacker,Float:velocity[3])
{
    if(!
is_user_alive(victim) || !is_user_alive(attacker) || !hasm1887[attacker])
        return 
0;

    new 
Float:vicorigin[3];
    new 
Float:attorigin[3];
    
entity_get_vector(victim EV_VEC_origin vicorigin);
    
entity_get_vector(attacker EV_VEC_origin attorigin);
    new 
Float:origin2[3]
    
origin2[0] = vicorigin[0] - attorigin[0];
    
origin2[1] = vicorigin[1] - attorigin[1];
    new 
Float:largestnum 0.0;
    if(
floatabs(origin2[0])>largestnumlargestnum floatabs(origin2[0]);
    if(
floatabs(origin2[1])>largestnumlargestnum floatabs(origin2[1]);
    
origin2[0] /= largestnum;
    
origin2[1] /= largestnum;
    
velocity[0] = ( origin2[0] * 100 3000 ) / get_entity_distance(victim attacker);
    
velocity[1] = ( origin2[1] * 100 3000 ) / get_entity_distance(victim attacker);
    if(
velocity[0] <= 20.0 || velocity[1] <= 20.0)
        
velocity[2] = random_float(200.0 275.0);
    return 
1;
}

public 
Player_TakeDamage(idinflictorattackerFloat:damagedamagebits)
{
    new 
weaponID read_data(2)
    if(!(
<= attacker <= g_iMaxPlayers) || attacker != inflictor || weaponID != CSW_KNIFE || !hasstrong_knife[attacker])
        return 
HAM_IGNORED;
    else 
SetHamParamFloat(4damage 5);
    if(!(
<= attacker <= g_iMaxPlayers) || attacker != inflictor || weaponID != CSW_ELITE || !hasddeagle[attacker])
        return 
HAM_IGNORED;
    else 
SetHamParamFloat(4damage 2);
    return 
HAM_HANDLED

moosewanted is offline
Old 05-25-2009, 23:36
fysiks
This message has been deleted by fysiks. Reason: . . .
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-25-2009 , 23:43   Re: [Help] Fix my Codes
Reply With Quote #3

Elaborate on "the menu isn't working properly."

Does it not show or does it not function after selecting an option?
__________________
fysiks 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 01:32.


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