[FAQ]armoury_entity

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

[FAQ]armoury_entity

Post by Archive-Poster »

I've seen a number of questions related to this topic, so I thought that such a FAQ is welcome.

What is an armoury_entity ? armoury_entity is the weapons that is spawned on the ground (like in fy_snow). This does not include the dropped weapons which are weaponboxes. If you pickup an armoury_entity and drop, it will be no longer an armoury_entity, but an weaponbox ent. An armoury_entity can hold more than one weapon.

Before you begin you need to know the armoury_entity indexs, this is what you will use.

Code: Select all

enum
{
	ARM_MP5, //0
	ARM_TMP,
	ARM_P90,
	ARM_MAC10,
	ARM_AK47,
	ARM_SG552,
	ARM_M4A1,
	ARM_AUG,
	ARM_SCOUT,
	ARM_G3SG1,
	ARM_AWP,
	ARM_M3,
	ARM_XM1014,
	ARM_M249,
	ARM_FLASHBANG,
	ARM_HEGRENADE,
	ARM_KEVLAR,
	ARM_ASSAULT,
	ARM_SMOKEGRENADE //18
}
You can name them whatever you want, but I choosed ARM_WPNNAME. The first one is 0 and the last one is 18.

The models for armoury_entity:

Code: Select all

"models/w_mp5.mdl",       
"models/w_tmp.mdl",        
"models/w_p90.mdl",    
"models/w_mac10.mdl",       
"models/w_ak47.mdl",       
"models/w_sg552.mdl",       
"models/w_m4a1.mdl",       
"models/w_aug.mdl",        
"models/w_scout.mdl",      
"models/w_g3sg1.mdl",      
"models/w_awp.mdl",         
"models/w_m3.mdl",          
"models/w_xm1014.mdl",    
"models/w_m249.mdl",        
"models/w_flashbang.mdl",   
"models/w_hegrenade.mdl",  
"models/w_kevlar.mdl",
"models/w_assault.mdl",     
"models/w_smokegrenade.mdl"
Note that you can't have armoury_entity with c4, knife, pistols, famas and galil.

Some offset that we will use:

Code: Select all

const XO_CArmoury = 4 //diff windows/linux
const m_iType = 34 // armoury_entity index( see above enum )
const m_iCount = 35// hold the number of weapons that the armoury_entity will have
Ok, let's begin:

1.Hook touch with an armoury_entity:

Code: Select all

#include <hamsandwich>
#include <cstrike>

//Hook as pre
RegisterHam(Ham_Touch, "armoury_entity", "CBaseEntity_Touch", false)

public CBaseEntity_Touch( iTouched, iToucher )
{
        //iTouched is the armoury_entity that is touched
        //iToucher is the entity index that touch the armoury_entity. It is not 100% a player, you need to check it's classname or use engine's register_touch with allow you to specify the toucher class too.
    new armouryIndex = cs_get_armoury_type(iTouched)
        //If you need to block return HAM_SUPERCEDE
        //If you need to block just for one weapon check if armouryIndex is what you want and supercede
       //cs_get_armoury_type return CSW_ indexs and not the one from the above list.
}
2.Create an armoury entity:

Code: Select all

enum
{
    ARM_MP5, //0
    ARM_TMP,
    ARM_P90,
    ARM_MAC10,
    ARM_AK47,
    ARM_SG552,
    ARM_M4A1,
    ARM_AUG,
    ARM_SCOUT,
    ARM_G3SG1,
    ARM_AWP,
    ARM_M3,
    ARM_XM1014,
    ARM_M249,
    ARM_FLASHBANG,
    ARM_HEGRENADE,
    ARM_KEVLAR,
    ARM_ASSAULT,
    ARM_SMOKEGRENADE //18
}

stock CreateArmouryEntity( itemType, itemCount, Float: fOrigin[ ] )
{
    new armouryEnt = create_entity("armoury_entity")
    if(!armouryEnt)
    {
        return -1
    }
    
    if(itemType < ARM_MP5 || itemType > ARM_SMOKEGRENADE)
    {
        return -1
    }
    
    set_pev(armouryEnt, pev_origin, fOrigin)
    set_pdata_int(armouryEnt, m_iType, itemType, XO_CArmoury)
    set_pdata_int(armouryEnt, m_iCount, itemCount, XO_CArmoury)
    dllfunc(DLLFunc_Spawn, armouryEnt)
    return armouryEnt
}
itemType is the index from the above enum( ARM_ )
itemCount is the number of the weapons that the armoury entity will hold.
fOrigin is the origin where the armoury_entity will be spawned.
The stock above will return -1 on failure/ the armoury index otherwise.

3.Remove all armoury_entity from the map:

Code: Select all

