Raised This Month: $ Target: $400
 0% 

pcvar help.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-19-2011 , 15:38   pcvar help.
Reply With Quote #1

Like almost everyone knows, i'm making the JailBreakShop. I want to add a pcvar wich enables & disables the shop, but i don't know how i should call it in a function. Can someone help me?

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

#include <amxmodx>
#include <cstrike>
#include <fun>
#include <colorchat>
#include <dhudmessage>

new const PLUGIN[] = "JailBreakShop"
new const VERSION[] = "v1.0"
new const AUTHOR[] = "NapoleoN#"

new const g_szPrefix[] = "^x04[JB-Shop]^x01"
new const JBINFO[] = "jbinfo.html"
new const CMD[] = "commands.html"

new g_pEnableShop
new g_pEnableInfo
new g_pEnableCommands
new g_pEnableGamble


public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("say /jbshop""JailBreakShop")
    
register_clcmd("say /shop""JailBreakShop")
    
register_clcmd("say /jailbreakshop""JailBreakShop")
    
register_clcmd("say_team /jbshop""JailBreakShop")
    
register_clcmd("say_team /shop""JailBreakShop")
    
register_clcmd("say_team /jailbreakshop""JailBreakShop")
    
    
register_clcmd("say /jbinfo""JailBreakInfo")
    
register_clcmd("say_team /jbinfo""JailBreakInfo")
    
register_clcmd("say /info""JailBreakInfo")
    
register_clcmd("say_team /info""JailBreakInfo")
    
    
register_clcmd("say /commands""Commands")
    
register_clcmd("say /cmds""Commands")
    
register_clcmd("say_team /commands""Commands")
    
register_clcmd("say_team /cmds""Commands")
    
    
register_clcmd("say /gamble""gamble")
    
register_clcmd("say /rtd""gamble")
    
register_clcmd("say_team /gamble""gamble")
    
register_clcmd("say_team /rtd""gamble")
    
    
g_pEnableShop register_cvar("jb_shop""1"FCVAR_SERVER)
    
g_pEnableInfo register_cvar("jb_info""1"FCVAR_SERVER)
    
g_pEnableCommands register_cvar("jb_commands""1"FCVAR_SERVER)
    
g_pEnableGamble register_cvar("jb_gamble""1"FCVAR_SERVER)
}

public 
JailBreakShop(id)
{
    if(
cs_get_user_team(id)==CS_TEAM_T && is_user_alive(id))
    {
        new 
ShopMenu menu_create("\rJailBreak \yShop \wMenu:""shop_handler")
        
menu_additem(ShopMenu"Deagle (7 Bullets) - \y3000$""1"id)
        
menu_additem(ShopMenu"Gravity (600) - \y2000$""2"id)
        
menu_additem(ShopMenu"Speed - \y1500$""3"id)
        
menu_additem(ShopMenu"Regenerate to 100 HP - \y4000$""4"id)
        
menu_additem(ShopMenu"Disable Footsteps - \y2000$""5"id)
        
menu_additem(ShopMenu"Invisebility 60 Seconds - \y6000$""6"id)
        
menu_additem(ShopMenu"Roll the dice!""7"id)
        
menu_display(idShopMenu0)
        
menu_setprop(ShopMenuMPROP_EXITMEXIT_ALL)
    }
    else if(
cs_get_user_team(id)==CS_TEAM_CT && is_user_alive(id))
    {
        new 
menu menu_create("\rJailBreak \yShop \wMenu:""menu_handler")
        
menu_additem(menu"Roll the dice!""1"id)
        
menu_display(idmenu0)
        
menu_setprop(menuMPROP_EXITMEXIT_ALL)
    }
}

