Thread: [Subplugin Submission] [ZP] Extra Item: Gas Mask
View Single Post
wicho
Veteran Member
Join Date: Feb 2012
Location: GuateAmala
Old 06-01-2013 , 16:50   Re: [ZP] Extra Item: Gas Mask
Reply With Quote #92

Try..

PHP Code:
/*

                           [ZP] Anti Infect Bomb 
                            - other name - 
                               Gas Mask

    Description: 
    [   Removes bombs that is thrown at zombie        ] 
    [   (it will remove everything in range of 150)   ]

    Credits to : 
    [     AmineKyo     ]
    [    Nick Haldem   ]
    [     Excalibur    ]
    [      micapat     ]
    [       Y060N      ]
    
    Version : 
    [2.2 - Final modifying]
*/

#include < amxmodx >
#include < hamsandwich >
#include < engine >

#include <zp50_core>
#include <zp50_items>
#include <zp50_ammopacks>

#define _PLUGIN   "[ZP50] Extra item: Gas Mask"
#define _VERSION             "2.2"
#define _AUTHOR           "H.RED.ZONE"

#define _MarkPlayerInMask(%0)   _bitPlayerInMask |= (1 << (%0 & 31))
#define _ClearPlayerInMask(%0)  _bitPlayerInMask &= ~(1 << (%0 & 31))
#define _IsPlayerInMask(%0)     _bitPlayerInMask & (1 << (%0 & 31))

#define _MarkPlayerConnected(%0)  _bitPlayerConnected |= (1 << (%0 & 31))
#define _ClearPlayerConnected(%0) _bitPlayerConnected &= ~(1 << (%0 & 31))
#define _IsPlayerConnected(%0)    _bitPlayerConnected & (1 << (%0 & 31))

#define _MarkPlayerAlive(%0)  _bitPlayerAlive |= (1 << (%0 & 31))
#define _ClearPlayerAlive(%0) _bitPlayerAlive &= ~(1 << (%0 & 31))
#define _IsPlayerAlive(%0)    _bitPlayerAlive & (1 << (%0 & 31))

#define EV_INT_nadetype     EV_INT_flTimeStepSound
#define NADETYPE_INFECTION  1111 

#define COST   20           // Item Cost

new g_itemid_buyremoverh
new g_icon 

new _pcvar_range
    
,_pcvar_after_remove
    
,_pcvar_prefix
    
,_pcvar_limit
    
new _bitPlayerInMask
    
,_bitPlayerAlive
    
,_bitPlayerConnected

new g_MsgSayText
    
,g_MaxPlayers
    
,g_Limit[33]
    
new const 
plr_command[][] = {
    
"say /mask",
    
"say_team /mask"    
}    
    
public 
plugin_init() {
    
register_plugin_PLUGIN_VERSION_AUTHOR )
    
    
RegisterHam(Ham_Killed"player""fw_PlayerKilled")
    
RegisterHam(Ham_Spawn"player""fw_PlayerSpawn")
    
RegisterHam(Ham_Think"grenade""fw_ThinkGrenade"1)
    
    
g_itemid_buyremoverh zp_items_register("Gas Mask" COST)
    
    
register_event"HLTV""NewRound""a""1=0""2=0" )
  
    for ( new 
IndexIndex sizeof plr_commandIndex++)
        
register_clcmd(plr_command[Index], "buy_mask")
  
    
_pcvar_range register_cvar"zp_gas_remover_range""200" )
    
_pcvar_after_remove register_cvar"zp_gas_remover_after""1" )
    
_pcvar_prefix register_cvar("zp_gas_mask_prefix""Mask")
    
_pcvar_limit register_cvar("zp_gas_mask_limit""1")
    
    
g_MsgSayText get_user_msgid("SayText");
    
g_MaxPlayers get_maxplayers()
    
g_icon get_user_msgid("StatusIcon"
}

