Zplague
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.

Zplague Entrar

Seu portal de Zombie Plague no Brasil


description[Ajuda] limitando esse item Empty[Ajuda] limitando esse item

more_horiz
Já tentei de varias formas mas não consigo colocar limite nela, alguém pode me ajudar

Quero colocar limite de 6 por round

Sma:

Código:

/*================================================================================
   
   -------------------------------------------
   -*- [ZP] Extra Item: Knife Blink 1.2 -*-
   -------------------------------------------
   
   ~~~~~~~~~~~~~~~
   - Description -
   ~~~~~~~~~~~~~~~
   
   This item/upgrade gives zombies the possibility to move rapidly towards a human over a short distance, when aiming at him and holding down the attack button.
   
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <chr_engine>

#define MIN_DISTANCE 50

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Knife Blink" }
const g_item_cost = 5
const g_iMaxDistance = 300;

/*============================================================================*/

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;

public plugin_init(){
   
   register_plugin("[ZP] Extra Item: Knife Blink", "1.2", "pharse");
   
   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", 1);
   register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
   
   register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

// ================================================== //
//          FORWARDS / EVENTS
// ================================================== //

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 (itemid == g_itemid_blink){
      
      g_iBlinks[player] += 1;
      client_print(player, print_chat, "[ZP] You have now %d Knife Blinks", g_iBlinks[player]);
   }
}

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

// ================================================== //
//          OPERATIONS
// ================================================== //

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] = 1;
         g_fLastSlash[id] = get_gametime();
         g_iBlinks[id] -= 1;
         new name[32];
         get_user_name(id,name,31)
         client_print(0, print_chat, "[ZP] %s just used a Knife Blink!", name);
         client_print(id, print_chat, "[ZP] %d Knife Blinks remaining", g_iBlinks[id]);
      }
   } 
}

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

// ================================================== //
//          CHECKS
// ================================================== //

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;
}

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Coloquei limite de 6, e traduzi as mensagens 

Tenta ai:

Código:

/*================================================================================
   
   -------------------------------------------
   -*- [ZP] Extra Item: Knife Blink 1.2 -*-
   -------------------------------------------
   
   ~~~~~~~~~~~~~~~
   - Description -
   ~~~~~~~~~~~~~~~
   
   This item/upgrade gives zombies the possibility to move rapidly towards a human over a short distance, when aiming at him and holding down the attack button.
   
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <chr_engine>

#define MIN_DISTANCE 50

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Knife Blink" }
const g_item_cost = 5
const g_iMaxDistance = 300;
new g_limit[33], cvar_limit_kb

/*============================================================================*/

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;

public plugin_init(){
    
    register_plugin("[ZP] Extra Item: Knife Blink", "1.2", "pharse");
    
    g_iMaxPlayers = get_maxplayers();
    
    g_itemid_blink = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_ZOMBIE);

        cvar_limit_kb = register_cvar("zp_limit_kb","5")  
    
    register_forward(FM_TraceLine, "FW_TraceLine_Post", 1);
    register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
    
    register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

// ================================================== //
//             FORWARDS / EVENTS
// ================================================== //

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 (itemid == g_itemid_blink )
        {
 
          if (g_limit[player] <= get_pcvar_num(cvar_limit_kb))
          {
        
        g_iBlinks[player] += 1;
                g_limit[player] += 1;
        client_print(player, print_chat, "[ZP] Voce tem agora %d Knife Blinks", g_iBlinks[player]);
          }

          else
          {
        
          client_print(player, print_chat, "[ZP] So pode comprar 6 !!!")



          }



    }

        

}

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

// ================================================== //
//             OPERATIONS
// ================================================== //

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] = 1;
            g_fLastSlash[id] = get_gametime();
            g_iBlinks[id] -= 1;
            new name[32];
            get_user_name(id,name,31)
            client_print(0, print_chat, "[ZP] %s usou uma Knife Blink!", name);
            client_print(id, print_chat, "[ZP] %d Knife Blinks remanescente", g_iBlinks[id]);
        }
    }  
}

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

// ================================================== //
//             CHECKS
// ================================================== //

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;
}  

Aqui um tutorial para limitar: https://zplague.forumeiro.com/t5293-tutorial-colocando-limite-de-compras-em-um-item-extra

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Não ta compilando waLL, arruma ae

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Troukill67 escreveu:
Não ta compilando waLL, arruma ae
Tenta agora 

Código:

/*================================================================================
   
    -------------------------------------------
    -*- [ZP] Extra Item: Knife Blink 1.2 -*-
    -------------------------------------------
   
    ~~~~~~~~~~~~~~~
    - Description -
    ~~~~~~~~~~~~~~~
   
    This item/upgrade gives zombies the possibility to move rapidly towards a human over a short distance, when aiming at him and holding down the attack button.
   
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <chr_engine>

#define MIN_DISTANCE 50

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Knife Blink" }
const g_item_cost = 5
const g_iMaxDistance = 300;
new g_limit[33], cvar_limit_kb

/*============================================================================*/

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;

