Raised This Month: $32 Target: $400
 8% 

Extra item - Buy 2000 hp Help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jievylook
Senior Member
Join Date: Sep 2018
Old 03-24-2019 , 16:20   Extra item - Buy 2000 hp Help
Reply With Quote #1

Hello everyone I have this code for an extra item for zombie plague but I need to be able to limit purchases to 1 or 2 times per round.

PHP Code:
#include <amxmodx>
#include <fun>
#include <zombieplague>

new const item_name[] = "Buy 2000 HP!"
new g_itemid_buyhp
new hpamount

public plugin_init() 
{
    
register_plugin("[ZP] Buy Health Points""1.0""T[h]E Dis[as]teR")
    
hpamount register_cvar("zp_buyhp_amount""2000")
    
g_itemid_buyhp zp_register_extra_item(item_name5ZP_TEAM_ZOMBIE)
}
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(idprint_chat,"[ZP] Not enough Ammopacks!");
            return 
PLUGIN_HANDLED;
        }
        else
        {
            
set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount));
            
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) - 5);
            
client_print(idprint_chat,"[ZP] You Bought HP!");
        }
    }
    return 
PLUGIN_CONTINUE;

jievylook is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 03-24-2019 , 18:09   Re: Extra item - Buy 2000 hp Help
Reply With Quote #2

Quote:
Originally Posted by jievylook View Post
PHP Code:
#include <amxmodx> 
Please pay more attention to where you post / send messages to in the future!

Moved from SourceMod/Scripting to AMX/Scripting Help.
__________________
Mostly known as "DarkDeviL".

Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
DarkDeviL is offline
Ynet
Member
Join Date: Aug 2017
Location: israel
Old 03-28-2019 , 21:17   Re: Extra item - Buy 2000 hp Help
Reply With Quote #3

There you go mate
PHP Code:
#include <amxmodx> 
#include <fun> 
#include <zombieplague> 

new const item_name[] = "Buy 2000 HP!" 
new g_itemid_buyhp 
new hpamount 
new bool:BoughtHP[33] = false;

public 
plugin_init()  

    
register_plugin("[ZP] Buy Health Points""1.0""T[h]E Dis[as]teR"
    
register_logevent("StartNewRound"2"1=Round_Start")  
    
hpamount register_cvar("zp_buyhp_amount""2000"
    
g_itemid_buyhp zp_register_extra_item(item_name5ZP_TEAM_ZOMBIE

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(idprint_chat,"[ZP] Not enough Ammopacks!"); 
            return 
PLUGIN_HANDLED
        } 
        else 
        { 
        
       if(
BoughtHP[id])
       return 
client_print(id,print_chat,"You Have Already Bought HP in This Round!");
    
            
set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount)); 
            
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) - 5); 
            
client_print(idprint_chat,"[ZP] You Bought HP!"); 
       
BoughtHP[id] = true;
        } 
    } 
    return 
PLUGIN_CONTINUE
}  

public 
StartNewRound()
{
    static 
Players32 ], iNumiPlayer;
    
    
get_playersPlayersiNum"ch" );
    
    for ( new 
iiNumi++ )
    {

    
    
BoughtHP[Players]] = false;
    
    }
    


Last edited by Ynet; 03-28-2019 at 21:22.
Ynet is offline
jievylook
Senior Member
Join Date: Sep 2018
Old 04-11-2019 , 00:12   Re: Extra item - Buy 2000 hp Help
Reply With Quote #4

Quote:
Originally Posted by Ynet View Post
There you go mate
PHP Code:
#include <amxmodx> 
#include <fun> 
#include <zombieplague> 

new const item_name[] = "Buy 2000 HP!" 
new g_itemid_buyhp 
new hpamount 
new bool:BoughtHP[33] = false;

public 
plugin_init()  

    
register_plugin("[ZP] Buy Health Points""1.0""T[h]E Dis[as]teR"
    
register_logevent("StartNewRound"2"1=Round_Start")  
    
hpamount register_cvar("zp_buyhp_amount""2000"
    
g_itemid_buyhp zp_register_extra_item(item_name5ZP_TEAM_ZOMBIE

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(idprint_chat,"[ZP] Not enough Ammopacks!"); 
            return 
PLUGIN_HANDLED
        } 
        else 
        { 
        
       if(
BoughtHP[id])
       return 
client_print(id,print_chat,"You Have Already Bought HP in This Round!");
    
            
set_user_health(id,get_user_health(id)+get_pcvar_num(hpamount)); 
            
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) - 5); 
            
client_print(idprint_chat,"[ZP] You Bought HP!"); 
       
BoughtHP[id] = true;
        } 
    } 
    return 
