Raised This Month: $ Target: $400
 0% 

Limit of buy item but he take ammo


Post New Thread Reply   
 
Thread Tools Display Modes
zollymaN
Junior Member
Join Date: Aug 2021
Location: Romania
Old 08-19-2021 , 17:00   Re: Limit of buy item but he take ammo
Reply With Quote #11

Quote:
Originally Posted by Napoleon_be View Post
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;
    }

now i can buy hp once per round it works properly, it gave me an error but i forgot to define MAX_PLAYERS 32: D

and I don't know why it bugs with another plugin ... that is the "knife blink" plugin...

Code is here from knife blink plugin if you need

Code:
#include <amxmodx>
#include <fakemeta>
#include <zp_apocalypse>
#include <colorchat>
#include <chr_engine>

// HUD messages
const Float:HUD_EVENT_X = -1.0
const Float:HUD_EVENT_Y = 0.17
const Float:HUD_INFECT_X = 0.05
const Float:HUD_INFECT_Y = 0.45
const Float:HUD_SPECT_X = -1.0
const Float:HUD_SPECT_Y = 0.8
const Float:HUD_STATS_X = 0.02
const Float:HUD_STATS_Y = 0.9

#pragma tabsize 0

#define MIN_DISTANCE 50
#define MAX_ROUND 1	//de aici modifici de cate ori sa foloseasca pe runda.

new const g_item_name[] = { "\r|Item| \wKnife Blink" }
const g_item_cost = 30
const g_iMaxDistance = 400;

new Float:g_fSpeed = 1000.0;
new Float:g_fDelay = 1.0;

new g_iMaxPlayers;
new g_iEnemy[33];
new g_iInBlink[33];
new Float:g_fLastSlash[33];
new g_iCanceled[33];
new g_iSlash[33];
new g_iBlinks[33];
new g_itemid_blink;

new Limita[33]

public plugin_init(){
   
   register_plugin("[ZP] Extra Item: Knife Blink", "1.3", "ExtreamCS");
   
   g_iMaxPlayers = get_maxplayers();
   
   g_itemid_blink = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_ZOMBIE);
   
   register_forward(FM_TraceLine, "FW_TraceLine_Post", 5);
   register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
   
   register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

public FW_TraceLine_Post(Float:start[3], Float:end[3], conditions, id, trace){
   
   if (!CHECK_ValidPlayer(id))
      return FMRES_IGNORED;
   
   new iWeaponID = get_user_weapon(id);
   
   if ( iWeaponID != CSW_KNIFE ){
      
      OP_Cancel(id);
      return FMRES_IGNORED;
   }
   
   new enemy = g_iEnemy[id];
   
   if (!enemy){
      
      enemy = get_tr2(trace, TR_pHit);
      
      if ( !CHECK_ValidPlayer(enemy) || zp_get_user_zombie(enemy) ){
         
         OP_Cancel(id);
         return FMRES_IGNORED;
      }
      
      g_iEnemy[id] = enemy;
   }
   
   return FMRES_IGNORED;
}

public FW_PlayerPreThink(id){
   
   if (!CHECK_ValidPlayer(id))
      return FMRES_IGNORED;
   
   new iWeaponID = get_user_weapon(id);
   
   if ( iWeaponID != CSW_KNIFE || !zp_get_user_zombie(id) ){
      
      OP_Cancel(id);
      return FMRES_IGNORED;
   }
   
   if ( g_iBlinks[id] == 0 )
      return FMRES_IGNORED;
   
   new button = pev(id,pev_button);
   
   if ( !(button & IN_ATTACK) && !(button & IN_ATTACK2) ){
      
      OP_Cancel(id)
      return FMRES_IGNORED;
   }
   
   if (g_iSlash[id])
      g_iSlash[id] = 0;
   
   OP_NearEnemy(id);
   
   if( g_iInBlink[id] ){
      
      OP_SetBlink(id);
      OP_Blink(id);
      g_iCanceled[id] = 0;
   }

   return FMRES_IGNORED;
}

// Player buys our upgrade, add one blink
public zp_extra_item_selected(player, itemid)
{
	if(Limita[player] == MAX_ROUND)
	{
		ColorChat(player, NORMAL, "^x04[ZP]^x01 You can only buy this item once per round !", MAX_ROUND)	//aici iti pui tu mesajul cum vrei
		return
	}
   if (itemid == g_itemid_blink){
      new name[32]
      get_user_name(player, name, 31)
	Limita[player]++;
      g_iBlinks[player] += 10;

         set_hudmessage(255, 0, 0, HUD_SPECT_X, HUD_SPECT_Y, 1, 0.0, 5.0, 1.0, 1.0, -1)
         //show_hudmessage(0, "%s bought a Knife Blinks!", name)
         ColorChat(player, NORMAL, "^x04[ZP]^x01 You have now [^x04%d^x01] Knife ^x04Blinks^x01", g_iBlinks[player]);
   }
}

// Reset blinks for all players on newround
public EVENT_round_start()
{
   for (new id; id <= 32; id++) {
		g_iBlinks[id] = 0;
		Limita[id] = 0
	}
}
public client_disconnect(id)	Limita[id] = 0