public plugin_init(){
   
    register_plugin("[ZP] Extra Item: Knife Blink", "1.2", "pharse");
   
    g_iMaxPlayers = get_maxplayers();
   
    g_itemid_blink = zp_register_extra_item(g_item_name, g_item_cost, ZP_TEAM_ZOMBIE);

        cvar_limit_kb = register_cvar("zp_limit_kb","5") 
   
    register_forward(FM_TraceLine, "FW_TraceLine_Post", 1);
    register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
   
    register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

// ================================================== //
//            FORWARDS / EVENTS
// ================================================== //

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 (itemid == g_itemid_blink )
        {
 
          if (g_limit[player] <= get_pcvar_num(cvar_limit_kb))
          {
       
        g_iBlinks[player] += 1;
                g_limit[player] += 1;
        client_print(player, print_chat, "[ZP] Voce tem agora %d Knife Blinks", g_iBlinks[player]);
          }

          else
          {
       
          client_print(player, print_chat, "[ZP] So pode comprar 6 !!!")



          }



    }

       

}

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

// ================================================== //
//            OPERATIONS
// ================================================== //

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] = 1;
            g_fLastSlash[id] = get_gametime();
            g_iBlinks[id] -= 1;
            new name[32];
            get_user_name(id,name,31)
            client_print(0, print_chat, "[ZP] %s usou uma Knife Blink!", name);
            client_print(id, print_chat, "[ZP] %d Knife Blinks remanescente", g_iBlinks[id]);
        }
    } 
}

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

// ================================================== //
//            CHECKS
// ================================================== //

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;

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Agora esta obg aee vo testa

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Era mais facil fazer isso o wallyzk já que a knife blink tem um g_has diferente.

Código:

/*================================================================================
  
   -------------------------------------------
   -*- [ZP] Extra Item: Knife Blink 1.2 -*-
   -------------------------------------------
  
   ~~~~~~~~~~~~~~~
   - Description -
   ~~~~~~~~~~~~~~~
  
   This item/upgrade gives zombies the possibility to move rapidly towards a human over a short distance, when aiming at him and holding down the attack button.
  
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <chr_engine>

#define MIN_DISTANCE 50

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Knife Blink" }
const g_item_cost = 5
const g_iMaxDistance = 300;

/*============================================================================*/

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 cvar_limit;

public plugin_init(){
  
   register_plugin("[ZP] Extra Item: Knife Blink", "1.2", "pharse");
  
   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", 1);
   register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
  
   cvar_limit = register_cvar("zp_knife_blink_limit", "6")
  
   register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

// ================================================== //
//          FORWARDS / EVENTS
// ================================================== //

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 (itemid == g_itemid_blink)
   {
      if(g_iBlinks[player] >= get_pcvar_num(cvar_limit))
   {
            client_print(player, print_chat, "[ZP] Voce ja tem o maximo de knifes blinks")  
            zp_set_user_ammo_packs(player, zp_get_user_ammo_packs(player) + g_item_cost)
            return;
   }
   else
   {
         g_iBlinks[player] += 1;
         client_print(player, print_chat, "[ZP] You have now %d Knife Blinks", g_iBlinks[player]);
   }
   }
}

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

// ================================================== //
//          OPERATIONS
// ================================================== //

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] = 1;
         g_fLastSlash[id] = get_gametime();
         g_iBlinks[id] -= 1;
         new name[32];
         get_user_name(id,name,31)
         client_print(0, print_chat, "[ZP] %s just used a Knife Blink!", name);
         client_print(id, print_chat, "[ZP] %d Knife Blinks remaining", g_iBlinks[id]);
      }
   }  
}

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

// ================================================== //
//          CHECKS
// ================================================== //

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;
}

@Troukill67 Testa ai caso o do wallyzk não de certo.

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Vlw scrash mas a do waLLzyk funcionou perfeitamente

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Desculpa mas nessa sma também não consegui colocar limite elas são diferentes

limite de 2 se alguém fazer agradeço

Código:

/*
   [ZP] Extra Item: Concussion Grenade
   Copyright (C) 2009 by NiHiLaNTh

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
   
   In addition, as a special exception, the author gives permission to
   link the code of this program with the Half-Life Game Engine ("HL
   Engine") and Modified Game Libraries ("MODs") developed by Valve,
   L.L.C ("Valve"). You must obey the GNU General Public License in all
   respects for all of the code used other than the HL Engine and MODs
   from Valve. If you modify this file, you may extend this exception
   to your version of the file, but you are not obligated to do so. If
   you do not wish to do so, delete this exception statement from your
   version.

   --- Introduction ---
   This plugin adds new weapon to zombie plague - concussion grenade.I took
   this idead from Team Fortress Classic.When grenade explodes it doesn't
   do any damage, but it starts to make hallucinations to players, such as
   screen shake, screen fade, recoil changes.
   
   --- CVARs ---
   zp_conc_nade_radius 500 -- Explosion radius
   zp_conc_nade_duration 7 -- Duration of hallucinations
   
   --- Credits ---
   NiHiLaNTh - Plugin
   dels/Shalun - Grenade model
   MeRcyLeZZ - Some useful code parts
   xPaw / Xellath - Code optimization
   
   --- Changelog ---
   v1.0 - Initial release
   v1.1 - Optimized code ( Thanks xPaw and Xellath )
   v1.2 - Fixed bug when after explosion player were not affected
   v1.3 - Added p_ and w_ model support
        - Fixed run-time error
        - Made some minor improvements ( MeTaLiCroSS )
   v1.4 - Players are able to carry multiple grenades at the same time    
*/

