Raised This Month: $51 Target: $400
 12% 

efficient remove of weaponbox (SOLVED)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-18-2011 , 09:06   efficient remove of weaponbox (SOLVED)
Reply With Quote #1

I've searched about this and I got the 43 offset, but when I tested it, it always prints 0... and I also tried cs_get_weapon_id(), it also returns 0.

Basically I'm trying to detect weapon_* entities for weaponbox entities and remove them (because I just found out they're not removed when weapon is dropped X_X) so instead of searching through all entities or parsing model, it'll be more efficient to have the CSW_* id and use the already defined weapon_* array...

So is there a CSW_* id offset for weaponbox class, which is it ?
__________________

Last edited by Hunter-Digital; 04-18-2011 at 13:37. Reason: changed title
Hunter-Digital is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-18-2011 , 10:42   Re: getting a weaponbox's CSW_* id
Reply With Quote #2

If the purpose is to remove the weaponbox entity, just let think the entity when it touches on the ground and weaponbox + weapon_* will be removed.
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-18-2011 , 11:59   Re: getting a weaponbox's CSW_* id
Reply With Quote #3

Slots offsets are 34-39 (linux +4)

Basically, 1 weaponbox could contain few weapons in each slots (same slots weapon linked with m_pNext weapon pdata), and that in all slots. In "reality" a weaponbox contain only 1 weapon).

See this plugin for more details : http://forums.alliedmods.net/showthread.php?p=761924


See also HLSDK :
Code:
//=========================================================
// CWeaponBox - Touch: try to add my contents to the toucher
// if the toucher is a player.
//=========================================================
void CWeaponBox::Touch( CBaseEntity *pOther )
{
	if ( !(pev->flags & FL_ONGROUND ) )
	{
		return;
	}

	if ( !pOther->IsPlayer() )
	{
		// only players may touch a weaponbox.
		return;
	}

	if ( !pOther->IsAlive() )
	{
		// no dead guys.
		return;
	}

	CBasePlayer *pPlayer = (CBasePlayer *)pOther;
	int i;

// dole out ammo
	for ( i = 0 ; i < MAX_AMMO_SLOTS ; i++ )
	{
		if ( !FStringNull( m_rgiszAmmo[ i ] ) )
		{
			// there's some ammo of this type. 
			pPlayer->GiveAmmo( m_rgAmmo[ i ], (char *)STRING( m_rgiszAmmo[ i ] ), MaxAmmoCarry( m_rgiszAmmo[ i ] ) );

			//ALERT ( at_console, "Gave %d rounds of %s\n", m_rgAmmo[i], STRING(m_rgiszAmmo[i]) );

			// now empty the ammo from the weaponbox since we just gave it to the player
			m_rgiszAmmo[ i ] = iStringNull;
			m_rgAmmo[ i ] = 0;
		}
	}

// go through my weapons and try to give the usable ones to the player. 
// it's important the the player be given ammo first, so the weapons code doesn't refuse 
// to deploy a better weapon that the player may pick up because he has no ammo for it.
	for ( i = 0 ; i < MAX_ITEM_TYPES ; i++ )
	{
		if ( m_rgpPlayerItems[ i ] )
		{
			CBasePlayerItem *pItem;

			// have at least one weapon in this slot
			while ( m_rgpPlayerItems[ i ] )
			{
				//ALERT ( at_console, "trying to give %s\n", STRING( m_rgpPlayerItems[ i ]->pev->classname ) );

				pItem = m_rgpPlayerItems[ i ];
				m_rgpPlayerItems[ i ] = m_rgpPlayerItems[ i ]->m_pNext;// unlink this weapon from the box

				if ( pPlayer->AddPlayerItem( pItem ) )
				{
					pItem->AttachToPlayer( pPlayer );
				}
			}
		}
	}

	EMIT_SOUND( pOther->edict(), CHAN_ITEM, "items/gunpickup2.wav", 1, ATTN_NORM );
	SetTouch(NULL);
	UTIL_Remove(this);
}