public OP_NearEnemy(id){
   
   new enemy = g_iEnemy[id];
   new Float:time = get_gametime();
   
   if (!enemy || g_fLastSlash[id]+g_fDelay>time){
      
      g_iInBlink[id] = 0;
      return;
   }
   
   new origin[3], origin_enemy[3];
   
   get_user_origin(id, origin, 0);
   get_user_origin(enemy, origin_enemy, 0);
   
   new distance = get_distance(origin, origin_enemy);
   
   if ( MIN_DISTANCE<=distance<=g_iMaxDistance){
      
      g_iInBlink[id] = 1;
      return;
      
   }else if (MIN_DISTANCE>distance && g_iInBlink[id])
   {
      OP_Slash(id);
   }
   OP_Cancel(id);
}

public OP_Blink(id){
   
   new Float:new_velocity[3];
   new enemy = g_iEnemy[id];
   new Float:origin_enemy[3];
   
   pev(enemy, pev_origin, origin_enemy);
   entity_set_aim(id, origin_enemy);
   
   get_speed_vector2(id, enemy, g_fSpeed, new_velocity)
   set_pev(id, pev_velocity, new_velocity);
}

public OP_Cancel(id){
   
   g_iInBlink[id] = 0;
   g_iEnemy[id] = 0;
   if (!g_iCanceled[id]){
      
      OP_SetBlink(id);
      g_iCanceled[id] = 1;
   }
}

public OP_Slash(id){
   
   set_pev(id, pev_velocity, {0.0,0.0,0.0});      // stop player's blink
   
   new weaponID = get_user_weapon(id, _, _);
   
   if(weaponID == CSW_KNIFE){
      
      new weapon[32]
      
      get_weaponname(weaponID,weapon,31)
      
      new ent = fm_find_ent_by_owner(-1,weapon,id)
      
      if(ent){
         
         set_pdata_float(ent,46, 0.0);
         set_pdata_float(ent,47, 0.0);
         g_iSlash[id] = 5;
         g_fLastSlash[id] = get_gametime();
         g_iBlinks[id] -= 1;
         new name[32];
         get_user_name(id,name,31)
         ColorChat(id, GREY, "^x04[ZP]^x01 ^x03%s^x01 just used a ^x04Knife Blink!^x01 [ ^x04%d^x01 remaining ] ", name, g_iBlinks[id]);
      }
   }  
}

public OP_SetBlink(id){
   
   new blink = g_iInBlink[id];
   
   if (blink>1)
      return;
   
   if (blink)
      g_iInBlink[id] += 1;
}

public CHECK_ValidPlayer(id){
   
   if (1<=id<=g_iMaxPlayers && is_user_alive(id))
      return 1;
   
   return 0;
}

// from fakemeta_util.inc
stock fm_find_ent_by_owner(index, const classname[], owner, jghgtype = 0) {
   new strtype[11] = "classname", ent = index;
   switch (jghgtype) {
      case 1: strtype = "target";
      case 2: strtype = "targetname";
   }

   while ((ent = engfunc(EngFunc_FindEntityByString, ent, strtype, classname)) && pev(ent, pev_owner) != owner) {}

   return ent;
}
from knife blink !
Code:
ColorChat(player, NORMAL, "^x04[ZP]^x01 You can only buy this item once per round !", MAX_ROUND)
and of buy hp...

Code:
client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");
this only happens if you buy knife blink and after you get your hp, I mention that knife blink has a limit..

https://imgur.com/a/qaAwLi4 - photo here

Last edited by zollymaN; 08-19-2021 at 17:28.
zollymaN is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 08-19-2021 , 17:29   Re: Limit of buy item but he take ammo
Reply With Quote #12

Off topic but I don't recommend you to use any of the mods I posted, they are old and not coded properly. Also if I remember correctly there are some bugs. You should probably stick with zp50, but that's your decision.

As for the problem, assuming the item costs 5 ammo packs, try this

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
            {
                zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + 5)
                client_print(id, print_chat,"[ZP] poti cumpara acest item daar odata pe runda");
            }
        }
    }
    return PLUGIN_CONTINUE;
}
__________________








CrazY. is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 08-19-2021 , 17:37   Re: Limit of buy item but he take ammo
Reply With Quote #13

Quote:
Originally Posted by Bugsy View Post
arrayset() would cover the entire array, I'm not sure how only resetting certain indexes would matter.
I'm not sure, but wouldn't it have to do with how the Array was created in the first place? Or destroying it when required?

EDIT: Something like this?

PHP Code:
new Array:g_iBought;

public 
plugin_init()
{
    
g_iBought ArrayCreate(MAX_PLAYERS 1);
}

public 
plugin_end()
{
    
ArrayDestroy(g_iBought);

PHP Code:
g_bCompradoid ] ++;
ArrayPushArray(g_iBoughtg_bComprado); // bought


ArrayClear(g_iBought); // new round 
__________________

Last edited by Napoleon_be; 08-19-2021 at 17:55.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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 02:33.


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