#include <  amxmodx >
#include <  fakemeta >
#include <  hamsandwich >
#include <  fun >
#include <  zombieplague >

// Plugin version
#define VERSION "1.4"

// Defines
#define MAXPLAYERS    32
#define FCVAR_FLAGS    ( FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
#define OFFSET_PLAYER   41
#define OFFSET_ACTIVE   373
#define LINUX_DIFF   5
#define NADE_TYPE_CONC   7000
#define FFADE_IN   0x0000
#define REPEAT      0.2 // Time when next screen fade/shake message is being sent
#define TASK_AFFECT   666
#define ID_AFFECT   ( taskid - TASK_AFFECT )
#define OFFSET_FLAMMO   387

// Grenade cost
#define GRENADE_COST   15

// Grenade models
new const grenade_model_p [ ] = "models/p_grenade_conc.mdl"
new const grenade_model [ ] = "models/v_grenade_conc.mdl"
new const grenade_model_w [ ] = "models/w_grenade_conc.mdl"

// Sounds
new const explosion_sound [ ] = "zombie_plague/concgren_blast1.wav"
new const purchase_sound [ ] = "items/gunpickup2.wav"
new const purchase_sound2 [ ] = "items/9mmclip1.wav"

// Cached sprite indexes
new m_iTrail, m_iRing

// Item ID
new g_conc

// Player variables
new g_NadeCount [ MAXPLAYERS+1 ]

// Message ID's
new g_msgScreenFade, g_msgScreenShake, g_msgAmmoPickup

// CVAR pointers
new cvar_nade_radius, cvar_duration

// Precache
public plugin_precache ( )
{
   // Precache grenade models
   precache_model ( grenade_model_p )
   precache_model ( grenade_model )
   precache_model ( grenade_model_w )
   
   // Precache sounds
   precache_sound ( explosion_sound )
   precache_sound ( purchase_sound )
   precache_sound ( purchase_sound2 )
   
   // Precache sprites
   m_iRing = precache_model ( "sprites/shockwave.spr" )
   m_iTrail = precache_model ( "sprites/laserbeam.spr" )
}

// Plugin initialization
public plugin_init ( )
{
   // New plugin
   register_plugin ( "[ZP] Extra Item: Concussion Grenade", VERSION, "NiHiLaNTh" )
   
   // Add cvar to detect servers with this plugin
   register_cvar ( "zp_concgren_version", VERSION, FCVAR_FLAGS )
   
   // New extra item
   g_conc = zp_register_extra_item ( "Granada de Alucinacao", GRENADE_COST, ZP_TEAM_ZOMBIE )
   
   // Events
   register_event ( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )
   register_event ( "DeathMsg", "Event_DeathMsg", "a" )
   register_event ( "CurWeapon", "Event_CurrentWeapon", "be", "1=1", "2=25" )
   
   // Forwards
   register_forward ( FM_SetModel, "fw_SetModel" )
   RegisterHam ( Ham_Think, "grenade", "fw_ThinkGrenade" )
   register_forward ( FM_CmdStart, "fw_CmdStart" )
   
   // CVARs
   cvar_nade_radius = register_cvar ( "zp_conc_nade_radius", "500" )
   cvar_duration = register_cvar ( "zp_conc_nade_duration", "7" )
   
   // Messages
   g_msgScreenShake = get_user_msgid ( "ScreenShake" )
   g_msgScreenFade = get_user_msgid ( "ScreenFade" )
   g_msgAmmoPickup = get_user_msgid ( "AmmoPickup" )
}

