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

Max Player Armor


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 04-10-2021 , 14:54   Max Player Armor
Reply With Quote #1

Hello, i wanted to ask for help, i dont know how to do that player cant go bigger than 200 armor , and in one round cant buy more than 600... I have the last thing i mentioned in my script but the first one i dont know how to do it without making that ItemCount trigger...
PHP Code:
#include <amxmodx> 
#include <fakemeta> 
#include <zombieplague> 
#include <cc>

new const g_item_name[] = { "Anti-Infection Armor" 
const 
g_item_cost 14

new const g_sound_buyarmor[] = { "items/tr_kevlar.wav" 
const 
g_armor_amount 100 
const g_armor_limit 200 

new g_ItemCount[33]
new 
g_itemid_armor 

public plugin_precache() 

    
precache_sound(g_sound_buyarmor


public 
plugin_init() 

    
register_plugin("[ZP] Extra: Anti-Infection Armor""1.0""MeRcyLeZZ"
    
    
register_event("HLTV""event_round_start""a""1=0""2=0")
        
    
g_itemid_armor zp_register_extra_item(g_item_nameg_item_costZP_TEAM_HUMAN
}

public 
event_round_start(id)
{
    
arrayset(g_ItemCount0sizeof g_ItemCount)
    
}

// Human buys our upgrade, give him some armor 
public zp_extra_item_selected(playeritemid

    if (
itemid == g_itemid_armor
    {    
        if(
g_ItemCount[player] >= 6)
        {
            
client_print_color(playerprint_chat"^4[^1ZP^4] ^1Max armor limit to buy in one round is^4 600^1!")
            
zp_set_user_ammo_packs(playerzp_get_user_ammo_packs(player) + g_item_cost)
        }
        else
        {
            
set_pev(playerpev_armorvaluefloat(min(pev(playerpev_armorvalue)+g_armor_amountg_armor_limit))) 
            
engfunc(EngFunc_EmitSoundplayerCHAN_BODYg_sound_buyarmor1.0ATTN_NORM0PITCH_NORM
            
            
g_ItemCount[player] ++
        }
    } 

HowToRuski is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-10-2021 , 17:59   Re: Max Player Armor
Reply With Quote #2

You can use zp_extra_item_selected() to hook the purchase. Make your checks, for example:
if ( get_user_armor(id) + g_armor_amount > g_armor_limit ) // If you want to block buying at 101-200 armor.
if ( get_user_armor(id) >= g_armor_limit ) // If you want to enable buying at 101-200.

returning ZP_PLUGIN_HANDLED will cancel the purchase and return the money.

If you choose the second, don't forget to use clamp() on the buy forward later to prevent it from going over 200.
clamp(get_user_armor(id)+g_armor_amount, 0, g_armor_limit);

For the 600 limit, add upp the g_armor_amount for every player in a global variable that you clear each round start/end.
__________________
Black Rose is offline
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 04-11-2021 , 01:32   Re: Max Player Armor
Reply With Quote #3

Quote:
Originally Posted by Black Rose View Post
You can use zp_extra_item_selected() to hook the purchase. Make your checks, for example:
if ( get_user_armor(id) + g_armor_amount > g_armor_limit ) // If you want to block buying at 101-200 armor.
if ( get_user_armor(id) >= g_armor_limit ) // If you want to enable buying at 101-200.

returning ZP_PLUGIN_HANDLED will cancel the purchase and return the money.

If you choose the second, don't forget to use clamp() on the buy forward later to prevent it from going over 200.
clamp(get_user_armor(id)+g_armor_amount, 0, g_armor_limit);

For the 600 limit, add upp the g_armor_amount for every player in a global variable that you clear each round start/end.
I bet i did it wrong as you thought , but works for me, thanks. ;D
PHP Code:
if ( get_user_armor(player) >= g_armor_limit ) {
        
clamp(get_user_armor(player)+g_armor_amount0g_armor_limit);
        return 
ZP_PLUGIN_HANDLED
        
}
        else 
HowToRuski is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-11-2021 , 04:38   Re: Max Player Armor
Reply With Quote #4

Not sure how you implemented it, this is what I intended:
Code:
public zp_extra_item_selected(player, itemid) {     if ( itemid == g_itemid_armor && pev(player, pev_armorvalue) >= g_armor_limit )     {         client_print_color(player, print_chat, "^4[^1ZP^4] ^1Max armor is^4 %d^1!", g_armor_limit)         return ZP_PLUGIN_HANDLED;     }     return 0; }
But you can do it exactly the same way you did the 6 item limit. There is no right or wrong here. It's all down to your preferred coding style.

I see that you already have min() instead of clamp() and g_ItemCount[], so you should be all covered.
__________________

Last edited by Black Rose; 04-11-2021 at 04:45.
Black Rose 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 06:00.


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