Absurd Minds
http://forums.absurdminds.net/

How do you get players guns.
http://forums.absurdminds.net/viewtopic.php?f=58&t=67
Page 1 of 1

Author:  SavSin [ 04 Apr 2010 01:35 ]
Post subject:  How do you get players guns.

Question...

How do you store a players guns in an array at any given time

g_pWep[id][pwep][gun][ammo]
g_pWep[id][swep][gun][ammo]

Something like that would be nice.

Author:  Amaroq [ 04 Apr 2010 11:24 ]
Post subject:  Re: How do you get players guns.

So you can give the weapons back after they drop the flag?

Author:  SavSin [ 06 Apr 2010 02:33 ]
Post subject:  Re: How do you get players guns.

Yeah Other wise they just run around with the knife out lol

Author:  SavSin [ 01 Feb 2013 14:43 ]
Post subject:  Re: How do you get players guns.

I can finally answer my own question lol ill post a snippet when I get home from work

Author:  SavSin [ 03 Feb 2013 05:57 ]
Post subject:  Re: How do you get players guns.

So this is for sourcemod as i dont really do much with amxx anymore..
Code:
/*Weapon Variables*/
new Handle:g_WeaponArray[2] = INVALID_HANDLE;

//When a player leaves clear the saved weapons.
public OnClientDisconnect(iClient)
{
	ClearClientWeapons(iClient);
}

//Ovb strips the weapons... for bones or a mod where you want the knife out use it like this. StripUserWeapons(iClient, true); Otherwise use false
stock StripUserWeapons(iClient, bool:bResetKnife)
{
	if(IsClientInGame(iClient) && IsPlayerAlive(iClient))
	{
		new iPrimaryWeapon = GetPlayerWeaponSlot(iClient, 0);
		new iSecondaryWeapon = GetPlayerWeaponSlot(iClient, 1);
		
		if(iPrimaryWeapon != -1)
			RemovePlayerItem(iClient, iPrimaryWeapon);
			
		if(iSecondaryWeapon != -1)
			RemovePlayerItem(iClient, iSecondaryWeapon);
		
		if(bResetKnife)		
		{
			new iKnifeSlot = GetPlayerWeaponSlot(iClient, 2);
			
			if(iKnifeSlot != -1)
				RemovePlayerItem(iClient, iKnifeSlot);
				
			GivePlayerItem(iClient, "weapon_knife");
		}
	}
}

//Call this to save a players current primary and secondary
stock SaveClientWeapons(const iClient)
{
	new weapon;
	decl String:weaponclassname[MAX_WEAPON_STRING];
	new j = 0;
	for (new i = 0, offset = Client_GetWeaponsOffset(iClient); i < MAX_WEAPONS; i++, offset += 4)
	{
		weapon = GetEntDataEnt2(iClient, offset);
		if (!Weapon_IsValid(weapon))
		{
			break;
		}
		GetEdictClassname(weapon, weaponclassname, MAX_WEAPON_STRING);
		if ((!StrEqual(weaponclassname, "weapon_knife")) && (!StrEqual(weaponclassname, "weapon_c4")))
		{
			strcopy(ClientWeapons[iClient][j], MAX_WEAPON_STRING, weaponclassname);
			j++;
			if (j == MAX_CLIENT_WEAPONS)
			{
				return;
			}
		}
	}
	GetEntPropVector(iClient, Prop_Data, "m_vecOrigin", g_flOrigin[iClient]);
	ClientWeapons[iClient][j][0] = '\0';
}

//Call this to give the weapons back to the player
stock RestoreClientWeapons(const iClient)
{
	StripUserWeapons(iClient, false);
	
	for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
	{
		if (ClientWeapons[iClient][i][0] == '\0')
		{
			return;
		}
		Client_GiveWeapon(iClient, ClientWeapons[iClient][i], false);
	}
}

//Clears the variable
stock ClearClientWeapons(const iClient)
{
	for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
	{
		ClientWeapons[iClient][i][0] = '\0';
	}
}

//Reads the variable up top and creates the weapons on the ground where the player died. Physics work most of the time.
stock CreateDroppedWeapons(const iClient)
{
	decl iEnt;
	for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
	{
		if((iEnt = CreateEntityByName(ClientWeapons[iClient][i])) != -1)
		{
			DispatchSpawn(iEnt);
			CS_SetDroppedWeaponAmmo(iEnt, GetMaxWeaponAmmo(ClientWeapons[iClient][i]));
			TeleportEntity(iEnt, g_flOrigin[iClient], NULL_VECTOR, NULL_VECTOR);
		}
	}
	ClearClientWeapons(iClient);
}

Page 1 of 1 All times are UTC-04:00
Powered by phpBB® Forum Software © phpBB Limited
https://www.phpbb.com/