// Someone decided to buy our an extra item
public zp_extra_item_selected ( Player, Item )
{
   // This is our grenade
   if ( Item == g_conc )
   {
      // Player already have it
      if ( g_NadeCount [ Player ] >= 1 )
      {
         // Increase nade count
         g_NadeCount [ Player ]++
         
         // Increase bp ammo
         set_pdata_int ( Player, OFFSET_FLAMMO, get_pdata_int ( Player, OFFSET_FLAMMO, LINUX_DIFF )+1, LINUX_DIFF )
         
         // Ammo pickup
         message_begin ( MSG_ONE, g_msgAmmoPickup, _, Player )
         write_byte ( 11 ) // Ammo ID
         write_byte ( 1 ) // Ammo amount
         message_end ( )
         
         // Emit sound
         emit_sound ( Player, CHAN_WEAPON, purchase_sound2, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
      }
      else // 0 grenades
      {
         // Increase nade count
         g_NadeCount [ Player ] = 1
         
         // Give him flashbang
         give_item ( Player, "weapon_flashbang" )
         
         // Play purchase sound
         client_cmd ( Player, "spk %s", purchase_sound )   
      }
   }
   return PLUGIN_CONTINUE
}
   
// Someone was infected   
public zp_user_infected_post ( Player, Infector )
{
   // We were affected by concussion grenade
   if ( task_exists ( Player+TASK_AFFECT ) )
      remove_task ( Player+TASK_AFFECT )
}   

// Someone were turned back to human
public zp_user_humanized_post ( Player, Survivor )
{
   // We dont' have nade anymore
   if ( g_NadeCount [ Player ] )
   {
      g_NadeCount [ Player ] = 0
   }
}

// New round started
public Event_NewRound ( )
{
   // Reset nade count
   arrayset ( g_NadeCount, false, 33 )
      
   // And they aren't affected by conc.grenade
   remove_task ( TASK_AFFECT )   
}

// Someone died
public Event_DeathMsg ( )
{
   // Get victim
   new victim = read_data ( 2 )
   
   // Some people had error without this check
   if ( !is_user_connected ( victim ) )
      return
   
   // Remove hallucinations
   remove_task ( victim+TASK_AFFECT )
      
   // Reset nade count   
   g_NadeCount [ victim ] = 0
}

// Current weapon player is holding
public Event_CurrentWeapon ( Player )
{
   // Dead or not zombie or don't have conc. grenade
   if ( !is_user_alive ( Player ) || !zp_get_user_zombie ( Player ) || g_NadeCount [ Player ] <= 0 )
      return PLUGIN_CONTINUE
   
   // Replace flashbang model with our ones
   set_pev ( Player, pev_viewmodel2, grenade_model )
   set_pev ( Player, pev_weaponmodel2, grenade_model_p )
   
   return PLUGIN_CONTINUE
}

// Set model
public fw_SetModel ( Entity, const Model [ ] )
{
   // Prevent invalid ent messages
   if ( !pev_valid ( Entity ) )
      return FMRES_IGNORED
      
   // Grenade not thrown yet   
   if ( pev ( Entity, pev_dmgtime ) == 0.0 )
      return FMRES_IGNORED
      
   // We are throwing concussion grenade   
   if ( g_NadeCount [ pev ( Entity, pev_owner ) ] >= 1 && equal ( Model [7 ], "w_fl", 4 ) )
   {
      //Draw trail
      message_begin ( MSG_BROADCAST, SVC_TEMPENTITY )
      write_byte ( TE_BEAMFOLLOW ) // Temp entity ID
      write_short ( Entity ) // Entity to follow
      write_short ( m_iTrail ) // Sprite index
      write_byte ( 10 ) // Life
      write_byte ( 10 ) // Line width
      write_byte ( 255 ) // Red amount
      write_byte ( 255 ) // Blue amount
      write_byte ( 0 ) // Blue amount
      write_byte ( 255 ) // Alpha
      message_end ( )
      
      // Set grenade entity
      set_pev ( Entity, pev_flTimeStepSound, NADE_TYPE_CONC )
      
      // Decrease nade count
      g_NadeCount [ pev ( Entity, pev_owner ) ]--
      
      // Set world model
      engfunc ( EngFunc_SetModel, Entity, grenade_model_w )
      return FMRES_SUPERCEDE
   }
   return FMRES_IGNORED
}

// Grenade is getting to explode
public fw_ThinkGrenade ( Entity )
{
   // Prevent invalid ent messages
   if ( !pev_valid ( Entity ) )
      return HAM_IGNORED
   
   // Get damage time
   static Float:dmg_time
   pev ( Entity, pev_dmgtime, dmg_time )
   
   // maybe it is time to go off
   if ( dmg_time > get_gametime ( ) )
      return HAM_IGNORED
      
   // Our grenade   
   if ( pev ( Entity, pev_flTimeStepSound ) == NADE_TYPE_CONC )
   {
      // Force to explode
      concussion_explode ( Entity )
      return HAM_SUPERCEDE
   }
   return HAM_IGNORED
}

// Command start
public fw_CmdStart ( Player, UC_Handle, Seed )
{
   // Dead, zombie or not affected
   if ( !is_user_alive ( Player ) || zp_get_user_zombie ( Player ) || !task_exists ( Player+TASK_AFFECT ) )
      return FMRES_IGNORED
   
   // Get buttons
   new buttons = get_uc ( UC_Handle, UC_Buttons )
   
   // We are firing
   if ( buttons & IN_ATTACK )
   {
      // We are holding an active weapon
      if ( get_pdata_cbase ( Player, OFFSET_ACTIVE, LINUX_DIFF ) )
      {
         // New recoil
         set_pev ( Player, pev_punchangle, Float:{3.0, 3.0, 4.0} )
      }
   }
   return FMRES_HANDLED
}
         

// Grenade explode
public concussion_explode ( Entity )
{
   // Invalid entity ?
   if ( !pev_valid ( Entity  ) )
      return
   
   // Get entities origin
   static Float:origin [ 3 ]
   pev ( Entity, pev_origin, origin )
   
   // Draw ring
   UTIL_DrawRing (origin )
   
   // Explosion sound
   emit_sound ( Entity, CHAN_WEAPON, explosion_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
   
   // Collisions
   static victim
   victim = -1
   
   // Find radius
   static Float:radius
   radius = get_pcvar_float ( cvar_nade_radius )
   
   // Find all players in a radius
   while ( ( victim = engfunc ( EngFunc_FindEntityInSphere, victim, origin, radius ) ) != 0 )
   {
      // Dead or zombie
      if ( !is_user_alive ( victim ) || zp_get_user_zombie ( victim ) )
         continue
         
      // Victim isn't affected yet   
      if ( !task_exists ( victim+TASK_AFFECT ) )
      {
         // Get duration
         new duration = get_pcvar_num ( cvar_duration )
         
         // Calculate affect times
         new affect_count = floatround ( duration / REPEAT )
         
         // Continiously affect them
         set_task ( REPEAT, "affect_victim", victim+TASK_AFFECT, _, _, "a", affect_count )
      }
   }
   
   // Remove entity from ground
   engfunc ( EngFunc_RemoveEntity, Entity )
}

// We are going to affect you
public affect_victim ( taskid )
{
   // Dead
   if ( !is_user_alive ( ID_AFFECT ) )
      return
      
   // Make a screen fade
   message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenFade, {0,0,0}, ID_AFFECT )
   write_short ( 1<<13 ) // Duration
   write_short ( 1<<14 ) // Hold Time
   write_short ( FFADE_IN ) // Fade type
   write_byte ( random_num ( 50, 200 ) ) // Red amount
   write_byte ( random_num ( 50, 200 ) ) // Green amount
   write_byte ( random_num ( 50, 200 ) ) // Blue amount
   write_byte ( random_num ( 50, 200 ) ) // Alpha
   message_end ( )
      
   // Make a screen shake
   message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT )
   write_short ( 0xFFFF ) // Amplitude
   write_short ( 1<<13 ) // Duration
   write_short ( 0xFFFF ) // Frequency
   message_end ( )
   
   // Remove task after all
   remove_task ( ID_AFFECT )
}

