ResetPlayerWeaponsEx

From SA-MP Wiki

Jump to: navigation, search



Image:32px-Ambox_warning_orange.png

Notes

  • This is not a native function. It was created by Kyoshiro and is for anyone who wants to use it.
  • This will not remove melee weapons! As it stands now there is no fix :(


Description:

Removes all weapons from a player except those specified.


Parameters:
(playerid, ...)
playeridThe ID of the player to give the weapon to
weaponidThe list of weapons to exclude


Return Values:

This function returns no specific value.


ResetPlayerWeaponsEx(playerid, 30,31); //Resets all of the players weapons except AK-47 (30) and the M4 (31).


code

stock ResetPlayerWeaponsEx(playerid,...)
{
	new W[] =
	{
		0,0,1,1,1,1,1,1,1,1,10,10,10,10,10,10,8,8,
		8,0,0,0,2,2,2,3,3,3,4,4,5,5,4,6,6,7,7,7,7,
		8,12,9,9,9,11,11,11,11
	};
 
	new
		idx = 0,
		tmp = 0,
		weapons,
 	 	args = numargs() - 1,
		bool:Reset[13] = {true,...};
 
 
	if(IsPlayerConnected(playerid))
	{
		if(args > 0)
		{
		    if(args <= 46)
		    {
				while(args > idx++)
				{
				    new wep = getarg(idx);
 
					if(0 <= wep <= 46)
					{
					    GetPlayerWeaponData(playerid,W[wep],weapons,tmp);
 
						if(weapons == wep)
						{
							Reset[W[wep]] = false;
						}
					}
					else
					{
		   				printf("ResetPlayerWeaponEx warning: invalid argument (argument: #%d)! \"%d\" is not a valid weapon!", idx+1,wep);
					}
				}
 
				for(new a = 0; a < 13; a ++)
				{
				    if(Reset[a])
				    {
				        GetPlayerWeaponData(playerid,a,weapons,tmp);
 
				        if(weapons)
				        {
	       					SetPlayerAmmo(playerid,weapons,0);
 
							weapons = -1;
						}
					}
				    else
				    {
						Reset[a] = true;
				    }
				}
				return 1;
			}
		    print("ResetPlayerWeaponsEx Error: You have specified over 46 weapons! Check for duplicate weapons");
		    return 1;
		}
		ResetPlayerWeapons(playerid);
		return 1;
	}
	return 1;
}

Related Functions

The following functions may be useful, as they are related to this function in one way or another.