Raised This Month: $ Target: $400
 0% 

Help for code


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
freust
Member
Join Date: Jul 2010
Old 07-30-2010 , 10:45   Help for code
Reply With Quote #1

Hi everybody,

I need help for a menu that im trying to write. I have a menu who contains 8 items. The item 8 is a ESPION item. When a Terrorist player choose this item, his model change to a CT model. I need a code who reset this item when the player die or change his team but my present code dont work.

Here is my code, could you help me ? THX

Code:

Code:
#include <amxmodx>
#include <fakemeta>
#include <cstrike>
#include <fun>
#include <hamsandwich>

new const VERSION[] = "0.1.0"

#define MAX_PLAYERS 32
#define IsPlayer(%1)    ( 1 <= %1 <= g_iMaxPlayers )

new g_iMaxPlayers

new const g_ModelSuperKnife[] = "models/jailmod_superknife.mdl"

new bool:g_HasAutoBhop[MAX_PLAYERS+1]
new bool:g_HasSuperKnife[MAX_PLAYERS+1]
new bool:g_HasEspion[MAX_PLAYERS+1]
new bool:g_HasHealth[MAX_PLAYERS+1]
new bool:g_HasArmor[MAX_PLAYERS+1]

enum _:Items {
    Item_He = 1,
    Item_Flash,
    Item_Smoke,
    Item_Armor,
    Item_Health,
    Item_Bunny,
    Item_SuperKnife,
    Item_Espion
}

new g_pCvarCost[Items]
new g_pCvarQuantityArmor, g_pCvarQuantityHealth, g_pCvarKnifeMultiplier

public plugin_init() 
{
    // Plugin Info
    register_plugin("Shop", VERSION, "Devil")
    
    // HamSandwich
    RegisterHam(Ham_Spawn, "player", "ham_Player_Spawn_Post", 1)
    RegisterHam(Ham_Player_Jump, "player", "ham_PlayerJump_Pre", 1)
    RegisterHam(Ham_TakeDamage, "player", "ham_TakeDamage_Pre")
    RegisterHam(Ham_Item_Deploy, "weapon_knife", "ham_ItemDeploy_Post", 1)
    
    // GetMaxPlayers
    g_iMaxPlayers = get_maxplayers()
    
    // Commandes
    register_clcmd("say /shop", "ShowBoutique")
    register_clcmd("say_team /shop", "ShowBoutique")
    register_clcmd("say shop", "ShowBoutique")
    
    // On définit le prix des items.
    g_pCvarCost[Item_He] = register_cvar("shop_cost_grenade", "3000")
    g_pCvarCost[Item_Flash] = register_cvar("shop_cost_flashbang", "2000")
    g_pCvarCost[Item_Smoke] = register_cvar("shop_cost_smoke", "1000")
    g_pCvarCost[Item_Armor] = register_cvar("shop_cost_armor", "2000")
    g_pCvarCost[Item_Health] = register_cvar("shop_cost_health", "2000")
    g_pCvarCost[Item_Bunny] = register_cvar("shop_cost_bunny", "2500")
    g_pCvarCost[Item_SuperKnife] = register_cvar("shop_cost_superknife", "14000")
    g_pCvarCost[Item_Espion] = register_cvar("shop_cost_espion", "15000")
    g_pCvarQuantityArmor = register_cvar("shop_quantity_armor", "50")
    g_pCvarQuantityHealth = register_cvar("shop_quantity_health", "10")
    g_pCvarKnifeMultiplier = register_cvar("shop_multiplier_superknife", "3")
}

public plugin_precache()
{
    precache_model(g_ModelSuperKnife)
}