// Draw explosion ring ( from zombie_plague40.sma )
stock UTIL_DrawRing ( const Float:origin [ 3 ] )
{
   engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
   write_byte(TE_BEAMCYLINDER) // TE id
   engfunc(EngFunc_WriteCoord, origin[0]) // x
   engfunc(EngFunc_WriteCoord, origin[1]) // y
   engfunc(EngFunc_WriteCoord, origin[2]) // z
   engfunc(EngFunc_WriteCoord, origin[0]) // x axis
   engfunc(EngFunc_WriteCoord, origin[1]) // y axis
   engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
   write_short( m_iRing ) // sprite
   write_byte(0) // startframe
   write_byte(0) // framerate
   write_byte(4) // life
   write_byte(60) // width
   write_byte(0) // noise
   write_byte(200) // red
   write_byte(200) // green
   write_byte(200) // blue
   write_byte(200) // brightness
   write_byte(0) // speed
   message_end()
}

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
[P]erfec[T] [S]cr[@]s[H] escreveu:
Era mais facil fazer isso o wallyzk já que a knife blink tem um g_has diferente.

Código:

/*================================================================================
  
   -------------------------------------------
   -*- [ZP] Extra Item: Knife Blink 1.2 -*-
   -------------------------------------------
  
   ~~~~~~~~~~~~~~~
   - Description -
   ~~~~~~~~~~~~~~~
  
   This item/upgrade gives zombies the possibility to move rapidly towards a human over a short distance, when aiming at him and holding down the attack button.
  
================================================================================*/

#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <chr_engine>

#define MIN_DISTANCE 50

/*================================================================================
 [Plugin Customization]
=================================================================================*/

new const g_item_name[] = { "Knife Blink" }
const g_item_cost = 5
const g_iMaxDistance = 300;

/*============================================================================*/

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 cvar_limit;

public plugin_init(){
  
   register_plugin("[ZP] Extra Item: Knife Blink", "1.2", "pharse");
  
   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", 1);
   register_forward(FM_PlayerPreThink, "FW_PlayerPreThink");
  
   cvar_limit = register_cvar("zp_knife_blink_limit", "6")
  
   register_event("HLTV", "EVENT_round_start", "a", "1=0", "2=0")
}

// ================================================== //
//          FORWARDS / EVENTS
// ================================================== //

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 (itemid == g_itemid_blink)
   {
      if(g_iBlinks[player] >= get_pcvar_num(cvar_limit))
   {
            client_print(player, print_chat, "[ZP] Voce ja tem o maximo de knifes blinks")  
            zp_set_user_ammo_packs(player, zp_get_user_ammo_packs(player) + g_item_cost)
            return;
   }
   else
   {
         g_iBlinks[player] += 1;
         client_print(player, print_chat, "[ZP] You have now %d Knife Blinks", g_iBlinks[player]);
   }
   }
}

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

// ================================================== //
//          OPERATIONS
// ================================================== //

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] = 1;
         g_fLastSlash[id] = get_gametime();
         g_iBlinks[id] -= 1;
         new name[32];
         get_user_name(id,name,31)
         client_print(0, print_chat, "[ZP] %s just used a Knife Blink!", name);
         client_print(id, print_chat, "[ZP] %d Knife Blinks remaining", g_iBlinks[id]);
      }
   }  
}

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

// ================================================== //
//          CHECKS
// ================================================== //

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;
}
@Troukill67 Testa ai caso o do wallyzk não de certo.
Melhor? Até onde eu vi você apenas alterou a ordem da condicional, isso seria trocar 6 por meia dúzia.
E melhor do que usar isso:

Código:

zp_set_user_ammo_packs(player, zp_get_user_ammo_packs(player) + g_item_cost)
Seria você usar:

Código:

return ZP_PLUGIN_HANDLED;
Dessa forma não é cobrado o preço do item e você não precisa usar 2 natives a mais no seu código, isso sem contar o fato de que g_item_cost é uma constante, então se no plugin o valor dessa constante é igual a 5 e o admin do servidor alterar o preço do item pelo arquivo zombieplague.ini o plugin vai continuar devolvendo os 5 ammopacks, e não o valor que foi definido no arquivo de configuração citado anteriormente.