PLUGIN_CONTINUE
}  

public 
StartNewRound()
{
    static 
Players32 ], iNumiPlayer;
    
    
get_playersPlayersiNum"ch" );
    
    for ( new 
iiNumi++ )
    {

    
    
BoughtHP[Players]] = false;
    
    }
    



This code has an error, the player can continue buying after the second purchase, he makes the discount of the ammo packs but does not add hp
jievylook is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-11-2019 , 00:42   Re: Extra item - Buy 2000 hp Help
Reply With Quote #5

PHP Code:
#include <amxmodx>
#include <fun>
#include <zombieplague>

new g_ItemID
new HpAmount

#define itemcost 20

new itemname[] = "Buy 2000 HP!"

new g_Limit[33]
new 
g_iMaxPlayers

public plugin_init()
{
    
register_plugin("Buy HP""1.0" "" )
    
HpAmount register_cvar("zp_buyhp_amount""2000")

    
g_ItemID zp_register_extra_item(itemnameitemcostZP_TEAM_ZOMBIE)

    
register_event("HLTV""event_new_round""a""1=0""2=0"
    
g_iMaxPlayers get_maxplayers()
}

public 
event_new_round()
{
    for(new 
id 1id <= g_iMaxPlayersid++)
    {
        
g_Limit[id] = 0
    
}
}

public 
zp_extra_item_selected(iditem)
{
    if(!
is_user_alive(id))
    return 
PLUGIN_HANDLED

    
if(item == g_ItemID)
    {
        if(
g_Limit[id] >= 2)
        {
            
client_print(idprint_chat"[ZP] You reached the limit of buying HP")
            return 
ZP_PLUGIN_HANDLED
        
}
        
set_user_health(idget_user_health(id) + get_pcvar_num(HpAmount))
        
client_print(idprint_chat"[ZP] You bought HP!")
        
g_Limit[id]++
    }
    return 
PLUGIN_HANDLED


Last edited by ZaX; 04-11-2019 at 23:16.
ZaX is offline
jievylook
Senior Member
Join Date: Sep 2018
Old 04-11-2019 , 21:29   Re: Extra item - Buy 2000 hp Help
Reply With Quote #6

Quote:
Originally Posted by ZaX View Post
PHP Code:
#include <amxmodx>
#include <fun>
#include <zombieplague>

new g_ItemID
new HpAmount

#define itemcost 20

new itemname[] = "Buy 2000 HP!"

new g_Limit[33]
new 
g_iMaxPlayers

public plugin_init()
{
    
register_plugin("Buy HP""1.0" "" )
    
HpAmount register_cvar("zp_buyhp_amount""2000")

    
g_ItemID zp_register_extra_item(itemnameitemcostZP_TEAM_ZOMBIE)

    
register_event("HLTV""event_new_round""a""1=0""2=0"
    
g_iMaxPlayers get_maxplayers()
}

public 
event_new_round()
{
    for(new 
0g_iMaxPlayersi++)
    {
        
g_Limit[i] = 0
    
}
}

public 
zp_extra_item_selected(iditem)
{
    if(!
is_user_alive(id))
    return 
PLUGIN_HANDLED

    
if(item == g_ItemID)
    {
        if(
g_Limit[id] >= 2)
        {
            
client_print(idprint_chat"[ZP] You reached the limit of buying HP")
            return 
ZP_PLUGIN_HANDLED
        
}
        
set_user_health(idget_user_health(id) + get_pcvar_num(HpAmount))
        
client_print(idprint_chat"[ZP] You bought HP!")
        
g_Limit[id]++
    }
    return 
PLUGIN_HANDLED



This code works correctly but limits the purchase to 2 times per map and I need it to be 2 times per round
jievylook is offline
ZaX
Senior Member
Join Date: Jan 2015
Old 04-11-2019 , 23:16   Re: Extra item - Buy 2000 hp Help
Reply With Quote #7

Edited the code, check the post
ZaX is offline
Reply


Thread Tools
Display Modes

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:01.


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