Raised This Month: $7 Target: $400
 1% 

engine weapon drop (CS/CZERO)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 04-08-2012 , 03:42   engine weapon drop (CS/CZERO)
Reply With Quote #1

What is the best method to hook what is the weapon dropped by the user, when he is buying another weapon the same type? I mean - i.e. - if I had an awp, I've bought another primary weapon, so the game engine forces me to drop my awp. It is not just client "drop", but it is something else. What is exactly the message type sent to force me to drop my awp, when I'm buying another primary weapon?
I need to this for sniperlimit plugin to catch when the player had an awp, but he bought another primary weapon, so the game engine forces him to drop that awp (so I can count how many players really have awps in a team - for that team awps quantity can be subtracted).
After testing it seems that this method:
register_clcmd("drop","handle_drop_weapon")
is not working on that kind of weapon drop (because it is not really the user calling "drop" command).
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.
KWo is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 04-08-2012 , 03:53   Re: engine weapon drop (CS/CZERO)
Reply With Quote #2

Hook SetModel_Post forward.

Last edited by claudiuhks; 04-08-2012 at 05:43.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-08-2012 , 04:05   Re: engine weapon drop (CS/CZERO)
Reply With Quote #3

I think it is void CBasePlayer:: DropPlayerItem ( char *pszItemName )
Also, it may exists a specific function for shield, i don't remember.

Code:
void CBasePlayer::DropPlayerItem ( char *pszItemName )
{
	if ( !g_pGameRules->IsMultiplayer() || (weaponstay.value > 0) )
	{
		// no dropping in single player.
		return;
	}

	if ( !strlen( pszItemName ) )
	{
		// if this string has no length, the client didn't type a name!
		// assume player wants to drop the active item.
		// make the string null to make future operations in this function easier
		pszItemName = NULL;
	} 

	CBasePlayerItem *pWeapon;
	int i;

	for ( i = 0 ; i < MAX_ITEM_TYPES ; i++ )
	{
		pWeapon = m_rgpPlayerItems[ i ];

		while ( pWeapon )
		{
			if ( pszItemName )
			{
				// try to match by name. 
				if ( !strcmp( pszItemName, STRING( pWeapon->pev->classname ) ) )
				{
					// match! 
					break;
				}
			}
			else
			{
				// trying to drop active item
				if ( pWeapon == m_pActiveItem )
				{
					// active item!
					break;
				}
			}

			pWeapon = pWeapon->m_pNext; 
		}

		
		// if we land here with a valid pWeapon pointer, that's because we found the 
		// item we want to drop and hit a BREAK;  pWeapon is the item.
		if ( pWeapon )
		{
			g_pGameRules->GetNextBestWeapon( this, pWeapon );

			UTIL_MakeVectors ( pev->angles ); 

			pev->weapons &= ~(1<<pWeapon->m_iId);// take item off hud

			CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create( "weaponbox", pev->origin + gpGlobals->v_forward * 10, pev->angles, edict() );
			pWeaponBox->pev->angles.x = 0;
			pWeaponBox->pev->angles.z = 0;
			pWeaponBox->PackWeapon( pWeapon );
			pWeaponBox->pev->velocity = gpGlobals->v_forward * 300 + gpGlobals->v_forward * 100;
			
			// drop half of the ammo for this weapon.
			int	iAmmoIndex;

			iAmmoIndex = GetAmmoIndex ( pWeapon->pszAmmo1() ); // ???
			
			if ( iAmmoIndex != -1 )
			{
				// this weapon weapon uses ammo, so pack an appropriate amount.
				if ( pWeapon->iFlags() & ITEM_FLAG_EXHAUSTIBLE )
				{
					// pack up all the ammo, this weapon is its own ammo type
					pWeaponBox->PackAmmo( MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[ iAmmoIndex ] );
					m_rgAmmo[ iAmmoIndex ] = 0; 

				}
				else
				{
					// pack half of the ammo
					pWeaponBox->PackAmmo( MAKE_STRING(pWeapon->pszAmmo1()), m_rgAmmo[ iAmmoIndex ] / 2 );
					m_rgAmmo[ iAmmoIndex ] /= 2; 
				}

			}

			return;// we're done, so stop searching with the FOR loop.
		}
	}
}
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-08-2012 at 04:05.
ConnorMcLeod is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 04-08-2012 , 04:16   Re: engine weapon drop (CS/CZERO)
Reply With Quote #4

Connor - my friend, I didn't ask to narrow the code in C++ in HLSDK of CS making by engine weapon drop, but I was asking how to hook this.
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.
KWo is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2012 , 05:01   Re: engine weapon drop (CS/CZERO)
Reply With Quote #5

"drop" command calls DropPlayerItem. But yes, DropPlayerItem is called in others functions directly.
Here a full list :

BuyPistol(CBasePlayer *,int)
BuyShotgun(CBasePlayer *,int)
BuySubMachineGun(CBasePlayer *,int)
BuyWeaponByWeaponID(CBasePlayer *,WeaponIdType)
BuyRifle(CBasePlayer *,int)
BuyMachineGun(CBasePlayer *,int)
BuyItem(CBasePlayer *,int)
ClientCommand(edict_s *)
DropPrimary(CBasePlayer *)
CHalfLifeMultiplay::RestartRound(void)
CBasePlayer::Killed(entvars_s *,int)
CBasePlayer::ThrowPrimary(void)

To hook it, you would need to use Orpheu or Rage. Are you fine using such modules ? Better to ask before doing something.

But for your need, hooking SetModel may be enough.
__________________

Last edited by Arkshine; 04-08-2012 at 05:18.
Arkshine is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 04-08-2012 , 07:44   Re: engine weapon drop (CS/CZERO)
Reply With Quote #6