@Edit
Granada de alucinação limitada:

Código:

/*
   [ZP] Extra Item: Concussion Grenade
   Copyright (C) 2009 by NiHiLaNTh

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
   In addition, as a special exception, the author gives permission to
   link the code of this program with the Half-Life Game Engine ("HL
   Engine") and Modified Game Libraries ("MODs") developed by Valve,
   L.L.C ("Valve"). You must obey the GNU General Public License in all
   respects for all of the code used other than the HL Engine and MODs
   from Valve. If you modify this file, you may extend this exception
   to your version of the file, but you are not obligated to do so. If
   you do not wish to do so, delete this exception statement from your
   version.

   --- Introduction ---
   This plugin adds new weapon to zombie plague - concussion grenade.I took
   this idead from Team Fortress Classic.When grenade explodes it doesn't
   do any damage, but it starts to make hallucinations to players, such as
   screen shake, screen fade, recoil changes.
  
   --- CVARs ---
   zp_conc_nade_radius 500 -- Explosion radius
   zp_conc_nade_duration 7 -- Duration of hallucinations
  
   --- Credits ---
   NiHiLaNTh - Plugin
   dels/Shalun - Grenade model
   MeRcyLeZZ - Some useful code parts
   xPaw / Xellath - Code optimization
  
   --- Changelog ---
   v1.0 - Initial release
   v1.1 - Optimized code ( Thanks xPaw and Xellath )
   v1.2 - Fixed bug when after explosion player were not affected
   v1.3 - Added p_ and w_ model support
        - Fixed run-time error
        - Made some minor improvements ( MeTaLiCroSS )
   v1.4 - Players are able to carry multiple grenades at the same time    
*/

#include <     amxmodx >
#include <     fakemeta >
#include <     hamsandwich >
#include <     fun >
#include <     zombieplague >

// Plugin version
#define VERSION "1.4"

// Defines
#define MAXPLAYERS    32
#define FCVAR_FLAGS    ( FCVAR_SERVER | FCVAR_SPONLY | FCVAR_UNLOGGED )
#define OFFSET_PLAYER   41
#define OFFSET_ACTIVE   373
#define LINUX_DIFF   5
#define NADE_TYPE_CONC   7000
#define FFADE_IN   0x0000
#define REPEAT      0.2 // Time when next screen fade/shake message is being sent
#define TASK_AFFECT   666
#define ID_AFFECT   ( taskid - TASK_AFFECT )
#define OFFSET_FLAMMO   387

// Grenade cost
#define GRENADE_COST   15

// Grenade models
new const grenade_model_p [ ] = "models/p_grenade_conc.mdl"
new const grenade_model [ ] = "models/v_grenade_conc.mdl"
new const grenade_model_w [ ] = "models/w_grenade_conc.mdl"

// Sounds
new const explosion_sound [ ] = "zombie_plague/concgren_blast1.wav"
new const purchase_sound [ ] = "items/gunpickup2.wav"
new const purchase_sound2 [ ] = "items/9mmclip1.wav"

// Cached sprite indexes
new m_iTrail, m_iRing

// Item ID
new g_conc

// Player variables
new g_NadeCount [ MAXPLAYERS+1 ]
new g_gNadeCount [ MAXPLAYERS+1 ]

// Message ID's
new g_msgScreenFade, g_msgScreenShake, g_msgAmmoPickup

// CVAR pointers
new cvar_nade_radius, cvar_duration, cvar_max_nades

// Precache
public plugin_precache ( )
{
   // Precache grenade models
   precache_model ( grenade_model_p )
   precache_model ( grenade_model )
   precache_model ( grenade_model_w )
  
   // Precache sounds
   precache_sound ( explosion_sound )
   precache_sound ( purchase_sound )
   precache_sound ( purchase_sound2 )
  
   // Precache sprites
   m_iRing = precache_model ( "sprites/shockwave.spr" )
   m_iTrail = precache_model ( "sprites/laserbeam.spr" )
}

// Plugin initialization
public plugin_init ( )
{
   // New plugin
   register_plugin ( "[ZP] Extra Item: Concussion Grenade", VERSION, "NiHiLaNTh" )
  
   // Add cvar to detect servers with this plugin
   register_cvar ( "zp_concgren_version", VERSION, FCVAR_FLAGS )
  
   // New extra item
   g_conc = zp_register_extra_item ( "Granada de Alucinacao", GRENADE_COST, ZP_TEAM_ZOMBIE )
  
   // Events
   register_event ( "HLTV", "Event_NewRound", "a", "1=0", "2=0" )
   register_event ( "DeathMsg", "Event_DeathMsg", "a" )
   register_event ( "CurWeapon", "Event_CurrentWeapon", "be", "1=1", "2=25" )
  
   // Forwards
   register_forward ( FM_SetModel, "fw_SetModel" )
   RegisterHam ( Ham_Think, "grenade", "fw_ThinkGrenade" )
   register_forward ( FM_CmdStart, "fw_CmdStart" )
  
   // CVARs
   cvar_nade_radius = register_cvar ( "zp_conc_nade_radius", "500" )
   cvar_duration = register_cvar ( "zp_conc_nade_duration", "7" )
   cvar_max_nades = register_cvar ( "zp_conc_nade_max", "2" )
  
   // Messages
   g_msgScreenShake = get_user_msgid ( "ScreenShake" )
   g_msgScreenFade = get_user_msgid ( "ScreenFade" )
   g_msgAmmoPickup = get_user_msgid ( "AmmoPickup" )
}