public 
shop_handler(idShopMenuitem)
{
    new 
money cs_get_user_money(id)
    if(
is_user_alive(id) && cs_get_user_team(id)==CS_TEAM_T)
    {
        switch(
item)
        {
            case 
0:
            {
                if(
money >= 3000)
                {
                    new 
setmoney money 3000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
give_item(id"weapon_deagle")
                    
ColorChat(idTEAM_COLOR"%s You received a^x03 deagle^x01 with 7 bullets!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
1:
            {
                if(
money >= 2000)
                {
                    new 
setmoney money 2000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
set_user_gravity(id0.7)
                    
ColorChat(idTEAM_COLOR"%s You have now 600 Gravity!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
2:
            {
                if(
money >= 1500)
                {
                    new 
setmoney money 1500
                    cs_set_user_money
(idclamp(setmoney016000))
                    
set_user_maxspeed(id320.0)
                    
ColorChat(idTEAM_COLOR"%s You have now more speed and you're ready to rebel!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
3:
            {
                if(
money >= 4000)
                {
                    new 
setmoney money 4000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
set_user_health(id100)
                    
ColorChat(idTEAM_COLOR"%s You regenerated your health to 100!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
4:
            {
                if(
money >= 2000)
                {
                    new 
setmoney money 2000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
set_user_footsteps(id1)
                    
ColorChat(idTEAM_COLOR"%s You don't have any footsteps anymore!"g_szPrefix)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
5:
            {
                if(
money >= 6000)
                {
                    new 
setmoney money 6000
                    cs_set_user_money
(idclamp(setmoney016000))
                    
set_user_rendering(idkRenderFxGlowShell000kRenderTransAlpha15);
                    
ColorChat(idTEAM_COLOR"%s You are now invisable for 60 seconds!"g_szPrefix)
                    
set_task(60.0"RemoveInvis"id)
                }
                else
                {
                    
ColorChat(idTEAM_COLOR"%s You do not have enough money to buy this item!"g_szPrefix)
                }
                return 
PLUGIN_CONTINUE
            
}
            case 
6:
            {
                
gamble(id)
            }
        }
    }
    return 
PLUGIN_HANDLED
}

public 
client_putinserver(id)
{
    
set_task(10.0"ShowMessage"id)
    
set_task(20.0"ShowInfo"id)
}

public 
ShowMessage(id)
{
    if(
is_user_connected(id))
    {
        new 
szName[32]; get_user_name(idszNamecharsmax(szName))
        
ColorChat(idTEAM_COLOR"%s Welcome to the server, ^x04[%s]^x01!"g_szPrefixszName)
    }
}

public 
RemoveInvis(id)
{
    if(
is_user_alive(id))
    {
        
set_user_rendering(idkRenderFxGlowShell000kRenderTransAlpha255)
        
ColorChat(idTEAM_COLOR"%s You are not invisable anymore!"g_szPrefix)
    }
}

public 
JailBreakInfo(id)
{
    if(
is_user_connected(id))
    {
        
show_motd(idJBINFO"JailBreak Shop Information!")
    }
}

public 
ShowInfo(id)
{
    if(
is_user_connected(id))
    {
        
ColorChat(idTEAM_COLOR"%s Type /info to check out the information about the JB Shop!"g_szPrefix)
    }
}

public 
Commands(id)
{
    if(
is_user_connected(id))
    {
        
show_motd(idCMD"JailBreak Shop Commands!")
    }
}

public 
gamble(id)
{
    new 
money cs_get_user_money(id)
    if(
money >= 500)
    {
        new 
Playernum random_num(1100)
        new 
Servernum random_num(25100)
        if(
Playernum Servernum)
        {
            new 
szName[32]; get_user_name(idszNamecharsmax(szName))
            new 
setmoney money 500
            cs_set_user_money
(idclamp(setmoney050000))
            
ColorChat(idTEAM_COLOR"%s %s has won the^x03 dice!^x04 %i^x01 versus^x04 %i"g_szPrefixszNamePlayernumServernum)
        
        }
        else if(
Servernum Playernum)
        {
            if(
money >= 500 )
            {
                new 
setmoney money 500
                cs_set_user_money
(idclamp(setmoney050000))
                
ColorChat(idTEAM_COLOR"%s Server! has won the ^x03 dice!^x04 %i^x01 versus^x03 %i"g_szPrefixServernumPlayernum)
            }
        }
    }
    else
    {
        
ColorChat(idTEAM_COLOR"%s You need atleast 500$ to gamble!"g_szPrefix)
    }
    return 
PLUGIN_CONTINUE
}

public 
menu_handler(idmenuitem)
{
    if(
is_user_alive(id) && cs_get_user_team(id)==CS_TEAM_CT)
    {
        switch(
item)
        {
            case 
0:
            {
                
gamble(id)
            }
        }
    }
    else
    {
        new 
szName[32]; get_user_name(idszNamecharsmax(szName))
        
ColorChat(idTEAM_COLOR"%s You have to be alive to enter the Shop, %s!"g_szPrefixszName)
    }
}

public 
enableshop(id)
{
    if(
get_pcvar_num(g_pEnableShop))
    {
        
    }
    if(!
get_pcvar_num(p_enableShop))
    {
        
    }

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-19-2011 , 15:47   Re: pcvar help.
Reply With Quote #2

You just have to use 1 cvar and have inside all states you want.
Here is an example:

PHP Code:
new cvar_ShopStatus

public plugin_init() {
    
    
    
cvar_ShopStatus register_cvar("command_in_console_to_change_cvar""default_value(0/1/2...)")
}

public 
Shop(id)
{
    switch(
cvar_ShopStatus)
    {
        case 
0:
        {
            
OpenShop(id)
        }
        
        case 
1:
        {
            
BlockShop(id)
        }
        
        
// and more...
    
}
    
    
    
/****** OR *******/
    
    
if (get_pcvar_num(cvar_ShopStatus) == 2)
    {
        
// Do something, if the value of the cvar is 2
    
}

Diegorkable is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-19-2011 , 15:51   Re: pcvar help.
Reply With Quote #3

Quote:
Originally Posted by Diegorkable View Post
You just have to use 1 cvar and have inside all states you want.
Here is an example:

PHP Code:
new cvar_ShopStatus

public plugin_init() {
    
    
    
cvar_ShopStatus register_cvar("command_in_console_to_change_cvar""default_value(0/1/2...)")
}

public 
Shop(id)
{
    switch(
cvar_ShopStatus)
    {
        case 
0:
        {
            
OpenShop(id)
        }
        
        case 
1:
        {
            
BlockShop(id)
        }
        
        
// and more...
    
}
    
    
    
/****** OR *******/
    
    
if (get_pcvar_num(cvar_ShopStatus) == 2)
    {
        
// Do something, if the value of the cvar is 2
    
}

Thanks, but how do i code it so the "OpenShop(id)" has the command to enable the shop and the BlockShop to disable it?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Diegorkable
Veteran Member
Join Date: Jun 2011
Old 09-19-2011 , 16:09   Re: pcvar help.
Reply With Quote #4

You just edit the cvar according to your needs, and check in the right functions if its the value you want it to be. If it is, then proceed, if not, return plugin handled and print them something. (Cvars are enabled disabled by admins with amx_cvar, so if an admin does amx_cvar g_EnableShop 1 in console, he sets the value of the cvar to 1, and you check that if its 1 you can proceed.
Diegorkable is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 09-20-2011 , 10:01   Re: pcvar help.
Reply With Quote #5

I know what your mean, but the problem is i don't know the code how to disable the shop if the pcvar value has 0. Can't you make it with looking in the code i gave you?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
e12harry
Member
Join Date: Apr 2010
Old 09-20-2011 , 10:37   Re: pcvar help.
Reply With Quote #6

In this example if someone says /shop - the shop will be displayed (if it is enabled - cvar jbs_active = 1) or will print information that shop is disabled (jbs_active = 0)
To enable/disable shop use command:
enable: amx_cvar jbs_active 1
disable: amx_cvar jbs_active 0

PHP Code:
new gCvarActive;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /shop""showShop");
    
gCvarActive register_cvar("jbs_active""1");
}

public 
showShop(id){
    if(!
get_pcvar_num(gCvarActive)){
        
client_print(idprint_chat"Shop is disabled!");
        return 
PLUGIN_HANDLED;
    }
    
    
//build your shop menu and display it to player

e12harry 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:30.


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