Checking if a player has a certain weapon in hand.
#1

Basically, I need help with a coding, what it's suppose to do is, if the player possesses a Shotgun, it attaches a Shotgun to their back. I got the Shotgun sticking to their back code, I just need help with the, checking if a player has a gun, and where the code should go. I'm not sure where to place this code, thanks.

Код:
if(GetPlayerWeapon(playerid) != 25)
{
    // attaches the shotgun to players back
}
Reply
#2

Put this at the end of the gamemode.

Код:
   stock gCheckPlayerWeapon(playerid, _weaponid)
   {
      const MAX_WEAPONS_SLOTS = 13;
      static ammo, weaponid;
      for (new i; i != MAX_WEAPONS_SLOTS; i++)
   {
      if (GetPlayerWeaponData(playerid, i, weaponid, ammo) == 0)
      return 0;
      if (weaponid == _weaponid)
      return 1;
   }
   return 0;
   }
And put this one in the OnPlayerSpawn public.
Код:
if(gCheckPlayerWeapon(playerid, putweaponidhere)) //put the id of the weapon that you desire
{
//attach shotgun code
}
Reply
#3

Quote:
Originally Posted by Battallboi
Посмотреть сообщение
Put this at the end of the gamemode.

Код:
   stock gCheckPlayerWeapon(playerid, _weaponid)
   {
      const MAX_WEAPONS_SLOTS = 13;
      static ammo, weaponid;
      for (new i; i != MAX_WEAPONS_SLOTS; i++)
   {
      if (GetPlayerWeaponData(playerid, i, weaponid, ammo) == 0)
      return 0;
      if (weaponid == _weaponid)
      return 1;
   }
   return 0;
   }
And put this one in the OnPlayerSpawn public.
Код:
if(gCheckPlayerWeapon(playerid, putweaponidhere)) //put the id of the weapon that you desire
{
//attach shotgun code
}
Doesn't work, I spawn the weapon and it doesn't place gun on my back
Reply
#4

Quote:
Originally Posted by Swarn
Посмотреть сообщение
Doesn't work, I spawn the weapon and it doesn't place gun on my back
Maybe you have to put

Код:
if(gCheckPlayerWeapon(playerid, putweaponidhere)) //put the id of the weapon that you desire
{
//attach shotgun code <<<<<<<<<<<<<<<<<<<<<<<<< HERE
}
Your attach code hm (?)
Reply
#5

Yeah, I put the attach code in, if you need it, here;
Код:
SetPlayerAttachedObject(playerid, 4,349,1,-0.102073, -0.200483, 0.094914, 15.186383, 61.980533, 357.054473);
Reply
#6

Okay, then put this:

Код:
if(gCheckPlayerWeapon(playerid, putweaponidhere)) //put the id of the weapon that you desire
{
SetPlayerAttachedObject(playerid, 4,349,1,-0.102073, -0.200483, 0.094914, 15.186383, 61.980533, 357.054473);
}
in OnPlayerUpdate and test it
Reply
#7

Yeah, that works, thanks.
But slight problem

When the player shoots all the ammo out, the weapon stays on his back, how to fix?
Reply
#8

Код:
new wep[2];
GetPlayerWeaponData(playerid, i, wep[0], wep[1]); // wep[0] = weapon ID - wep[1] = ammo of the weapon
if(gCheckPlayerWeapon(playerid, putweaponidhere))
{
	if(wep[0] == IDWEAP && wep[1] == 0) RemovePlayerAttachedObject(playerid, 4);
	SetPlayerAttachedObject(playerid, 4, 349,1,-0.102073, -0.200483, 0.094914, 15.186383, 61.980533, 357.054473); // Here put the attach of the weapon that you want
}
Try with this
Reply
#9

Where do I put that?
Reply
#10

I wouldn't recommend putting it on OnPlayerUpdate, put it in a timer.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)