// Someone decided to buy our an extra item
public zp_extra_item_selected ( Player, Item )
{
   // This is our grenade
   if ( Item == g_conc )
   {
      if(g_gNadeCount [ Player ] >= get_pcvar_num(cvar_max_nades))
     {
      client_print(Player, print_chat, "[ZP] VOce ja comprou muitas Granadas de Alucinacao!");
      return ZP_PLUGIN_HANDLED;
     }
   
      // Player already have it
      if ( g_NadeCount [ Player ] >= 1 )
      {
      
         // Increase nade count
         g_NadeCount [ Player ]++
         g_gNadeCount [ Player ]++
        
         // Increase bp ammo
         set_pdata_int ( Player, OFFSET_FLAMMO, get_pdata_int ( Player, OFFSET_FLAMMO, LINUX_DIFF )+1, LINUX_DIFF )
        
         // Ammo pickup
         message_begin ( MSG_ONE, g_msgAmmoPickup, _, Player )
         write_byte ( 11 ) // Ammo ID
         write_byte ( 1 ) // Ammo amount
         message_end ( )
        
         // Emit sound
         emit_sound ( Player, CHAN_WEAPON, purchase_sound2, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
      }
      else // 0 grenades
      {
         // Increase nade count
         g_NadeCount [ Player ] = g_gNadeCount[ Player ] = 1
        
         // Give him flashbang
         give_item ( Player, "weapon_flashbang" )
        
         // Play purchase sound
         client_cmd ( Player, "spk %s", purchase_sound )  
      }
   }
   return PLUGIN_CONTINUE
}
  
// Someone was infected  
public zp_user_infected_post ( Player, Infector )
{
   // We were affected by concussion grenade
   if ( task_exists ( Player+TASK_AFFECT ) )
      remove_task ( Player+TASK_AFFECT )
}  

// Someone were turned back to human
public zp_user_humanized_post ( Player, Survivor )
{
   // We dont' have nade anymore
   if ( g_NadeCount [ Player ] )
   {
      g_NadeCount [ Player ] = 0
      g_gNadeCount [ Player ] = 0
   }
}

// New round started
public Event_NewRound ( )
{
   // Reset nade count
   arrayset ( g_NadeCount, false, 33 )
   arrayset ( g_gNadeCount, false, 33 )
      
   // And they aren't affected by conc.grenade
   remove_task ( TASK_AFFECT )  
}

// Someone died
public Event_DeathMsg ( )
{
   // Get victim
   new victim = read_data ( 2 )
  
   // Some people had error without this check
   if ( !is_user_connected ( victim ) )
      return
  
   // Remove hallucinations
   remove_task ( victim+TASK_AFFECT )
      
   // Reset nade count  
   g_NadeCount [ victim ] = 0
   g_gNadeCount [ victim ] = 0
}

// Current weapon player is holding
public Event_CurrentWeapon ( Player )
{
   // Dead or not zombie or don't have conc. grenade
   if ( !is_user_alive ( Player ) || !zp_get_user_zombie ( Player ) || g_NadeCount [ Player ] <= 0 )
      return PLUGIN_CONTINUE
  
   // Replace flashbang model with our ones
   set_pev ( Player, pev_viewmodel2, grenade_model )
   set_pev ( Player, pev_weaponmodel2, grenade_model_p )
  
   return PLUGIN_CONTINUE
}

// Set model
public fw_SetModel ( Entity, const Model [ ] )
{
   // Prevent invalid ent messages
   if ( !pev_valid ( Entity ) )
      return FMRES_IGNORED
      
   // Grenade not thrown yet  
   if ( pev ( Entity, pev_dmgtime ) == 0.0 )
      return FMRES_IGNORED
      
   // We are throwing concussion grenade  
   if ( g_NadeCount [ pev ( Entity, pev_owner ) ] >= 1 && equal ( Model [7 ], "w_fl", 4 ) )
   {
      //Draw trail
      message_begin ( MSG_BROADCAST, SVC_TEMPENTITY )
      write_byte ( TE_BEAMFOLLOW ) // Temp entity ID
      write_short ( Entity ) // Entity to follow
      write_short ( m_iTrail ) // Sprite index
      write_byte ( 10 ) // Life
      write_byte ( 10 ) // Line width
      write_byte ( 255 ) // Red amount
      write_byte ( 255 ) // Blue amount
      write_byte ( 0 ) // Blue amount
      write_byte ( 255 ) // Alpha
      message_end ( )
      
      // Set grenade entity
      set_pev ( Entity, pev_flTimeStepSound, NADE_TYPE_CONC )
      
      // Decrease nade count
      g_NadeCount [ pev ( Entity, pev_owner ) ]--
      
      // Set world model
      engfunc ( EngFunc_SetModel, Entity, grenade_model_w )
      return FMRES_SUPERCEDE
   }
   return FMRES_IGNORED
}

// Grenade is getting to explode
public fw_ThinkGrenade ( Entity )
{
   // Prevent invalid ent messages
   if ( !pev_valid ( Entity ) )
      return HAM_IGNORED
  
   // Get damage time
   static Float:dmg_time
   pev ( Entity, pev_dmgtime, dmg_time )
  
   // maybe it is time to go off
   if ( dmg_time > get_gametime ( ) )
      return HAM_IGNORED
      
   // Our grenade  
   if ( pev ( Entity, pev_flTimeStepSound ) == NADE_TYPE_CONC )
   {
      // Force to explode
      concussion_explode ( Entity )
      return HAM_SUPERCEDE
   }
   return HAM_IGNORED
}

// Command start
public fw_CmdStart ( Player, UC_Handle, Seed )
{
   // Dead, zombie or not affected
   if ( !is_user_alive ( Player ) || zp_get_user_zombie ( Player ) || !task_exists ( Player+TASK_AFFECT ) )
      return FMRES_IGNORED
  
   // Get buttons
   new buttons = get_uc ( UC_Handle, UC_Buttons )
  
   // We are firing
   if ( buttons & IN_ATTACK )
   {
      // We are holding an active weapon
      if ( get_pdata_cbase ( Player, OFFSET_ACTIVE, LINUX_DIFF ) )
      {
         // New recoil
         set_pev ( Player, pev_punchangle, Float:{3.0, 3.0, 4.0} )
      }
   }
   return FMRES_HANDLED
}
        

// Grenade explode
public concussion_explode ( Entity )
{
   // Invalid entity ?
   if ( !pev_valid ( Entity  ) )
      return
  
   // Get entities origin
   static Float:origin [ 3 ]
   pev ( Entity, pev_origin, origin )
  
   // Draw ring
   UTIL_DrawRing (origin )
  
   // Explosion sound
   emit_sound ( Entity, CHAN_WEAPON, explosion_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
  
   // Collisions
   static victim
   victim = -1
  
   // Find radius
   static Float:radius
   radius = get_pcvar_float ( cvar_nade_radius )
  
   // Find all players in a radius
   while ( ( victim = engfunc ( EngFunc_FindEntityInSphere, victim, origin, radius ) ) != 0 )
   {
      // Dead or zombie
      if ( !is_user_alive ( victim ) || zp_get_user_zombie ( victim ) )
         continue
        
      // Victim isn't affected yet  
      if ( !task_exists ( victim+TASK_AFFECT ) )
      {
         // Get duration
         new duration = get_pcvar_num ( cvar_duration )
        
         // Calculate affect times
         new affect_count = floatround ( duration / REPEAT )
        
         // Continiously affect them
         set_task ( REPEAT, "affect_victim", victim+TASK_AFFECT, _, _, "a", affect_count )
      }
   }
  
   // Remove entity from ground
   engfunc ( EngFunc_RemoveEntity, Entity )
}

// We are going to affect you
public affect_victim ( taskid )
{
   // Dead
   if ( !is_user_alive ( ID_AFFECT ) )
      return
      
   // Make a screen fade
   message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenFade, {0,0,0}, ID_AFFECT )
   write_short ( 1<<13 ) // Duration
   write_short ( 1<<14 ) // Hold Time
   write_short ( FFADE_IN ) // Fade type
   write_byte ( random_num ( 50, 200 ) ) // Red amount
   write_byte ( random_num ( 50, 200 ) ) // Green amount
   write_byte ( random_num ( 50, 200 ) ) // Blue amount
   write_byte ( random_num ( 50, 200 ) ) // Alpha
   message_end ( )
      
   // Make a screen shake
   message_begin ( MSG_ONE_UNRELIABLE, g_msgScreenShake, {0,0,0}, ID_AFFECT )
   write_short ( 0xFFFF ) // Amplitude
   write_short ( 1<<13 ) // Duration
   write_short ( 0xFFFF ) // Frequency
   message_end ( )
  
   // Remove task after all
   remove_task ( ID_AFFECT )
}

// Draw explosion ring ( from zombie_plague40.sma )
stock UTIL_DrawRing ( const Float:origin [ 3 ] )
{
   engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, origin, 0)
   write_byte(TE_BEAMCYLINDER) // TE id
   engfunc(EngFunc_WriteCoord, origin[0]) // x
   engfunc(EngFunc_WriteCoord, origin[1]) // y
   engfunc(EngFunc_WriteCoord, origin[2]) // z
   engfunc(EngFunc_WriteCoord, origin[0]) // x axis
   engfunc(EngFunc_WriteCoord, origin[1]) // y axis
   engfunc(EngFunc_WriteCoord, origin[2]+555.0) // z axis
   write_short( m_iRing ) // sprite
   write_byte(0) // startframe
   write_byte(0) // framerate
   write_byte(4) // life
   write_byte(60) // width
   write_byte(0) // noise
   write_byte(200) // red
   write_byte(200) // green
   write_byte(200) // blue
   write_byte(200) // brightness
   write_byte(0) // speed
   message_end()
}

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Obrigado waLLzyk scrash e Spriite ajudou muito, plug-ins pegando corretamente

pode fechar o tópico!

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
Fechado!

description[Ajuda] limitando esse item EmptyRe: [Ajuda] limitando esse item

more_horiz
privacy_tip Permissões neste sub-fórum
Não podes responder a tópicos
power_settings_newInicie sessão para responder