//=========================================================
// CWeaponBox - PackWeapon: Add this weapon to the box
//=========================================================
BOOL CWeaponBox::PackWeapon( CBasePlayerItem *pWeapon )
{
	// is one of these weapons already packed in this box?
	if ( HasWeapon( pWeapon ) )
	{
		return FALSE;// box can only hold one of each weapon type
	}

	if ( pWeapon->m_pPlayer )
	{
		if ( !pWeapon->m_pPlayer->RemovePlayerItem( pWeapon ) )
		{
			// failed to unhook the weapon from the player!
			return FALSE;
		}
	}

	int iWeaponSlot = pWeapon->iItemSlot();
	
	if ( m_rgpPlayerItems[ iWeaponSlot ] )
	{
		// there's already one weapon in this slot, so link this into the slot's column
		pWeapon->m_pNext = m_rgpPlayerItems[ iWeaponSlot ];	
		m_rgpPlayerItems[ iWeaponSlot ] = pWeapon;
	}
	else
	{
		// first weapon we have for this slot
		m_rgpPlayerItems[ iWeaponSlot ] = pWeapon;
		pWeapon->m_pNext = NULL;	
	}

	pWeapon->pev->spawnflags |= SF_NORESPAWN;// never respawn
	pWeapon->pev->movetype = MOVETYPE_NONE;
	pWeapon->pev->solid = SOLID_NOT;
	pWeapon->pev->effects = EF_NODRAW;
	pWeapon->pev->modelindex = 0;
	pWeapon->pev->model = iStringNull;
	pWeapon->pev->owner = edict();
	pWeapon->SetThink( NULL );// crowbar may be trying to swing again, etc.
	pWeapon->SetTouch( NULL );
	pWeapon->m_pPlayer = NULL;

	//ALERT ( at_console, "packed %s\n", STRING(pWeapon->pev->classname) );

	return TRUE;
}

//=========================================================
// CWeaponBox - PackAmmo
//=========================================================
BOOL CWeaponBox::PackAmmo( int iszName, int iCount )
{
	int iMaxCarry;

	if ( FStringNull( iszName ) )
	{
		// error here
		ALERT ( at_console, "NULL String in PackAmmo!\n" );
		return FALSE;
	}
	
	iMaxCarry = MaxAmmoCarry( iszName );

	if ( iMaxCarry != -1 && iCount > 0 )
	{
		//ALERT ( at_console, "Packed %d rounds of %s\n", iCount, STRING(iszName) );
		GiveAmmo( iCount, (char *)STRING( iszName ), iMaxCarry );
		return TRUE;
	}

	return FALSE;
}
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-18-2011 , 13:30   Re: getting a weaponbox's CSW_* id
Reply With Quote #4

Quote:
Originally Posted by Arkshine View Post
If the purpose is to remove the weaponbox entity, just let think the entity when it touches on the ground and weaponbox + weapon_* will be removed.
Well, while searching, someone said that call_think() doesn't remove the weapon_* but from what I just tested, it does remove the weaponbox and the weapon_*, it also doesn't matter if it touches the ground, because the weapon floats upwards while it's removed xD

Btw, I checked for weapon_* entities using a task, because it's logic that it will detect the entities in the same function call.

So this is a verry efficient method... unless it fails =)

EDIT: I also printed entitiy count, it drops by 2 every time :}
__________________

Last edited by Hunter-Digital; 04-18-2011 at 13:36.
Hunter-Digital is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-18-2011 , 14:11   Re: efficient remove of weaponbox (SOLVED)
Reply With Quote #5

If you want to remove them faster you can hook Ham_Touch, "weaponbox".
Spawn is too early but Touch is ok.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-18-2011 , 14:33   Re: efficient remove of weaponbox (SOLVED)
Reply With Quote #6

What I've said...
__________________
Arkshine is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-18-2011 , 16:46   Re: efficient remove of weaponbox (SOLVED)
Reply With Quote #7

Not really, you said when it touches the ground, when you hook weaponbox Touch, it is triggered right after spawn because it touches player who is dropping the weapon, maybe when it is on player death the first Touch is ground touch though.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 04-18-2011 , 17:01   Re: efficient remove of weaponbox (SOLVED)
Reply With Quote #8

Well, I'm removing the weaponbox from the ground after it's stayed there for a cvar controlled number of seconds, then it floats into the air and vanishes :} so no, no touch hook for me.
__________________
Hunter-Digital is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-18-2011 , 17:07   Re: efficient remove of weaponbox (SOLVED)
Reply With Quote #9

Quote:
then it floats into the air and vanishes :}
I sense some proudness here. :p
I was talking about touch because previous help was always in this situation, but it's fine as long as entity is fully spawned and think initialized.
__________________

Last edited by Arkshine; 04-18-2011 at 18:16.
Arkshine is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:37.


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