I don't know Orpheu nor Rage modules at all. About Set_Model - I believe You guys are talking about this VEN's function I found in his plugin weapon_drop_details:
Code:
public forward_set_model(ent, const model[]) {
	if (!pev_valid(ent) || !equali(model, g_wbox_model_prefix, sizeof g_wbox_model_prefix - 1) || equali(model, g_wbox_model))
		return FMRES_IGNORED

	new id = pev(ent, pev_owner)
	if (!(g_start_client_index <= id <= g_max_clients))
		return FMRES_IGNORED

	static class[32]
	pev(ent, pev_classname, class, sizeof class - 1)
	if (!equal(class, g_wbox_class))
		return FMRES_IGNORED

	for (new i = g_max_clients + 1; i < g_max_entities; ++i) {
		if (!pev_valid(i) || ent != pev(i, pev_owner))
			continue

		new wid = cs_get_weapon_id(i)
		new droptype:drop_type
		if (!is_user_connected(id))
			drop_type = droptype_ondisconnect
		else if (!is_user_alive(id))
			drop_type = droptype_ondeath
		else if (equal(g_command[id], g_drop))
			drop_type = droptype_manual
		else if (wid != CSW_C4)
			drop_type = droptype_onbuy
		else
			return FMRES_IGNORED

		pev(i, pev_classname, class, sizeof class - 1)

		server_print("BoxOwnerClientIndex: %2d, DropType: %-12s, Index: %2d, Name: %-16s, BoxEntityIndex: %3d, EntityIndex: %3d, BoxModel: %s", id, g_drop_type[drop_type], wid, class, ent, i, model)

		return FMRES_IGNORED
	}

	return FMRES_IGNORED
}
I really appreaciate VEN's knowledge and high skill in coding, but I don't like this method, because I would need to loop through all entities to find which one belongs to weapon_box (or vice versa) to narrow down the dropped weapon I'm looking for. If that would be used for some huge maps with many entities (or with CSDM item mode), that must really take the CPU power of the server (which I don't want). This is the same method I'm using in "my" version of CSDM to hook all weapon drop (including bots). But at least that one is done in C++ in csdm module, so I believe it works faster. BAILOPAN didn't like that method neither, so this fix to hook all weapon drop (including bots) was never included in oficial CSDM module. He was suggesting me to find some help in private datas of entities (so we don't need to loop everytime through all entities of the map), but I didn't know how to use this advice.
I thought You know guys a better method to hook the event I was asking for. To my need it is probably enough to just hook primary weapon buy/pickup message to check - if the user had an awp, but he is now buying/pickuping another primary weapon, that means he doesn't have anymore his awp. The only thing I'm not sure is - how many plugins/mods is around they let users to have more than 1 primary weapon? In such case my method wouldn't work correctly, but more than likely is more efficient than that looping thing. But yes, VEN's method in such cases is more accurate.
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.

Last edited by KWo; 04-08-2012 at 07:46.
KWo is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2012 , 08:50   Re: engine weapon drop (CS/CZERO)
Reply With Quote #7

Like you said, you have to use the weaponbox offsets (private datas) instead of the loop like has done VEN.

Here a fast example which should be enough, in hoping it's correct :

Spoiler
__________________

Last edited by Arkshine; 04-08-2012 at 08:55.
Arkshine is offline
KWo
AMX Mod X Beta Tester
Join Date: Jul 2004
Location: Poland
Old 04-08-2012 , 15:01   Re: engine weapon drop (CS/CZERO)
Reply With Quote #8

Thanks for example, but what are offsets for windows? How did You get that offset value for linux?
[EDIT]
It looks like I don't have experience with hamsandvich module, too, but I was jsut reading about that linuxoffset - it is just the difference between windows and linux private data offsets. Anyway - where did You get the difference for linux value from? And what are these values m_rgpPlayerItems_wpnbx[] = { 34, 35, 36, 37, 38, 39 }? Where did You get them from?
[/EDIT]
__________________
The Fullpack of podbot mm V3B22 - 24 apr 2012!!! is available here.
The All-In-One 3.2a package - 02 jun 2013 (AMX X 1.8.2 [with ATAC 3.0.1b , CSDM2.1.3c beta, CM OE 0.6.5, podbot mm V3B22c and mm 1.20) is available here.
The newest Beta V3B23a (rel. 28 august 2018!!!) is available here.

Last edited by KWo; 04-08-2012 at 15:29.
KWo is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 04-08-2012 , 15:53   Re: engine weapon drop (CS/CZERO)
Reply With Quote #9

Ven used to find 34 and 35, we just checked that the other ones were 36 37 and 38.
Now, we would check this on IDA.

Well, no need to be experienced with hamsandwich, let's say that fakemeta was not supporting retrievieng pdata offset when it was about CBase pointers, get_pdata_cbase allows that.
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 04-08-2012 at 15:56.
ConnorMcLeod is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-08-2012 , 17:03   Re: engine weapon drop (CS/CZERO)
Reply With Quote #10

Quote:
It looks like I don't have experience with hamsandvich module, too, but I was jsut reading about that linuxoffset - it is just the difference between windows and linux private data offsets. Anyway - where did You get the difference for linux value from? And what are these values m_rgpPlayerItems_wpnbx[] = { 34, 35, 36, 37, 38, 39 }? Where did You get them from?
The difference is generally +4 for weapons and +5 for player. That's something you can check with IDA.
m_rgpPlayerItems[6] is an array. The size is 6 because CS handles 6 slots, though [0] is not used, just 1 to 5 for : primary/secondary/knife/grenade/c4. When a weapon is dropped, the weapon is saved in the corresponding slot of the weaponbox offset. Meaning, if a primary weapon dropped, you will find the value in m_rgpPlayerItems_wpnbx[1].
That's why we loop through all the slots.
__________________
Arkshine is offline
Reply


Thread Tools
Display Modes

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 01:41.


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