new armouryEnt = -1
while((armouryEnt = find_ent_by_class(armouryEnt, "armoury_entity"))
{
    remove_entity(armouryEnt)
}
User avatar
Archive-Poster
Posts: 1267
Gender:
United States of America

Re: [FAQ]armoury_entity

Post by Archive-Poster »

remove_entity and remove_entity_name are the same thing, the last one is a stock which call remove_entity on the specified classname(it loops all ents that have the given identifier). Since remove means actually remove, using such functions on armoury_entities will make them unable to spawn on new round.
Metalicross way sets the item count to 0, so it will contain 0 weapons of it's type and make them invisible, this is the trick.

Now, why removing them make them unable to respawn ?

When the item count from an armoury is decremented to 0 the armoury will get hidden and on new round the m_iCount is restored, so the actual ent is not removed when m_iCount is 0.

Code: Select all

void CArmoury::ArmouryTouch( CBaseEntity *pOther )
{
    if( pOther->IsPlayer() && !pOther->m_fIsVIP )
    {
        if( m_iCount > 0 )
        {
            if( m_iItem <= 13 )
            {
                if( pOther->m_fHasPrimaryWeapon )
                {
                    return;
                }
                
                m_iCount--;

                switch ( m_iItem )
                {
                  case 0 :
                    pOther->GiveNamedItem( "weapon_mp5navy" );
                    pOther->GiveAmmo( 60, "9mm", 120 );
                    break;
                  case 1 :
                    pOther->GiveNamedItem( "weapon_tmp" );
                    pOther->GiveAmmo( 60, "9mm", 120 );
                    break;
                  case 2 :
                    pOther->GiveNamedItem( "weapon_p90" );
                    pOther->GiveAmmo( 50, "57mm", 100 );
                    break;
                  case 3 :
                    pOther->GiveNamedItem( "weapon_mac10" );
                    pOther->GiveAmmo( 60, "45acp", 100 );
                    break;
                  case 4 :
                    pOther->GiveNamedItem( "weapon_ak47" );
                    pOther->GiveAmmo( 60, "762Nato", 90 );
                    break;
                  case 5 :
                    pOther->GiveNamedItem( "weapon_sg552" );
                    pOther->GiveAmmo( 60, "556Nato", 90 );
                    break;
                  case 6 :
                    pOther->GiveNamedItem( "weapon_m4a1" );
                    pOther->GiveAmmo( 60, "556Nato", 90 );
                    break;
                  case 7 :
                    pOther->GiveNamedItem( "weapon_aug" );
                    pOther->GiveAmmo( 60, "556Nato", 90 );
                    break;
                  case 8 :
                    pOther->GiveNamedItem( "weapon_scout" );
                    pOther->GiveAmmo( 30, "762Nato", 90 );
                    break;
                  case 9 :
                    pOther->GiveNamedItem( "weapon_g3sg1" );
                    pOther->GiveAmmo( 30, "762Nato", 90 );
                    break;
                  case 10 :
                    pOther->GiveNamedItem( "weapon_awp" );
                    pOther->GiveAmmo( 20, "338Magnum", 30 );
                    break;
                  case 11 :
                    pOther->GiveNamedItem( "weapon_m3" );
                    pOther->GiveAmmo( 24, "buckshot", 32 );
                    break;
                  case 12 :
                    pOther->GiveNamedItem( "weapon_xm1014" );
                    pOther->GiveAmmo( 24, "buckshot", 32 );
                    break;
                  case 13 :
                    pOther->GiveNamedItem( "weapon_m249" );
                    pOther->GiveAmmo( 60, "556NatoBox", 200 );
                    break;
                  default:
                    break;
                }
            }
            else
            {
                switch ( m_iItem )
                {
                  case 14 :
                    if( pOther->AmmoInventory( pOther->GetAmmoIndex( "Flashbang" ) ) >= 2 )
                        return;
                    pOther->GiveNamedItem( "weapon_flashbang" );
                    break;
                  case 15 :
                    if( pOther->AmmoInventory( pOther->GetAmmoIndex( "HEGrenade" ) ) >= 1 )
                        return;
                    pOther->GiveNamedItem( "weapon_hegrenade" );
                    break;
                  case 16 :
                    if( m_iKevlar == 1 )
                        return;
                    pOther->GiveNamedItem( "item_kevlar" );
                    break;
                  case 17 :
                    if( m_iKevlar == 2 )
                        return;
                    pOther->GiveNamedItem( "item_assaultsuit" );
                    break;
                  case 18 :
                    if( pOther->AmmoInventory( pOther->GetAmmoIndex( "SmokeGrenade" ) ) >= 1 )
                        return;
                    pOther->GiveNamedItem( "weapon_smokegrenade" );
                    break;
                  default:
                    break;
                }
                
                m_iCount--;
            }
        }
        
        if( !m_iCount )
        {
             pev->effects |= EF_NODRAW;
        }
    }
} 

Code: Select all

if( !m_iCount )
{
             pev->effects |= EF_NODRAW;
} 
The snippet shows that when the item count is 0 the armoury is set to invisible.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests