SA-MP Forums Archive
Giving Player only a Weapon (No Ammo) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Giving Player only a Weapon (No Ammo) (/showthread.php?tid=603994)



Giving Player only a Weapon (No Ammo) - eikzdej - 30.03.2016

As the title says, is this possible?


Re: Giving Player only a Weapon (No Ammo) - DiverseCardinal - 30.03.2016

Short Answer: No.

Reasoning: There are three functions related to weapons, SetPlayerArmedWeapon, GivePlayerWeapon and GetPlayerWeapon. The function you would want, GivePlayerWeapon, takes three arguments: playerid, weaponid, and ammo. The ammo parameter is not optional. You can, however, set it to a very small amount like one bullet as such:

Код:
GivePlayerWeapon(playerid, 29, 1);
N.B: Of course, you can give a melee weapon without ammo. The ammo parameter must be supplied with a number > 0, but it's not actually going to affect "how much" of the melee weapon the player will have. If you try to give the player a weapon with the ammo parameter at 0, the weapon will very quickly appear in the player's inventory and then disappear.


Re: Giving Player only a Weapon (No Ammo) - -CaRRoT - 30.03.2016

Yes, you can create a function that uses SetPlayerAttachedObject, attach the model ID to the right hand (Bone 6) and save the weapon ID you wanna give as a var, once you wanna give him ammo, just get the var ID and replace the attached object with an actual weapon.


Re: Giving Player only a Weapon (No Ammo) - itsCody - 30.03.2016

You could attach the weapon object to the player also.

edit; why teh fuck am i so slow.


Re: Giving Player only a Weapon (No Ammo) - DiverseCardinal - 30.03.2016

Quote:
Originally Posted by -CaRRoT
Yes, you can create a function that uses SetPlayerAttachedObject, attach the model ID to the right hand (Bone 6) and save the weapon ID you wanna give as a var, once you wanna give him ammo, just get the var ID and replace the attached object with an actual weapon.
Didn't think of that, now I feel stupid.


Re: Giving Player only a Weapon (No Ammo) - eikzdej - 30.03.2016

Thanks Guys, i thinking of it right now, but i have one problem, What if i ran out of ammo? Does the Attached Object will removed also?


Re: Giving Player only a Weapon (No Ammo) - -CaRRoT - 30.03.2016

You don't need an attached object if you were already shooting, you only attach the object if you have 0 ammo, so the 2 scenarios you'd do that is that if you give someone a gun with no ammo, then you'd attach the object, or if you run out of ammo while shooting, you'd attach the object. Other than that, make sure to deattach it while having a gun with ammo.


Re: Giving Player only a Weapon (No Ammo) - DiverseCardinal - 30.03.2016

No. The weapon and the object are considered distinct entities.

Edit: Too slow, I guess. But I just did some quick testing with a Colt 45 weapon and Colt 45 model and while the object's attached, it will seem like the player's holding two guns. When the weapon runs out of ammo, it will disappear but the model will stay. I don't know about bigger weapons or differing weapons; I'd say it's best to follow what -CaRRoT outlined above me.