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

Limit of buy item but he take ammo


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 08-18-2021 , 12:33   Limit of buy item but he take ammo
Reply With Quote #1

I put a limit on an item so I can't abuse it but when I want to buy the same item I keep deducting from ammo packs why?


Code:
#include <amxmodx>
#include <fun>
#include <zp_apocalypse>

new const item_name[] = "Buy 1000 HP!"
new g_itemid_buyhp
new hpamount
new g_bComprado[ 33 ];
new cvar_limit

public plugin_init() 
{
    register_plugin("[ZP] Buy Health Points", "1.0", "T[h]E Dis[as]teR")
    
    hpamount = register_cvar("zp_buyhp_amount", "1000")
    cvar_limit = register_cvar("zp_buyhp_limit", "1")
    
    g_itemid_buyhp = zp_register_extra_item(item_name, 5, ZP_TEAM_ZOMBIE & ZP_TEAM_HUMAN)
    
    register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
}
public event_round_start()
{
    arrayset( g_bComprado, 33, 0 );
}
public zp_extra_item_selected(id,itemid)
{
    if(!is_user_alive(id))
        
    return PLUGIN_HANDLED;
    
    if(itemid==g_itemid_buyhp)
    {
        if(zp_get_user_ammo_packs(id) < 20)
        {
            client_print(id, print_chat,"[ZP] Not enough Ammopacks!");
            return PLUGIN_HANDLED;
        }
        else
        {
            if( g_bComprado[ id ] < get_pcvar_num(cvar_limit))
            {
                g_bComprado[ id ] ++;
                set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount));
                zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - 5);
                client_print(id, print_chat,"[ZP] You Bought HP!");
            }
            else
            {
                client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");
            }
        }
    }
    return PLUGIN_CONTINUE;
}
zollymaN is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 08-18-2021 , 13:55   Re: Limit of buy item but he take ammo
Reply With Quote #2

Because you don't register cvar correct.

you have to do something like this

PHP Code:
new g_Cvar[2];

public 
plugin_init() 
{
    
register_plugin("[ZP] Buy Health Points""1.0""T[h]E Dis[as]teR")
    
    
g_Cvar[0] = register_cvar("zp_buyhp_amount""1000")
    
g_Cvar[1] = register_cvar("zp_buyhp_limit""1")
    
    
cvar_limit get_pcvar_num(g_Cvar[1]);
    
hpamount get_pcvar_num(g_Cvar[0]);

    
g_itemid_buyhp zp_register_extra_item(item_name5ZP_TEAM_ZOMBIE ZP_TEAM_HUMAN)
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")

and next time, do some debugging using server_print.

You could resolve this if you easily print on server console cvar_limit.

Code:
native register_cvar(const name[], const string[], flags = FCVAR_NONE, Float:fvalue = 0.0);

Return
Unique cvar pointer
https://www.amxmodx.org/api/cvars/register_cvar

Last edited by lexzor; 08-18-2021 at 13:56.
lexzor is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-18-2021 , 19:11   Re: Limit of buy item but he take ammo
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
Because you don't register cvar correct.

you have to do something like this

PHP Code:
new g_Cvar[2];

public 
plugin_init() 
{
    
register_plugin("[ZP] Buy Health Points""1.0""T[h]E Dis[as]teR")
    
    
g_Cvar[0] = register_cvar("zp_buyhp_amount""1000")
    
g_Cvar[1] = register_cvar("zp_buyhp_limit""1")
    
    
cvar_limit get_pcvar_num(g_Cvar[1]);
    
hpamount get_pcvar_num(g_Cvar[0]);

    
g_itemid_buyhp zp_register_extra_item(item_name5ZP_TEAM_ZOMBIE ZP_TEAM_HUMAN)
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")

and next time, do some debugging using server_print.

You could resolve this if you easily print on server console cvar_limit.

Code:
native register_cvar(const name[], const string[], flags = FCVAR_NONE, Float:fvalue = 0.0);

Return
Unique cvar pointer
https://www.amxmodx.org/api/cvars/register_cvar
There's nothing wrong with the way he's registering his cvars. You're making things complicated for no reason.

OP: Are you gaining any health when this happens, or is it just deducting packs?
__________________

Last edited by Napoleon_be; 08-18-2021 at 19:13.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-18-2021 , 21:16   Re: Limit of buy item but he take ammo
Reply With Quote #4

Do some debugging. Log or server_print() the value of g_bComprado[ id ] at each stage in this function (when increased, when value checked); do the same for the cvar value. Somehow you are getting into code that deducts ammo packs. You can figure out all issues on your own once you learn the general principle of debugging.

Code:
    if(itemid==g_itemid_buyhp)     {         if(zp_get_user_ammo_packs(id) < 20)         {             client_print(id, print_chat,"[ZP] Not enough Ammopacks!");             return PLUGIN_HANDLED;         }         else         {
            server_print( "g_bComprado[ %d ] = %d , cvar=%d" , id , g_bComprado[ id ] , get_pcvar_num(cvar_limit) );
            if( g_bComprado[ id ] < get_pcvar_num(cvar_limit))             {
                server_print( "reached code where ammo packs bought" );
                g_bComprado[ id ] ++;                 set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount));                 zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - 5);                 client_print(id, print_chat,"[ZP] You Bought HP!");             }             else             {                 client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");             }         }     }
__________________

Last edited by Bugsy; 08-18-2021 at 21:18.
Bugsy is offline
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 08-19-2021 , 05:09   Re: Limit of buy item but he take ammo
Reply With Quote #5

none of these work, and I also discovered that in fact the limit is once on the map, not on the round...... What's wrong with this plugin?

Last edited by zollymaN; 08-19-2021 at 05:11.
zollymaN is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-19-2021 , 08:50   Re: Limit of buy item but he take ammo
Reply With Quote #6

Are you referring to my code? If so, then the function is not even getting called that is causing your issue.
__________________
Bugsy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-19-2021 , 12:08   Re: Limit of buy item but he take ammo
Reply With Quote #7

To me it looks like this is your issue, as you're mentioning that u can only use it once a map.

PHP Code:
public event_round_start()
{
    
arraysetg_bComprado33);

Try this

PHP Code:
public event_round_start()
{
    new 
iPlayers[MAX_PLAYERS], iNum;
    
get_players(iPlayersiNum)

    for(new 
iiNumi++) {
        
g_bComprado[iPlayers[i]] = 0;
    }

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-19-2021 , 13:10   Re: Limit of buy item but he take ammo
Reply With Quote #8

arrayset() would cover the entire array, I'm not sure how only resetting certain indexes would matter.
__________________
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-19-2021 , 13:14   Re: Limit of buy item but he take ammo
Reply With Quote #9

I'm not sure what's your zp version, usually you have to return PLUGIN_HANDLED in order to block the user from buying, but you're returning PLUGIN_CONTINUE

Code:
#include <amxmodx>
#include <fun>
#include <zp_apocalypse>

new const item_name[] = "Buy 1000 HP!"
new g_itemid_buyhp
new hpamount
new g_bComprado[ 33 ];
new cvar_limit

public plugin_init() 
{
    register_plugin("[ZP] Buy Health Points", "1.0", "T[h]E Dis[as]teR")
    
    hpamount = register_cvar("zp_buyhp_amount", "1000")
    cvar_limit = register_cvar("zp_buyhp_limit", "1")
    
    g_itemid_buyhp = zp_register_extra_item(item_name, 5, ZP_TEAM_ZOMBIE & ZP_TEAM_HUMAN)
    
    register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
}
public event_round_start()
{
    arrayset( g_bComprado, 33, 0 );
}
public zp_extra_item_selected(id,itemid)
{
    if(!is_user_alive(id))
        
    return PLUGIN_HANDLED;
    
    if(itemid==g_itemid_buyhp)
    {
        if(zp_get_user_ammo_packs(id) < 20)
        {
            client_print(id, print_chat,"[ZP] Not enough Ammopacks!");
            return PLUGIN_HANDLED;
        }
        else
        {
            if( g_bComprado[ id ] < get_pcvar_num(cvar_limit))
            {
                g_bComprado[ id ] ++;
                set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount));
                zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - 5);
                client_print(id, print_chat,"[ZP] You Bought HP!");
                return PLUGIN_CONTINUE
            }
            else
            {
                client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");
                return PLUGIN_HANDLED
            }
        }
    }
    return PLUGIN_CONTINUE;
}
__________________









