Raised This Month: $51 Target: $400
 12% 

if.. else statement


Post New Thread Reply   
 
Thread Tools Display Modes
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 02-21-2015 , 22:42   Re: if.. else statement
Reply With Quote #21

If you want, you can use this plugin:

https://forums.alliedmods.net/showthread.php?t=245805
zmd94 is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 02-22-2015 , 08:28   Re: if.. else statement
Reply With Quote #22

Sorry about this but.

I think I have a problem when seting user's money.

Because after I buy any item, it sets my money to



What's wrong?
Code:
case 0: // ---------- Silent Walk ----------         {             if( HasSW[ id ] )             {                 client_print( id, print_chat, "[Shop] You already have this item." );                 return PLUGIN_HANDLED;             }                         else if( cs_get_user_money(id) < get_pcvar_num( sw_cost ) )             {                 client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );                 return PLUGIN_HANDLED;             }                         else cs_set_user_money(id, cs_get_user_money(id)- sw_cost)             {                 // Gives the player silent walk                 set_user_footsteps( id, 1 );                                 client_print(id, print_chat, "*** You have bought Silent Walk");                 HasSW[ id ] = true;             }                     }

Last edited by Obada; 02-22-2015 at 08:29.
Obada is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 02-22-2015 , 08:53   Re: if.. else statement
Reply With Quote #23

