AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [FAQ]armoury_entity (https://forums.alliedmods.net/showthread.php?t=250922)

HamletEagle 11-02-2014 05:20

[FAQ]armoury_entity
 

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:

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:

"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:
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:
#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:
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:
new armouryEnt = -1 while((armouryEnt = find_ent_by_class(armouryEnt, "armoury_entity")) {     remove_entity(armouryEnt) }

I'm waiting for suggestion and comments.

Please check this post: https://forums.alliedmods.net/showpo...8&postcount=10 in order to find out how armoury entities are hidden when they contain 0 weapons and how they are restored.

bibu 11-02-2014 07:13

Re: [FAQ]armoury_entity
 
Good tutorial. Though AFAIK you don't need to use the models enum. Using this should be enough:

PHP Code:

    //cs_set_armoury_type(armouryEnt, itemType)
    
ExecuteHamB(Ham_SpawnarmouryEnt


HamletEagle 11-02-2014 07:20

Re: [FAQ]armoury_entity
 
It seems that you are right, game sets the model on it's own. But I'll let the model list, in case someone wants to know.

Arkshine 11-02-2014 07:45

Re: [FAQ]armoury_entity
 
I thought defines were existing for armoury_entity, but I guess it's defined only in cstrike module. It would be probably welcomed to define that in amxconst.inc as well.

GuskiS 11-03-2014 06:04

Re: [FAQ]armoury_entity
 
You shouldn't set origin with set_pev.
Is there a way to set ammo for weapon inside that ent? Or, what happens when setting more than one count? Also, how to set other weapons in armoury entity? I'm not sure, but if I remember correctly, via valve hammer editor you could set weapon, then count, then set other weapon and it's count (I could be wrong, did mapping long time ago, will check later).

HamletEagle 11-03-2014 10:42

Re: [FAQ]armoury_entity
 
No, it's perfectly fine with set_pev. EngFunc_SetOrigins is usefull for linking the entity with the world, I don't think this is needed now, so we can reduce the code that is called internally.

I don't think you can change the default ammo directly, like an offset, will check that.

Aydeev 01-12-2015 18:39

Re: [FAQ]armoury_entity
 
Quote:

Originally Posted by HamletEagle (Post 2219096)


3.Remove all armoury_entity from the map:

Code:

      new armouryEnt = -1 while((armouryEnt = find_ent_by_class(armouryEnt, "armoury_entity")) { &nbsp;&nbsp;&nbsp;&nbsp;remove_entity(armouryEnt) }

Why does this remove the entities for the remainder of the map? Since picked up weapons respawn each round I would have thought removing them would make them reappear again next round.

I want to remove all armoury_entity entities for round 1 only since we play a map that only gives the Terror team AKs and that gives them an unfair advantage in the first round

meTaLiCroSS 01-15-2015 20:34

Re: [FAQ]armoury_entity
 
Quote:

Originally Posted by Aydeev (Post 2248453)
Why does this remove the entities for the remainder of the map? Since picked up weapons respawn each round I would have thought removing them would make them reappear again next round.

I want to remove all armoury_entity entities for round 1 only since we play a map that only gives the Terror team AKs and that gives them an unfair advantage in the first round

PHP Code:

new armouryEnt = -1
while((armouryEnt find_ent_by_class(armouryEnt"armoury_entity"))
{
    
set_pdata_int(armouryEntm_iCount0XO_CArmoury);
    
set_pev(armouryEntpev_effectspev(armouryEntpev_effects) | EF_NODRAW);



RateX 01-15-2015 20:50

Re: [FAQ]armoury_entity
 
Quote:

Originally Posted by meTaLiCroSS (Post 2249733)
PHP Code:

new armouryEnt = -1
while((armouryEnt find_ent_by_class(armouryEnt"armoury_entity"))
{
    
set_pdata_int(armouryEntm_iCount0XO_CArmoury);
    
set_pev(armouryEntpev_effectspev(armouryEntpev_effects) | EF_NODRAW);



So remove_entity/remove_entity_by_name will prevent them from spawning again in the rounds after entirely?

HamletEagle 01-16-2015 12:32

Re: [FAQ]armoury_entity
 
Well...yes.

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.

Look at this decompiled code by Arkshine:
PHP Code:

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

                switch ( 
m_iItem )
                {
                  case 
:
                    
pOther->GiveNamedItem"weapon_mp5navy" );
                    
pOther->GiveAmmo60"9mm"120 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_tmp" );
                    
pOther->GiveAmmo60"9mm"120 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_p90" );
                    
pOther->GiveAmmo50"57mm"100 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_mac10" );
                    
pOther->GiveAmmo60"45acp"100 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_ak47" );
                    
pOther->GiveAmmo60"762Nato"90 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_sg552" );
                    
pOther->GiveAmmo60"556Nato"90 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_m4a1" );
                    
pOther->GiveAmmo60"556Nato"90 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_aug" );
                    
pOther->GiveAmmo60"556Nato"90 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_scout" );
                    
pOther->GiveAmmo30"762Nato"90 );
                    break;
                  case 
:
                    
pOther->GiveNamedItem"weapon_g3sg1" );
                    
pOther->GiveAmmo30"762Nato"90 );
                    break;
                  case 
10 :
                    
pOther->GiveNamedItem"weapon_awp" );
                    
pOther->GiveAmmo20"338Magnum"30 );
                    break;
                  case 
11 :
                    
pOther->GiveNamedItem"weapon_m3" );
                    
pOther->GiveAmmo24"buckshot"32 );
                    break;
                  case 
12 :
                    
pOther->GiveNamedItem"weapon_xm1014" );
                    
pOther->GiveAmmo24"buckshot"32 );
                    break;
                  case 
13 :
                    
pOther->GiveNamedItem"weapon_m249" );
                    
pOther->GiveAmmo60"556NatoBox"200 );
                    break;
                  default:
                    break;
                }
            }
            else
            {
                switch ( 
m_iItem )
                {
                  case 
14 :
                    if( 
pOther->AmmoInventorypOther->GetAmmoIndex"Flashbang" ) ) >= )
                        return;
                    
pOther->GiveNamedItem"weapon_flashbang" );
                    break;
                  case 
15 :
                    if( 
pOther->AmmoInventorypOther->GetAmmoIndex"HEGrenade" ) ) >= )
                        return;
                    
pOther->GiveNamedItem"weapon_hegrenade" );
                    break;
                  case 
16 :
                    if( 
m_iKevlar == )
                        return;
                    
pOther->GiveNamedItem"item_kevlar" );
                    break;
                  case 
17 :
                    if( 
m_iKevlar == )
                        return;
                    
pOther->GiveNamedItem"item_assaultsuit" );
                    break;
                  case 
18 :
                    if( 
pOther->AmmoInventorypOther->GetAmmoIndex"SmokeGrenade" ) ) >= )
                        return;
                    
pOther->GiveNamedItem"weapon_smokegrenade" );
                    break;
                  default:
                    break;
                }
                
                
m_iCount--;
            }
        }
        
        if( !
m_iCount )
        {
             
pev->effects |= EF_NODRAW;
        }
    }


PHP Code:

if( !m_iCount )
{
             
pev->effects |= EF_NODRAW;


The snippet shows that when the item count is 0 the armoury is set to invisible.


All times are GMT -4. The time now is 21:52.

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