Absurd Minds

More than 100 years without a motto.
It is currently 25 Nov 2024 04:10

All times are UTC-04:00




Post new topic  Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 04 Apr 2010 01:35 
Offline

Joined: 26 Mar 2010 00:47
Posts: 41
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.


Top
   
PostPosted: 04 Apr 2010 11:24 
Offline
User avatar

Joined: 25 Mar 2010 19:07
Posts: 8392
So you can give the weapons back after they drop the flag?


Top
   
PostPosted: 06 Apr 2010 02:33 
Offline

Joined: 26 Mar 2010 00:47
Posts: 41
Yeah Other wise they just run around with the knife out lol


Top
   
PostPosted: 01 Feb 2013 14:43 
Offline

Joined: 26 Mar 2010 00:47
Posts: 41
I can finally answer my own question lol ill post a snippet when I get home from work


Top
   
PostPosted: 03 Feb 2013 05:57 
Offline

Joined: 26 Mar 2010 00:47
Posts: 41
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);
}


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 5 posts ] 

All times are UTC-04:00


Who is online

Users browsing this forum: Bing [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Limited