public 
zp_fw_items_select_pre(iditemid
{
    if (
itemid == g_itemid_buyremoverh
        {
        if (
zp_core_is_zombie(id))
            return 
ZP_ITEM_DONT_SHOW;
        
        if ( 
g_Limit[id] >= get_pcvar_num _pcvar_limit ) )
            return 
ZP_ITEM_NOT_AVAILABLE;
        
        return 
ZP_ITEM_AVAILABLE;
    }
    return 
ZP_ITEM_AVAILABLE;
}

public 
zp_fw_items_select_post(plritemidignorecost)
{
        if (
itemid == g_itemid_buyremoverh
        {
        
_MarkPlayerInMaskplr )
        
ProtoChat(plr"You now have Gas Mask.")
        
Icon_On(plr)
        
g_Limit[plr]++
        }
}  

public 
buy_mask(id) {
    new 
AmmoPacks zp_ammopacks_get(id)
    
    if( 
AmmoPacks COST) {
        
_MarkPlayerInMask(id)
        
zp_ammopacks_set(idAmmoPacks COST);
        
g_Limit[id]++
    }
    else {
        
ProtoChat(id"You can't buy^x04 Gas Mask^x01 now.")
    }    
}

public 
fw_ThinkGrenadeentity ) {
    if( 
is_valid_ententity ) && entity_get_intentityEV_INT_nadetype ) == NADETYPE_INFECTION  ) { 
        new 
_cvar_range get_pcvar_num_pcvar_range 
        new 
_cvar_after_remove get_pcvar_num_pcvar_after_remove )
        
        for( new 
id id <= g_MaxPlayers id++ ) {
            if( 
_IsPlayerAliveid ) && _IsPlayerInMaskid )) {
                            if( 
get_entity_distanceentityid ) <= _cvar_range ) {
                                
remove_entityentity )
                        
                                if( 
_cvar_after_remove ) {
                                        
_ClearPlayerInMaskid )
                            
                                        
Icon_Off(id)    
                                        
ProtoChat(id"Infect nade is removed, you don't have mask anymore.")
                                }
                            }
                    }
                }
        }
    return 
HAM_IGNORED;
}  

public 
NewRound() 
{

     for ( new 
plrplr <= g_MaxPlayersplr++) 
    {
    
_bitPlayerInMask 0
    g_Limit
[plr] = 0
    
}
}

public 
client_connectplr )
{
    
_MarkPlayerConnectedplr )    
}

public 
client_disconnectplr 
{
    
_ClearPlayerConnectedplr )
    
Icon_Offplr )    
}

public 
zp_user_infected_postid )
{
    
_ClearPlayerInMaskid )
    
Icon_Offid )    
}

public 
zp_user_infected_preid 
{
    
_ClearPlayerInMaskid )
    
Icon_Offid )    


public 
Icon_On(plr) {
    
message_beginMSG_ONE_UNRELIABLEg_icon, { 00}, plr );
    
write_byte);
    
write_string"dmg_gas" );
    
write_byte);
    
write_byte255 );
    
write_byte);
    
message_end( );
}
    
public 
Icon_Off(plr) {
    
message_beginMSG_ONE_UNRELIABLEg_icon, { 00}, plr );
    
write_byte);
    
write_string"dmg_gas" );
    
write_byte);
    
write_byte255 );
    
write_byte);
    
message_end( );
}
    
public 
fw_PlayerKilled(plrattackershouldgib) {
    if(
_IsPlayerConnected(plr)) {
        
_ClearPlayerAlive(plr)
        
Icon_Off(plr)    
    }
}

public 
fw_PlayerSpawn(plr) {
    if(
_IsPlayerConnected(plr)) {
        
_MarkPlayerAlive(plr)
        
Icon_Off(plr)
    }
}

ProtoChat (plr, const sFormat[], any:...) {
    static 
iplr plr get_player();
    if ( !
) {
        return 
PLUGIN_HANDLED;
    }
    
    new 
sPrefix[16];
    
get_pcvar_string(_pcvar_prefixsPrefix15);
    
    new 
sMessage[256];
    new 
len formatex(sMessage255"^x01[^x04%s^x01] "sPrefix);
    
vformat(sMessage[len], 255-lensFormat3)
    
sMessage[192] = '^0' 
    
    
Make_SayText(plrisMessage)
    
    return 
PLUGIN_CONTINUE;
}

get_player() {
    for ( new 
plrplr <= g_MaxPlayersplr++) {
        if (
_IsPlayerConnected(plr)) {
            return 
plr;
        }
    }
    return 
PLUGIN_HANDLED
}

Make_SayText(ReceiverSendersMessage[]) {
    if (!
Sender) {
        return 
PLUGIN_HANDLED;
    }
    
message_begin(Receiver MSG_ONE_UNRELIABLE MSG_ALLg_MsgSayText, {0,0,0}, Receiver)
    
write_byte(Sender)
    
write_string(sMessage)
    
message_end()
    
    return 
PLUGIN_CONTINUE;

wicho is offline