public ShowBoutique(id)
{
    if ( is_user_alive(id) )
    {
        if ( cs_get_user_team(id) == CS_TEAM_T )
        {
            new Text[64]
            new menu = menu_create("[La boutique de la prison]", "Shop")
            formatex(Text, charsmax(Text), "Grenade HE [%d $]", get_pcvar_num(g_pCvarCost[Item_He]))
            menu_additem(menu, Text, "1")
            formatex(Text, charsmax(Text), "Flashbang [%d $]", get_pcvar_num(g_pCvarCost[Item_Flash]))
            menu_additem(menu, Text, "2")
            formatex(Text, charsmax(Text), "Fumigène [%d $]", get_pcvar_num(g_pCvarCost[Item_Smoke]))
            menu_additem(menu, Text, "3")
            formatex(Text, charsmax(Text), "Armure [%d AP] [%d $]",  get_pcvar_num(g_pCvarQuantityArmor),  get_pcvar_num(g_pCvarCost[Item_Armor]))
            menu_additem(menu, Text, "4")
            formatex(Text, charsmax(Text), "Santé [%d HP] [%d $]",  get_pcvar_num(g_pCvarQuantityHealth),  get_pcvar_num(g_pCvarCost[Item_Health]))
            menu_additem(menu, Text, "5")
            formatex(Text, charsmax(Text), "Bunny Hop [%d $]", get_pcvar_num(g_pCvarCost[Item_Bunny]))
            menu_additem(menu, Text, "6")
            formatex(Text, charsmax(Text), "Super couteau [%d $]", get_pcvar_num(g_pCvarCost[Item_SuperKnife]))
            menu_additem(menu, Text, "7")
            formatex(Text, charsmax(Text), "Espion [%d $]", get_pcvar_num(g_pCvarCost[Item_Espion]))
            menu_additem(menu, Text, "8")
            
            menu_setprop(menu, MPROP_EXITNAME, "Quitter")
            menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
            
            menu_display(id, menu)
        }
        else
        {
            client_print(id, print_chat, "Tu dois être PRISONNIER pour acheter un objet !")
            return PLUGIN_HANDLED
        }
    }
    else
    {
        client_print(id, print_chat, "Tu dois être VIVANT pour acheter un objet !")
    }
}

