Changing weapon preferences
Like the above poster, these functions will allow people to switch weapons but is not limited to the vehicle (in case you don't want certain weapons to be allowed to shoot from drive-by). Also, this gives a more simple, and clean approach. There are three functions included, even though one of them is used internally (I'm sure you could find better uses for it as well). Please note, this will take 0.3c RC4 or later to work correctly.
All descriptions about the functions can be found inside of the comments. If you have questions regarding them, ask.
pawn Код:
// You will need to change the IDs in the array to match with the weapons
// you do not want used inside of the script
/*
Function:
AdjustWeapons
Params:
playerid - The ID of the player
Usage:
Checks for certain weapons, if that weapon is armed
then it will replace it with a sub-machine gun if
the player has one. If not, it will set to fist.
Returns:
N/A
*/
stock AdjustWeapons( playerid )
{
new
ForbiddenWeapons[ ] = { 24, 27 }
;
for( new i = 0; i < sizeof( ForbiddenWeapons ); i ++ )
{
if( GetPlayerWeapon( playerid ) == ForbiddenWeapons[ i ] )
{
new
weapon,
ammo
;
GetPlayerWeaponData( playerid, 4, weapon, ammo );
if( ammo > 0 )
SetPlayerArmedWeapon( playerid, weapon );
else
SetPlayerArmedWeapon( playerid, 0 );
}
}
}
/*
Function:
AdjustWeaponsEx
Params:
playerid - The ID of the player
slot - The ID of the slot to replace the forbidden weapon with
weapon = 0 - The ID of the weapon to replace with (if the slot specified is unoccupied)
Usage:
Checks for certain weapons, if that weapon is armed
it will replace it with a weapon in the specified
slot. If there are no weapons in that slot, it will
replace it with the specified weapon ID (default = 0)
If that weapon is not found either, it will default
back to fist.
Returns:
N/A
*/
stock AdjustWeaponsEx( playerid, slot, weapon = 0 )
{
new
ForbiddenWeapons[ ] = { 24, 27 }
;
for( new i = 0; i < sizeof( ForbiddenWeapons ); i ++ )
{
if( GetPlayerWeapon( playerid ) == ForbiddenWeapons[ i ] )
{
new
weapon_s,
ammo
;
GetPlayerWeaponData( playerid, slot, weapon_s, ammo );
if( ammo <= 0 )
{
GetPlayerWeaponData( playerid, GetWeaponSlot( weapon ), weapon_s, ammo );
if( ammo <= 0 )
SetPlayerArmedWeapon( playerid, 0 );
else
SetPlayerArmedWeapon( playerid, weapon );
}
else
SetPlayerArmedWeapon( playerid, weapon_s );
}
}
}
/*
Function:
GetWeaponSlot
Params:
weaponid - The ID of the weapon
Usage:
Gets the slot ID for the specified weapon
Returns:
The returned slot ID. (Default = -1)
*/
stock GetWeaponSlot( weaponid )
{
switch( weaponid )
{
case 0, 1: return 0;
case 2..9: return 1;
case 10..15: return 10;
case 16..18, 39: return 8;
case 22..24: return 2;
case 25..27: return 3;
case 28, 29, 32: return 4;
case 30, 31: return 5;
case 33, 34: return 6;
case 35..38: return 7;
case 40: return 12;
case 41..43: return 9;
case 44..46: return 11;
default: return -1;
}
return -1;
}
As mentioned above, these functions are not limited to vehicles, so you can use them for other things as you please. A few examples are below:
pawn Код:
// Will check if the player has a weapon in slot 5 and put that weapon
// If not, it will switch the player to weapon ID 16
// If none of the above are possible (meaning the player has no weapons in slot 5 and no weapon ID 16), it will default to fist
// That is all considering the player entered the vehicle with a weapon that corresponds to the IDs in the array
public OnPlayerStateChange( playerid, newstate, oldstate )
{
if( newstate == PLAYER_STATE_PASSENGER )
AdjustWeaponsEx( playerid, 5, 16 );
return 1;
}
I'm looking forward to releasing more things on the forums again. If you have any suggestions for anything, send me a PM.