View Single Post
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 08-10-2008 , 06:03   Re: New to scripting? This will get you started.
Reply With Quote #7

an error I noticed with part II code is your usage of price, and plugin_on. The way you defined them they are pcvars thus instead of
Code:
if (plugin_on == 1)
you should have
Code:
if (get_pcvar_num(plugin_on) == 1)
same for price. To use them instead the way that you did you would have to do this in plugin_init
Code:
    register_cvar("amx_tutorial_plugin", "1")
    register_cvar("amx_tutorial_price", "4000")
    plugin_on = get_cvar_num("amx_tutorial_plugin")
    price = get_cvar_num("amx_tutorial_price")

edit:
yes do
Code:
cs_set_user_money(id, money - get_pcvar_num(price))
and upon better inspection of the code since the mass comments overwhelmed everything, I would suggest that you first check if the user has enough money to afford the steroids before setting the health and gravity. Also rather than just arbitrarily setting heath to 150 I would instead add 50 health since someone could use the command just before dieing to reset health to max each time.
Code:
public steroids(id)
{
    if ( !get_pcvar_num(plugin_on) ) {	
    /*
    ! operator means false which equates to 0 in numerical sense so this equates
    to if ( get_pcvar_num(plugin_on) == 0 )
    */	
        client_print(id, print_chat, "Steroids currently disabled");
        return;		//ends the function on the spot
    }
    new money = cs_get_user_money(id);
    new cost = get_pcvar_num(price);	//rather than calling get_pcvar_num 3 times, store it to a variable
    if ( money >= cost )	//run a check on if user has enough cach
    {  
        cs_set_user_money(id, money - cost);  
        set_user_health(id, ( get_user_health(id)+50 ) );	//sets user health 50 points greater tehn current health incase they have more or less than starting 100
        set_user_gravity(id, 0.50 );
        client_print(id, print_chat, "You just purchased some steroids, dude!");
    }
    else 	//if they didn't have enough cash display a message stating how much more they need
    	client_print(id, print_chat, "Sorry you need %d more cash to afford steroids", cost-money);
}
__________________
If at first you don't succeed, then skydiving isn't for you.

Last edited by G-Dog; 08-10-2008 at 13:47.
G-Dog is offline
Send a message via AIM to G-Dog