public Shop(id, menu, item)
{
    if (item == MENU_EXIT)
    {
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    
    if ( !is_user_alive(id) )
    {
        client_print(id, print_chat, "Tu dois etre VIVANT pour acheter un objet !")
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    
    new info[3]
    new access, callback
    menu_item_getinfo(menu, item, access, info, 2, _, _, callback)
    
    new key = str_to_num(info)
    new iNewMoney = cs_get_user_money(id) - get_pcvar_num(g_pCvarCost[key])
    
    if ( iNewMoney < 0 )
    {
        client_print(id, print_chat, "Tu n'as pas assez d'argent pour acheter cet objet !")
        menu_destroy(menu)
        return PLUGIN_HANDLED
    }
    else
    {
        if ( cs_get_user_team(id) == CS_TEAM_T )
        {
            switch(key)
            {
                case Item_He:
                {
                    if ( user_has_weapon(id, CSW_HEGRENADE) )
                    {
                        client_print(id, print_chat, "Tu as déjà une grenade HE !")
                        menu_destroy(menu)
                        return PLUGIN_HANDLED
                    }
                    cs_set_user_money(id, iNewMoney, 1)
                    give_item(id, "weapon_hegrenade")
                    client_print(id, print_chat, "Tu viens d'acheter une grenade HE !")
                }
                
                case Item_Flash:
                {
                    if ( cs_get_user_bpammo(id, CSW_FLASHBANG) == 2 )
                    {
                        client_print(id, print_chat, "Tu as déjà deux flashbang !")
                        menu_destroy(menu)
                        return PLUGIN_HANDLED
                    }
                    cs_set_user_money(id, iNewMoney, 1)
                    give_item(id, "weapon_flashbang")
                    client_print(id, print_chat, "Tu viens d'acheter une flashbang !")
                }
                
                case Item_Smoke:
                {
                    if ( user_has_weapon(id, CSW_SMOKEGRENADE) )
                    {
                        client_print(id, print_chat, "Tu as déjà une fumigène !")
                        menu_destroy(menu)
                        return PLUGIN_HANDLED
                    }
                    cs_set_user_money(id, iNewMoney, 1)
                    give_item(id, "weapon_smokegrenade")
                    client_print(id, print_chat, "Tu viens d'acheter une fumigène !")
                }
                
                case Item_Armor:
                {
                    cs_set_user_money(id, iNewMoney, 1)
                    g_HasArmor[id] = true
                    new iArmorQuantity = get_pcvar_num(g_pCvarQuantityArmor)
                    cs_set_user_armor(id, get_user_armor(id) + iArmorQuantity, CS_ARMOR_VESTHELM)
                    client_print(id, print_chat, "Tu viens d'acheter %d d'armure !", iArmorQuantity)
                }
                
                case Item_Health:
                {
                    cs_set_user_money(id, iNewMoney, 1)
                    g_HasHealth[id] = true
                    new iHealthQuantity = get_pcvar_num(g_pCvarQuantityHealth)
                    set_user_health(id, get_user_health(id) + iHealthQuantity)
                    client_print(id, print_chat, "Tu viens d'acheter %d HP !", iHealthQuantity)
                }
                
                case Item_Bunny:
                {
                    cs_set_user_money(id, iNewMoney, 1)
                    g_HasAutoBhop[id] = true
                    client_print(id, print_chat, "Tu viens d'acheter un Bunny Hop hop hop hop...")
                }
                
                case Item_SuperKnife:
                {
                    cs_set_user_money(id, iNewMoney, 1)
                    g_HasSuperKnife[id] = true
                    if ( get_user_weapon(id) == CSW_KNIFE )
                    {
                        set_pev(id, pev_viewmodel2, g_ModelSuperKnife)
                    }
                    client_print(id, print_chat, "Tu viens d'acheter le super couteau de la mort qui tue !")
                }
                
                case Item_Espion:
                {
                    cs_set_user_money(id, iNewMoney, 1)
                    cs_set_user_model(id, "IG_gardiens")
                    g_HasEspion[id] = true
                    client_print(id, print_chat, "Tu es maintenant un espion du KFC... heu KGB !")
                }
            }
        }
        else
        {
            client_print(id, print_chat, "Tu dois être PRISONNIER pour acheter un objet")
        }
    }
    
    menu_destroy(menu)
    return PLUGIN_HANDLED
}

public ham_PlayerJump_Pre(id)
{
    if ( g_HasAutoBhop[id] && is_user_alive(id) )
    {
        if ( pev(id, pev_flags) & (FL_WATERJUMP | FL_ONGROUND) == FL_ONGROUND && pev(id, pev_waterlevel) < 2 )
        {
            new iOldButtons = pev(id, pev_oldbuttons)
            if ( iOldButtons & IN_JUMP )
            {
                set_pev(id, pev_oldbuttons, iOldButtons & ~IN_JUMP)
            }
        }
    }
}

public ham_Player_Spawn_Post(id)
{
    if ( is_user_alive(id) )
    {
        client_print(id, print_chat, "Tape /shop dans le chat pour acheter un objet !")
        
        if ( g_HasSuperKnife[id] && get_user_weapon(id) == CSW_KNIFE )
        {
            //On remet le model normal si il avait le super Knife et qu'il n'est pas mort.
            set_pev(id, pev_viewmodel2, "models/jail/v_knife.mdl")
        }
        g_HasSuperKnife[id] = false
        
        if ( g_HasEspion[id] && cs_get_user_team(id) == CS_TEAM_T )
        {
            cs_set_user_model(id, "IG_gardiens")
            g_HasEspion[id] = false
        }
        
        if ( g_HasEspion[id] && cs_get_user_team(id) == CS_TEAM_CT )
        {
            cs_set_user_model(id, "IG_prisonnier")
            g_HasEspion[id] = false
        }
        
        g_HasAutoBhop[id] = false
        g_HasHealth[id] = false
        g_HasArmor[id] = false
    }
}

public ham_TakeDamage_Pre(victim, inflictor, attacker, Float:damage, damage_bits)
{
    if ( IsPlayer(attacker) && g_HasSuperKnife[attacker]  && is_user_alive(attacker) && inflictor == attacker  && get_user_weapon(attacker) == CSW_KNIFE )
    {
        SetHamParamFloat( 4, damage * get_pcvar_float(g_pCvarKnifeMultiplier) )
    }
}

public ham_ItemDeploy_Post(weapon_ent)
{
    static owner
    owner = get_pdata_cbase(weapon_ent, 41, 4)
    
    if ( is_user_alive(owner) && g_HasSuperKnife[owner] )
    {
        set_pev(owner, pev_viewmodel2, g_ModelSuperKnife)
    }
}  
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1036\\ f0\\ fs16 \n\\ par }
*/
freust is offline
 



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 00:10.


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