Last edited by CrazY.; 08-19-2021 at 13:14.
CrazY. is offline
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 08-19-2021 , 16:48   Re: Limit of buy item but he take ammo
Reply With Quote #10

Quote:
Originally Posted by CrazY. View Post
I'm not sure what's your zp version, usually you have to return PLUGIN_HANDLED in order to block the user from buying, but you're returning PLUGIN_CONTINUE

Code:
#include <amxmodx>
#include <fun>
#include <zp_apocalypse>

new const item_name[] = "Buy 1000 HP!"
new g_itemid_buyhp
new hpamount
new g_bComprado[ 33 ];
new cvar_limit

public plugin_init() 
{
    register_plugin("[ZP] Buy Health Points", "1.0", "T[h]E Dis[as]teR")
    
    hpamount = register_cvar("zp_buyhp_amount", "1000")
    cvar_limit = register_cvar("zp_buyhp_limit", "1")
    
    g_itemid_buyhp = zp_register_extra_item(item_name, 5, ZP_TEAM_ZOMBIE & ZP_TEAM_HUMAN)
    
    register_event("HLTV", "event_round_start", "a", "1=0", "2=0")
}
public event_round_start()
{
    arrayset( g_bComprado, 33, 0 );
}
public zp_extra_item_selected(id,itemid)
{
    if(!is_user_alive(id))
        
    return PLUGIN_HANDLED;
    
    if(itemid==g_itemid_buyhp)
    {
        if(zp_get_user_ammo_packs(id) < 20)
        {
            client_print(id, print_chat,"[ZP] Not enough Ammopacks!");
            return PLUGIN_HANDLED;
        }
        else
        {
            if( g_bComprado[ id ] < get_pcvar_num(cvar_limit))
            {
                g_bComprado[ id ] ++;
                set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount));
                zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) - 5);
                client_print(id, print_chat,"[ZP] You Bought HP!");
                return PLUGIN_CONTINUE
            }
            else
            {
                client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");
                return PLUGIN_HANDLED
            }
        }
    }
    return PLUGIN_CONTINUE;
}
I use the version where you updated it mr crazy, that is 4.4, my opinion is that it is the most stable and well developed source of zm

I tried the code written by you but it still drops me from ammo packs when I want to buy hp again
zollymaN 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 11:06.


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