Raised This Month: $ Target: $400
 0% 

Give Weapon Ammo Issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 12-09-2007 , 02:45   Give Weapon Ammo Issue
Reply With Quote #1

Hello gents. I'm trying to give a player a weapon when he walks over it; normally he'd be able to pick it up like normal, but he already has a primary weapon so I'm going around it with hamsandwich.

The giving part works fine, but the ammo doesn't go with it. The clip ammo does, but not the backpack ammo. So if I drop an SMG for example, with 23 rounds in the clip and 4 extra magazines, I go to pick it back up and only get those 23 rounds total - no extra magazines.

Code:
// Adapted from XxAvalanchexX's stock stock ham_give_weapon_entity( id, wpnent ) {     if( !pev_valid(wpnent) ) return 0;             if(!ExecuteHamB(Ham_AddPlayerItem,id,any:wpnent) || !ExecuteHamB(Ham_Item_AttachToPlayer,wpnent,any:id))     {         if(pev_valid(wpnent)) set_pev(wpnent,pev_flags,pev(wpnent,pev_flags) & FL_KILLME);         return 0;     }           return 1; }

So my question is, first of all, if anyone knows a better way around this.

But assuming no one does, does anyone know where backpack ammo is stored? Is it on the person, or in the gun (which would be logical). If it's in the gun, where? Pdata (I've looked through some offsets to no avail)?

Thanks in advance
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-09-2007 , 03:33   Re: Give Weapon Ammo Issue
Reply With Quote #2

How is it for counter-strike :

Bpammo are player offsets.
When you drop a weapon, you keep the bpammo, that bpammo is shared for other weapons you could have.
For example you use the same bpammo for glock18, mp5navy, tmp and elites.
You only drop this bpammo when you die.

Hope it's the same for dod ;)
Good research

Code:
	#define OFFSET_AWM_AMMO				426 + EXTRAOFFSET // +44
	#define OFFSET_SCOUT_AMMO			427 + EXTRAOFFSET // +44
	#define OFFSET_PARA_AMMO			428 + EXTRAOFFSET // +44
	#define OFFSET_FAMAS_AMMO			429 + EXTRAOFFSET // +44
	#define OFFSET_M3_AMMO				430 + EXTRAOFFSET // +44
	#define OFFSET_USP_AMMO				431 + EXTRAOFFSET // +44
	#define OFFSET_FIVESEVEN_AMMO		432 + EXTRAOFFSET // +44
	#define OFFSET_DEAGLE_AMMO			433 + EXTRAOFFSET // +44
	#define OFFSET_P228_AMMO			434 + EXTRAOFFSET // +44
	#define OFFSET_GLOCK_AMMO			435 + EXTRAOFFSET // +44
	#define OFFSET_FLASH_AMMO			436 + EXTRAOFFSET // +44
	#define OFFSET_HE_AMMO				437 + EXTRAOFFSET // +44
	#define OFFSET_SMOKE_AMMO			438 + EXTRAOFFSET // +44
	#define OFFSET_C4_AMMO				439	+ EXTRAOFFSET // +44

static cell AMX_NATIVE_CALL cs_get_user_backpackammo(AMX *amx, cell *params) // cs_get_user_backpackammo(index, weapon); = 2 params
{
	// Get amount of ammo in a user's backpack for a specific weapon type.
	// params[1] = user index
	// params[2] = weapon, as in CSW_*

	// Valid entity should be within range
	CHECK_PLAYER(params[1]);

	// Make into edict pointer
	edict_t *pPlayer = MF_GetPlayerEdict(params[1]);

	int offset;

	switch (params[2]) {
		case CSW_AWP:
			offset = OFFSET_AWM_AMMO;
			break;
		case CSW_SCOUT:
		case CSW_AK47:
		case CSW_G3SG1:
			offset = OFFSET_SCOUT_AMMO;
			break;
		case CSW_M249:
			offset = OFFSET_PARA_AMMO;
			break;
		case CSW_FAMAS:
		case CSW_M4A1:
		case CSW_AUG:
		case CSW_SG550:
		case CSW_GALI:
		case CSW_SG552:
			offset = OFFSET_FAMAS_AMMO;
			break;
		case CSW_M3:
		case CSW_XM1014:
			offset = OFFSET_M3_AMMO;
			break;
		case CSW_USP:
		case CSW_UMP45:
		case CSW_MAC10:
			offset = OFFSET_USP_AMMO;
			break;
		case CSW_FIVESEVEN:
		case CSW_P90:
			offset = OFFSET_FIVESEVEN_AMMO;
			break;
		case CSW_DEAGLE:
			offset = OFFSET_DEAGLE_AMMO;
			break;
		case CSW_P228:
			offset = OFFSET_P228_AMMO;
			break;
		case CSW_GLOCK18:
		case CSW_MP5NAVY:
		case CSW_TMP:
		case CSW_ELITE:
			offset = OFFSET_GLOCK_AMMO;
			break;
		case CSW_FLASHBANG:
			offset = OFFSET_FLASH_AMMO;
			break;
		case CSW_HEGRENADE:
			offset = OFFSET_HE_AMMO;
			break;
		case CSW_SMOKEGRENADE:
			offset = OFFSET_SMOKE_AMMO;
			break;
		case CSW_C4:
			offset = OFFSET_C4_AMMO;
			break;
		default:
			MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", params[2]);
			return 0;
	}

	return (int)*((int *)pPlayer->pvPrivateData + offset);
	
	return 0;
}

static cell AMX_NATIVE_CALL cs_set_user_backpackammo(AMX *amx, cell *params) // cs_set_user_backpackammo(index, weapon, amount); = 3 params
{
	// Set amount of ammo in a user's backpack for a specific weapon type.
	// params[1] = user index
	// params[2] = weapon, as in CSW_*
	// params[3] = new amount

	// Valid entity should be within range
	CHECK_PLAYER(params[1]);

	// Make into edict pointer
	edict_t *pPlayer = MF_GetPlayerEdict(params[1]);

	int offset;

	switch (params[2]) {
		case CSW_AWP:
			offset = OFFSET_AWM_AMMO;
			break;
		case CSW_SCOUT:
		case CSW_AK47:
		case CSW_G3SG1:
			offset = OFFSET_SCOUT_AMMO;
			break;
		case CSW_M249:
			offset = OFFSET_PARA_AMMO;
			break;
		case CSW_FAMAS:
		case CSW_M4A1:
		case CSW_AUG:
		case CSW_SG550:
		case CSW_GALI:
		case CSW_SG552:
			offset = OFFSET_FAMAS_AMMO;
			break;
		case CSW_M3:
		case CSW_XM1014:
			offset = OFFSET_M3_AMMO;
			break;
		case CSW_USP:
		case CSW_UMP45:
		case CSW_MAC10:
			offset = OFFSET_USP_AMMO;
			break;
		case CSW_FIVESEVEN:
		case CSW_P90:
			offset = OFFSET_FIVESEVEN_AMMO;
			break;
		case CSW_DEAGLE:
			offset = OFFSET_DEAGLE_AMMO;
			break;
		case CSW_P228:
			offset = OFFSET_P228_AMMO;
			break;
		case CSW_GLOCK18:
		case CSW_MP5NAVY:
		case CSW_TMP:
		case CSW_ELITE:
			offset = OFFSET_GLOCK_AMMO;
			break;
		case CSW_FLASHBANG:
			offset = OFFSET_FLASH_AMMO;
			break;
		case CSW_HEGRENADE:
			offset = OFFSET_HE_AMMO;
			break;
		case CSW_SMOKEGRENADE:
			offset = OFFSET_SMOKE_AMMO;
			break;
		case CSW_C4:
			offset = OFFSET_C4_AMMO;
			break;
		default:
			MF_LogError(amx, AMX_ERR_NATIVE, "Invalid weapon id %d", params[2]);
			return 0;
	}

	*((int *)pPlayer->pvPrivateData + offset) = params[3];
	
	return 1;
}
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 12-09-2007 at 03:41.
ConnorMcLeod is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 12-09-2007 , 08:55   Re: Give Weapon Ammo Issue
Reply With Quote #3

But conorr, correct me if I'm wrong here..but..

In CS, if you buy an AK47 and comma comma comma that sucker, so you've got 30x90, then bam some CT honkey kills you before you even fire a shot, comes up and steals your beautiful new Kalashnikov....he's gonna have 30x90 in there, is he not? Regardless of how much ammo he purchased prior?
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 12-09-2007 , 09:27   Re: Give Weapon Ammo Issue
Reply With Quote #4

You're right, but i told you before.
Quote:
Originally Posted by connorr View Post
You only drop this bpammo when you die.
If you drop this weapon just before you die, your killer will pickup the ak47 with 30 ammo but not the other 90 ;)

Also bpammo is shared for multiple weapons, for exemple usp, ump45 and mac10.
usp is a gun, ump45 and mac10 are smgs.

Suppose you have those weapons :
usp 12/100
mac10 30/100

You shoot 5 bullets with the usp -> 7/100
You reload it --> 12/95
Switch to mac10 --> 30/95


Hope it helps you
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 12-10-2007 , 04:43   Re: Give Weapon Ammo Issue
Reply With Quote #5

Quote:
Originally Posted by Wilson [29th ID] View Post
But conorr, correct me if I'm wrong here..but..

In CS, if you buy an AK47 and comma comma comma that sucker, so you've got 30x90, then bam some CT honkey kills you before you even fire a shot, comes up and steals your beautiful new Kalashnikov....he's gonna have 30x90 in there, is he not? Regardless of how much ammo he purchased prior?
Yes. But of course, only if said honkey does indeed cap you.
Should he arrive spawn-wards and kindly request you chuck your hands in the air and your AK on the floor, then assuming you acquiesce, he would walk off but one AK and 30 rounds richer.

I assume that when you did your data dump of the item it was a gun that was dropped from killing, and not "drop", right?
purple_pixie is offline
Wilson [29th ID]
Veteran Member
Join Date: Nov 2005
Location: London
Old 12-10-2007 , 07:18   Re: Give Weapon Ammo Issue
Reply With Quote #6

Actually, I'm dropping it. And then picking it back up myself. So it seems when I drop it, either my bpammo gets lost or it doesn't get applied once I pick it back up. Because once I pick it back up I only have what was in the clip on dropping it.
__________________

Day of Defeat AMXX Community

FakeMeta Research . Voice Proximity . Advanced Deploy . Technician
Wilson [29th ID] is offline
Send a message via ICQ to Wilson [29th ID] Send a message via AIM to Wilson [29th ID] Send a message via MSN to Wilson [29th ID] Send a message via Yahoo to Wilson [29th ID]
purple_pixie
Veteran Member
Join Date: Jun 2007
Location: Winchester, England
Old 12-10-2007 , 07:34   Re: Give Weapon Ammo Issue
Reply With Quote #7

That's just weird.

Last time I checked, you just keep the ammo when you drop it.
Unless that's your existing code screwing you over for 3 clips.

If you have an AK with 3 spare clips, and swap your AK with someone who only had 1 spare clip (both drop + pick up each others) you would both have the same BPammo as you started with, but whatever gun-ammo was in the other guy's rifle.

Try scanning offsets and that after slaying yourself instead.
purple_pixie 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 11:04.


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