#define PRESSING(%0,%1) (%0 & (%1)) #define RELEASED(%0) (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
new Helmet_Attached_Object[MAX_PLAYERS] ;
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
/*
Now if the player has the helmet enabled, and is holding a sniper rifle the attachment,
will be hidden (removed) temporarily until the player releases the key.
*/
if(PRESSING(newkeys, KEY_HANDBRAKE))
{
if(Helmet_Attached_Object[playerid] == 1 && GetPlayerWeapon(playerid) == 34)
{
if(IsPlayerAttachedObjectSlotUsed(playerid, 1))
{
RemovePlayerAttachedObject(playerid, 1);
}
}
}
/*
Now when the player releases (stops pressing) the aiming key, the attachment
will be re-added to his head so it doesn't disturb him any longer!
*/
else if(RELEASED(KEY_HANDBRAKE))
{
if(Helmet_Attached_Object[playerid] == 1 && GetPlayerWeapon(playerid) == 34)
{
SetPlayerAttachedObject(playerid, 1, 19103, 2, 0.18, 0.00, 0.01, -5.30, 175.80, -158.00, 1.00, 1.00, 1.00);
}
}
return 1;
}
public OnPlayerSpawn(playerid)
{
Helmet_Attached_Object[playerid] = 1; // Setting the variable to "1" so that the player has the helmet.
SetPlayerAttachedObject(playerid, 1, 19103, 2, 0.18, 0.00, 0.01, -5.30, 175.80, -158.00, 1.00, 1.00, 1.00); // Attaching helmet on slot 1.
GivePlayerWeapon(playerid, 34, 20); // Giving the player a sniper rifle with 20 rounds of ammo to test the system.
return 1;
}
#include <a_samp>
/*
Okay, so we will be defining PRESSING and RELEASED, to check if the player is pressing
the aiming key (KEY_HANDBRAKE) so we can remove the attachment and re-add it once
the aiming key (KEY_HANDBRAKE) is released (no longer being pressed). Easy!
*/
#define PRESSING(%0,%1) (%0 & (%1))
#define RELEASED(%0) (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
/*
We will declare the variable "Helmet_Attached_Object", to store if the player
has the attachment to do the removing and re-adding process properly.
*/
new
Helmet_Attached_Object[MAX_PLAYERS]
;
public OnPlayerSpawn(playerid)
{
Helmet_Attached_Object[playerid] = 1; // Setting the variable to "1" so that the player has the helmet.
SetPlayerAttachedObject(playerid, 1, 19103, 2, 0.18, 0.00, 0.01, -5.30, 175.80, -158.00, 1.00, 1.00, 1.00); // Attaching helmet on slot 1.
GivePlayerWeapon(playerid, 34, 20); // Giving the player a sniper rifle with 20 rounds of ammo to test the system.
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
/*
Now if the player has the helmet enabled, and is holding a sniper rifle the attachment,
will be hidden (removed) temporarily until the player releases the key.
*/
if(PRESSING(newkeys, KEY_HANDBRAKE))
{
if(Helmet_Attached_Object[playerid] == 1 && GetPlayerWeapon(playerid) == 34)
{
if(IsPlayerAttachedObjectSlotUsed(playerid, 1))
{
RemovePlayerAttachedObject(playerid, 1);
}
}
}
/*
Now when the player releases (stops pressing) the aiming key, the attachment
will be re-added to his head so it doesn't disturb him any longer!
*/
else if(RELEASED(KEY_HANDBRAKE))
{
if(Helmet_Attached_Object[playerid] == 1 && GetPlayerWeapon(playerid) == 34)
{
SetPlayerAttachedObject(playerid, 1, 19103, 2, 0.18, 0.00, 0.01, -5.30, 175.80, -158.00, 1.00, 1.00, 1.00);
}
}
return 1;
}
Helmet_Attached_Object[playerid] = 0;
new Attachments[3];
|
What if the object is not a helmet?
Is the object offset accurate for every skin? |