Please learn from this.
Code:
        case 0: // ---------- Silent Walk ----------
        {
            if( HasSW[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            else if( cs_get_user_money(id) < get_pcvar_num( sw_cost ) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            else cs_set_user_money(id, cs_get_user_money(id)- sw_cost)
            {
                // Gives the player silent walk 
                set_user_footsteps( id, 1 );
                
                client_print(id, print_chat, "*** You have bought Silent Walk");
                HasSW[ id ] = true;
            }
        }
-->
Code:
        case 0: // ---------- Silent Walk ----------
        {
            if( HasSW[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( sw_cost ) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id)- get_pcvar_num( sw_cost ))
            
            // Gives the player silent walk 
            set_user_footsteps( id, 1 );
                
            client_print(id, print_chat, "*** You have bought Silent Walk");
            HasSW[ id ] = true;
        }

Last edited by zmd94; 02-22-2015 at 10:30.
zmd94 is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 02-22-2015 , 09:12   Re: if.. else statement
Reply With Quote #24

Thanks man.

But it still shows 154k money.
Obada is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 02-22-2015 , 09:13   Re: if.. else statement
Reply With Quote #25

PHP Code:
cs_set_user_money(idcs_get_user_money(id)- get_pcvar_num(sw_cost)) 
You don't want to think, you just copy paste stuffs without understanding and learning anything. If sw_cost is a cvar, you need to do as above.
__________________
HamletEagle is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 02-22-2015 , 09:44   Re: if.. else statement
Reply With Quote #26

Alright thanks, I don't know how I forgot it.


But still it gave me the same result.

If you want, you can try it.
Attached Files
File Type: sma Get Plugin or Get Source (shop.sma - 273 views - 14.0 KB)
Obada is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 02-27-2015 , 04:54   Re: if.. else statement
Reply With Quote #27

So I guess it's a bug? :/
Obada is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 02-27-2015 , 06:26   Re: if.. else statement
Reply With Quote #28

Just try below code:
Code:
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < fakemeta >
#include < fun >
#include < engine >

// Some globals
new shop
new sw_cost
new health_cost
new armour_cost
new awp_cost
new speed_cost
new gravity_cost
new norecoil_cost
new chameleon_cost
new invisibility_cost
new gSpeedCvar
new gGravityCvar
new g_CZ
new p_iHealth
new p_iMaxHealth
new p_iAdd_Health
new gInvisPercent

// Item variables
new HasSW[ 33 ];
new HasHealth[ 33 ];
new HasArmour[ 33 ];
new HasAWP[ 33 ];
new HasSpeed[ 33 ];
new HasGravity[ 33 ];
new HasNoRecoil[ 33 ];
new HasChameleon[ 33 ];
new HasInvisibility[ 33 ];

// Those models are for the chameleon effect
new const t_models[][] =
{
    "arctic",
    "guerilla",
    "leet",
    "terror",
    "militia"
}

new const ct_models[][] =
{
    "gign",
    "gsg9",
    "sas",
    "urban",
    "spetsnaz"
}

public plugin_init()
{
    // Some events right here
    register_event( "DeathMsg", "event_death", "a")
    register_event( "DeathMsg", "Hook_Deathmessage", "a" );
    register_logevent( "logevent_round_start", 2, "1=Round_Start" );
    
    register_plugin("Shop Menu", "1.0", "Obada");
    register_clcmd("say /shop", "ShowMenu", _, "Brings up shop menu");
    
    // Price of each item in the shop, except for the first one ofcourse
    shop = register_cvar ( "amx_shop", "1" ); // 1 = On , 2 = Off
    sw_cost = register_cvar ( "amx_silentwalk_price", "2500" );
    health_cost = register_cvar ( "amx_health_price", "4000" );
    armour_cost = register_cvar ( "amx_armour_price", "3500" );
    awp_cost = register_cvar ( "amx_awp_price", "5000" );
    speed_cost = register_cvar ( "amx_speed_price", "3500" );
    gravity_cost = register_cvar ( "amx_gravity_price", "3500" );
    norecoil_cost = register_cvar ( "amx_norecoil_price", "12000" );
    chameleon_cost = register_cvar ( "amx_chameleon_price", " 14000" );
    invisibility_cost = register_cvar ( "amx_invisibility_price", "16000" );
    
    // The power of some effects on players
    gSpeedCvar = register_cvar( "amx_speed_power", "400.0" );
    gGravityCvar = register_cvar( "amx_gravity_power", "0.7" );
    g_CZ        = is_running("czero")
    p_iHealth     = register_cvar("chameleon_health", "1")
    p_iMaxHealth    = register_cvar("cham_killer_max_health", "120")
    p_iAdd_Health     = register_cvar("cham_killer_health", "20")
    gInvisPercent    = register_cvar("invisibility_percent", "111")
}

// When client is connecting, let's reset stuff
public client_connect( id )
{
    HasSW[ id ] = false;
    HasHealth[ id ] = false;
    HasArmour[ id ] = false;
    HasAWP[ id ] = false;
    HasSpeed[ id] = false;
    HasGravity[ id ] = false;
    HasNoRecoil[ id ] = false;
    HasChameleon[ id ] = false;
    HasInvisibility[ id ] = false;
}

// When client has disconnected let's reset stuff
public client_disconnect( id )
{
    HasSW[ id ] = false;
    HasHealth[ id ] = false;
    HasArmour[ id ] = false;
    HasAWP[ id ] = false;
    HasSpeed[ id] = false;
    HasGravity[ id ] = false;
    HasNoRecoil[ id ] = false;
    HasChameleon[ id ] = false;
    HasInvisibility[ id ] = false;
}

public ShowMenu(id)
{
    // If cvar is set to 0, player can't open the shop
    if( get_pcvar_num( shop ) != 1 )
    {
        client_print( id, print_chat, "[Shop] Sorry, the shop is currently disabled" );
        return PLUGIN_HANDLED;
    }
    
    // If player is dead, he/she cant buy items
    if( !is_user_alive( id ) )
    {
        client_print( id, print_chat, "[Shop] You must be alive to buy from the shop" );
        return PLUGIN_HANDLED;
    }
    
    new menu = menu_create("Shop Menu", "Shop_Menu");
    
    menu_additem(menu, "Silent Walk - \y2500$", "", 0); // case 0
    menu_additem(menu, "200 hp - \y4000$", "", 0); // case 1
    menu_additem(menu, "200 armor - \y3500$", "", 0); // case 2
    menu_additem(menu, "AWP - \y5000$", "",  0); // case 3
    menu_additem(menu, "Speed - \y3500$", "",  0); // case 4
    menu_additem(menu, "Gravity - \y3500$", "", 0); // case 5
    menu_additem(menu, "No recoil - \y12000$", "",  0); // case 6
    menu_additem(menu, "Chameleon (change skin) - \y%14000$", "", 0); // case 7
    menu_additem(menu, "Invisibility - \y16000$", "", 0); // case 8
    menu_additem(menu, "", "", 0); // case 9
    
    menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
    
    menu_display(id, menu, 0);
    
    return PLUGIN_HANDLED;
}

public Shop_Menu(id, menu, item)
{
    if(item == MENU_EXIT)
    {
        menu_cancel(id);
        return PLUGIN_HANDLED;
    }
    
    new command[6], name[64], access, callback;
    
    menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);
    
    switch(item)
    {
        case 0: // ---------- Silent Walk ----------
        {
            if( HasSW[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( sw_cost ) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id)- get_pcvar_num(sw_cost))
            
            // Gives the player silent walk 
            set_user_footsteps( id, 1 );
                
            client_print(id, print_chat, "*** You have bought Silent Walk");
            HasSW[ id ] = true;
        }
        
        case 1: // ---------- Health Points ----------
        {
            if( HasHealth[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( health_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - health_cost) 

            // Gives the player 200 Health Points
            set_user_health( id, 200 )
                
            client_print(id, print_chat, "*** You have bought 200 HP");
            HasHealth[ id ] = true;
            
        }
        case 2: // ---------- Armour Points ----------
        {
            if( HasArmour[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num(armour_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(armour_cost) ) 

            // Gives the player 200 Armour Points
            set_user_armor( id, 200 )
                
            client_print(id, print_chat, "*** You have bought 200 armor");
            HasArmour[ id ] = true;
        }
        
        case 3: // ---------- AWP ----------
        {
            if( HasAWP[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( awp_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(awp_cost) )

            // Give the player AWP
            give_item ( id, "weapon_awp" );
                
            client_print(id, print_chat, "*** You have bought AWP");
            HasAWP[ id ] = true;

        }
        
        case 4: // ---------- Speed ----------
        {
            if( HasSpeed[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( speed_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(speed_cost) )
            
            // Gives the player speed
            set_user_maxspeed( id, get_pcvar_float( gSpeedCvar ) );
                
            client_print(id, print_chat, "*** You have bought Speed");
            HasSpeed[ id ] = true;
        }
        
        case 5: // ---------- Gravity ----------
        {
            if( HasGravity[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( gravity_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(gravity_cost) )

            // Gives the player some lower gravity
            set_user_gravity( id, get_pcvar_float( gGravityCvar ) );
                
            client_print(id, print_chat, "*** You have bought Gravity");
            HasGravity[ id ] = true;
        }
        
        case 6: // ---------- No Recoil ----------
        {
            if( HasNoRecoil[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( norecoil_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(norecoil_cost) )

            // Gives the player no recoil
            if(get_user_button(id) & IN_ATTACK)
                entity_set_vector(id, EV_VEC_punchangle, Float:{0.0, 0.0, 0.0});

                
            client_print(id, print_chat, "*** You have bought No recoil");
            HasNoRecoil[ id ] = true;
        }
        
        case 7: // ---------- Chameleon --------------------
        {
            if( HasChameleon[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( chameleon_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(chameleon_cost) )

            //Gives the player some chameleon effect
            new name [32]
            get_user_name(id, name, 31)
                
            switch(cs_get_user_team(id))
            {
                case CS_TEAM_T:
                {
                    cs_set_user_model(id, ct_models[random(g_CZ ? 5 : 4 )])
                    client_print(id, print_chat, "*** You have bought the Chameleon effect");
                    client_print(id, print_chat, "*** Make sure that cl_minmodels is set to 0, else it won't work.");
                    HasChameleon[id] = true
                }
                case CS_TEAM_CT:
                {
                    cs_set_user_model(id, t_models[random(g_CZ ? 5 : 4 )])
                    client_print(id, print_chat, "*** You have bought the Chameleon effect");
                    client_print(id, print_chat, "*** Make sure that cl_minmodels is set to 0, else it won't work.");
                    HasChameleon[ id ] = true;
                }
            }
        }
        
        case 8: // ---------- Invisibility ----------
        {    
            if( HasInvisibility[ id ] )
            {
                client_print( id, print_chat, "[Shop] You already have this item." );
                return PLUGIN_HANDLED;
            }
            
            if( cs_get_user_money(id) < get_pcvar_num( invisibility_cost) )
            {
                client_print( id, print_chat, "[Shop] Sorry, but you don't have enough money." );
                return PLUGIN_HANDLED;
            }
            
            cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(invisibility_cost) )
            
            // Gives the player invisibility
            set_user_rendering( id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, get_pcvar_num( gInvisPercent ) );
            
            client_print(id, print_chat, "*** You have bought Invisibility");
            HasInvisibility[ id ] = true;
            
        }
        
        case 9: client_print(id, print_chat, "You have selected ");
    }
    
    menu_display(id, menu, 0);
    
    return PLUGIN_HANDLED;
}

public event_death()
{
    new iKiller = read_data(1)
    new iVictim = read_data(2)
    
    if(iKiller != iVictim && is_user_connected(iKiller) )
    {
        if(HasChameleon[iVictim])
        {
            if(get_pcvar_num(p_iHealth))
            {
                new szKillerName[32]
                get_user_name(iKiller, szKillerName, charsmax(szKillerName))
                client_print(0, print_chat, "*** %s Receives an additional health for killing chameleon!", szKillerName)
                
                set_user_health(iKiller, get_user_health(iKiller) + get_pcvar_num(p_iAdd_Health))
                
                if(get_user_health(iKiller) >= get_pcvar_num(p_iMaxHealth))
                {
                    set_user_health(iKiller, get_pcvar_num(p_iMaxHealth))
                }
            }
            
        }
    }
}

// ------------------------------------- Stock(s) -------------------------------------

// Event for round start

public logevent_round_start()
{
    // If plugin is on
    if( get_pcvar_num( shop ) == 1 )
    {
        // I used this native because with get_maxplayers will recieve an error with invalid player id
        // This is good because we can skip bots
        new iPlayers[ 32 ], iNum, i, id;
        get_players( iPlayers, iNum, "c" );
        
        for( i = 0; i < iNum; i++ )
        {
            // Find the index
            id = iPlayers[ i ];
            
            // Reseting items
            HasSW[ id ] = false;
            HasHealth[ id ] = false;
            HasArmour[ id ] = false;
            HasAWP[ id ] = false;
            HasSpeed[ id] = false;
            HasGravity[ id ] = false;
            HasNoRecoil[ id ] = false;
            HasChameleon[ id ] = false;
            HasInvisibility[ id ] = false;
            
            set_user_footsteps( id, 0 );
            set_user_health( id, 100 );
            set_user_armor( id, 100 );
            set_user_maxspeed( id, 0.0 );
            set_user_gravity( id, 1.0 );    
            
            cs_reset_user_model(id)
            set_user_rendering( id );
            
            remove_task( id );
        }
    }
}

// Event when player died
public Hook_Deathmessage(id)
{
    // If plugin is on
    if( get_pcvar_num( shop ) == 1 )
    {
        // Get the killer and attacker
        new killer = read_data( 1 );
        new victim = read_data( 2 );

        // If player has died with world
        if( killer == victim )
        {
            return PLUGIN_HANDLED;
        }
        
    
        // Reseting items
        HasSW[ id ] = false;
        HasHealth[ id ] = false;
        HasArmour[ id ] = false;
        HasAWP[ id ] = false;
        HasSpeed[ id] = false;
        HasGravity[ id ] = false;
        HasNoRecoil[ id ] = false;
        HasChameleon[ id ] = false;
        HasInvisibility[ id ] = false;
            
        set_user_footsteps( id, 0 );
        set_user_health( id, 100 );
        set_user_armor( id, 100 );
        set_user_maxspeed( id, 0.0 );
        set_user_gravity( id, 1.0 );    
            
        cs_reset_user_model(id)
        set_user_rendering( id );
    }
    
    return PLUGIN_CONTINUE;
}
zmd94 is offline
Obada
Senior Member
Join Date: Dec 2014
Location: Abu Dhabi
Old 02-27-2015 , 08:28   Re: if.. else statement
Reply With Quote #29

Thanks, but what did you change?
Obada is offline
zmd94
Veteran Member
Join Date: Nov 2013
Location: Malaysia (9w2zow).
Old 02-27-2015 , 09:08   Re: if.. else statement
Reply With Quote #30

Have you tested it?
zmd94 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 21:16.


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