objs 14077, revolver, revolver, 299, 0 16969, deagle, deagle, 299, 0 end
#include <a_samp>
#include <zcmd>
#define SCM SendClientMessage
CMD:deagle(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
GivePlayerWeapon(playerid, 24, 999);
SetPlayerAttachedObject(playerid, GetLowestID(playerid), 16969, RIGHT_HAND);
return SCM(playerid, -1, "You got a desert eagle with 999 ammo !");
}
GetLowestID(playerid)
{
for(new i = 0; i < 10; i++)
{
if(!IsPlayerAttachedObjectSlotUsed(playerid, i)) return i;
}
return -1;
}
#include <a_samp>
#include <zcmd>
#define SCM SendClientMessage
#define GivePlayerWeapon S_GivePlayerWeapon
CMD:deagle(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
GivePlayerWeapon(playerid, 24, 999);
return SCM(playerid, -1, "You got a desert eagle with 999 ammo !");
}
CMD:revolver(playerid, params[])
{
GivePlayerWeapon(playerid, 24, 999, true);
return SCM(playerid, -1, "You got a revolver with 999 ammo !");
}
stock S_GivePlayerWeapon(playerid, weaponid, ammo, bool:revolver = false)
{
if(weaponid == 24)
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
if(revolver) SetPlayerAttachedObject(playerid, GetLowestID(playerid), 16969, RIGHT_HAND);
else SetPlayerAttachedObject(playerid, GetLowestID(playerid), 14077, RIGHT_HAND)
}
GivePlayerWeapon(playerid, weaponid, ammo);
return 1;
}
GetLowestID(playerid)
{
for(new i = 0; i < 10; i++)
{
if(!IsPlayerAttachedObjectSlotUsed(playerid, i)) return i;
}
return -1;
}
new bool:revEquipped[MAX_PLAYERS char] = false;
new shots[MAX_PLAYERS char] , oldw[MAX_PLAYERS char];
new slot[2 char] = {-1, -1};
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(revEquipped{playerid} && ++shots{playerid} == 6) // Checking if it's the sixth shot after the last reload
{
SetPlayerArmedWeapon(playerid, 0); // We set the armed weapon of the player to 0
SetPlayerArmedWeapon(playerid, 24); // We set the armed weapon to the revolver back, means the ammo was reloaded
ApplyAnimation(playerid, "PYTHON", "python_reload", 4.1, 0, 0, 0, 0, 1); // We apply the reloading animation
shots{playerid} = 0; // We reset the "shot" counter
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new neww = GetPlayerWeapon(playerid);
if(neww != oldw[playerid])
{
if(oldw{playerid} == 24)
{
if(revEquipped{playerid}) RemovePlayerAttachedObject(playerid, slot{0});
else RemovePlayerAttachedObject(playerid, slot{1});
}
if(neww == 24)
{
if(revEquipped{playerid}) SetPlayerAttachedObject(playerid, GetLowestID(playerid), 16969, RIGHT_HAND);
else SetPlayerAttachedObject(playerid, GetLowestID(playerid), 14077, RIGHT_HAND);
}
}
oldw{playerid} = neww;
return 1;
}
#include <a_samp>
#include <zcmd>
#define SCM SendClientMessage
#define RIGHT_HAND 6
new bool:revEquipped[MAX_PLAYERS char] = false;
new shots[MAX_PLAYERS char], oldw[MAX_PLAYERS char];
new slot[2 char] = {-1, -1};
CMD:deagle(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
GivePlayerWeapon(playerid, 24, 999);
return SCM(playerid, -1, "You got a desert eagle with 999 ammo !");
}
CMD:revolver(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
GivePlayerWeapon(playerid, 24, 999, true);
revEquipped{playerid} = true;
return SCM(playerid, -1, "You got a revolver with 999 ammo !");
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(revEquipped{playerid} && ++shots{playerid} == 6 && weaponid == 24) // Checking if it's the sixth shot after the last reload
{
SetPlayerArmedWeapon(playerid, 0); // We set the armed weapon of the player to 0
SetPlayerArmedWeapon(playerid, 24); // We set the armed weapon to the revolver back, means the ammo was reloaded
ApplyAnimation(playerid, "PYTHON", "python_reload", 4.1, 0, 0, 0, 0, 1); // We apply the reloading animation
shots{playerid} = 0; // We reset the "shot" counter
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new neww = GetPlayerWeapon(playerid);
if(neww != oldw[playerid])
{
if(oldw{playerid} == 24)
{
if(revEquipped{playerid}) RemovePlayerAttachedObject(playerid, slot{0});
else RemovePlayerAttachedObject(playerid, slot{1});
}
if(neww == 24)
{
if(revEquipped{playerid}) SetPlayerAttachedObject(playerid, GetLowestID(playerid), 16969, RIGHT_HAND);
else SetPlayerAttachedObject(playerid, GetLowestID(playerid), 14077, RIGHT_HAND);
}
}
oldw{playerid} = neww;
return 1;
}
stock S_GivePlayerWeapon(playerid, weaponid, ammo, bool:revolver = false)
{
if(weaponid == 24)
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a weapon !");
if(revolver)
{
slot{0} = GetLowestID(playerid);
SetPlayerAttachedObject(playerid, GetLowestID(playerid), 16969, RIGHT_HAND);
}
else
{
slot{1} = GetLowestID(playerid);
SetPlayerAttachedObject(playerid, GetLowestID(playerid), 14077, RIGHT_HAND);
}
}
GivePlayerWeapon(playerid, weaponid, ammo);
return 1;
}
#if defined _ALS_GivePlayerWeapon
#undef GivePlayerWeapon
#else
#define _ALS_GivePlayerWeapon
#endif
#define GivePlayerWeapon S_GivePlayerWeapon
stock GetLowestID(playerid)
{
for(new i = 0; i < 10; i++)
{
if(!IsPlayerAttachedObjectSlotUsed(playerid, i)) return i;
}
return -1;
}
objs 12034, om4, om4, 299, 0 15222, acr, acr, 299, 0 end
#include <a_samp>
#include <zcmd>
#define SCM SendClientMessage
#define RIGHT_HAND 6
new bool:acrEquipped[MAX_PLAYERS char] = false;
new shots[MAX_PLAYERS char], oldw[MAX_PLAYERS char], bool:crouched[MAX_PLAYERS char];
new slot[2 char] = {-1, -1};
CMD:m4(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a heavy weapon !");
GivePlayerWeapon(playerid, 31, 999);
return SCM(playerid, -1, "You got a M4 with 999 ammo !");
}
CMD:acr(playerid, params[])
{
if(GetLowestID(playerid) == -1) return SCM(playerid, -1, "You have too many things on you to carry a heavy weapon !");
GivePlayerWeapon(playerid, 31, 999, true);
acrEquipped{playerid} = true;
return SCM(playerid, -1, "You got an ACR with 999 ammo !");
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
if( (PRESSED(KEY_CROUCH)) && (!crouched{playerid}) ) crouched{playerid} = true;
if( (PRESSED(KEY_CROUCH)) && ( crouched{playerid}) ) crouched{playerid} = false;
return 1;
}
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
if(acrEquipped{playerid} && ++shots{playerid} == 40 && weaponid == 31)
{
SetPlayerArmedWeapon(playerid, 0);
SetPlayerArmedWeapon(playerid, 31);
if(!crouched{playerid}) ApplyAnimation(playerid, "COLT", "colt45_reload", 4.1, 0, 0, 0, 0, 1);
else ApplyAnimation(playerid, "COLT", "colt45_crouchreload", 4.1, 0, 0, 0, 0, 1);
shots{playerid} = 0; // We reset the "shot" counter
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new neww = GetPlayerWeapon(playerid);
if(neww != oldw{playerid})
{
if(oldw{playerid} == 31)
{
if(acrEquipped{playerid}) RemovePlayerAttachedObject(playerid, slot{0});
else RemovePlayerAttachedObject(playerid, slot{1});
}
if(neww == 31)
{
if(acrEquipped{playerid}) SetPlayerAttachedObject(playerid, GetLowestID(playerid), 15222, RIGHT_HAND);
else SetPlayerAttachedObject(playerid, GetLowestID(playerid), 12034, RIGHT_HAND);
}
}
oldw{playerid} = neww;
return 1;
}
stock S_GivePlayerWeapon(playerid, weaponid, ammo, bool:acr = false)
{
if(weaponid == 31)
{
if(acr)
{
slot{0} = GetLowestID(playerid);
SetPlayerAttachedObject(playerid, GetLowestID(playerid), 15222, RIGHT_HAND);
}
else
{
slot{1} = GetLowestID(playerid);
SetPlayerAttachedObject(playerid, GetLowestID(playerid), 12034, RIGHT_HAND);
}
}
GivePlayerWeapon(playerid, weaponid, ammo);
return 1;
}
#if defined _ALS_GivePlayerWeapon
#undef GivePlayerWeapon
#else
#define _ALS_GivePlayerWeapon
#endif
#define GivePlayerWeapon S_GivePlayerWeapon
stock GetLowestID(playerid)
{
for(new i = 0; i < 10; i++)
{
if(!IsPlayerAttachedObjectSlotUsed(playerid, i)) return i;
}
return -1;
}
Well, true.
I'll correct it right now. But how to check for the shooting animation because it's applied each time a shot is fired, and we actually can't know when a shot is fired using pawn, can't we ? EDIT : Finally done. |
[13:51:37] Warning(opcode 0x107): Exception 0xC0000005 at 0x59F8B4