SA-MP Forums Archive
Help with max ammo for weapon - 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: Help with max ammo for weapon (/showthread.php?tid=624845)



Help with max ammo for weapon - Markoni990 - 23.12.2016

Hi all. I have a question for player weapons. How can i set max ammo for some weapon in hand.? Example:
Max ammo in hand for Desert Eagle is 150 and when someone give me deagle with 200 ammo, it should automatically reduced ammo in my "hand" on 150. and it should tell me in chat that max ammo fot that weapon is 150. Thanks in advance


Re: Help with max ammo for weapon - JaKe Elite - 24.12.2016

Try this out.

PHP код:
new weapons[13][2];
for(new 
i=0i<13i++)
{
    
GetPlayerWeaponData(playeridiweapons[i][0], weapons[i][1]);
}
if(
weapons[2][0] == 24 && weapons[2][1] > 150)
{
    
// Checks if player has Desert Eagle on their inventory.
    // If the ammo for Desert Eagle exceeds 150, It will be setted back to 150.
    
SetPlayerAmmo(playeridweapons[2][0], 150);




Re: Help with max ammo for weapon - Markoni990 - 24.12.2016

Код:
forward OruzjeRuka(playerid);
public OruzjeRuka(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new weapons[13][2];
for(new i=0; i<13; i++)
{
    GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
}
 
if(weapons[2][0] == 24 && weapons[2][1] > 150)
{
    // Checks if player has Desert Eagle on their inventory.
    // If the ammo for Desert Eagle exceeds 150, It will be setted back to 150.
    SetPlayerAmmo(playerid, weapons[2][0], 150);
}
return 1;
}
I put this under OnGameModeInit() I put the timer to check SetTimer("OruzjeRuka",1000,1);

OruzjeRuka=WeaponHand

I want to put other weapons too.


Re: Help with max ammo for weapon - JaKe Elite - 24.12.2016

Quote:
Originally Posted by Markoni990
Посмотреть сообщение
Код:
forward OruzjeRuka(playerid);
public OruzjeRuka(playerid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
new weapons[13][2];
for(new i=0; i<13; i++)
{
    GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
}
 
if(weapons[2][0] == 24 && weapons[2][1] > 150)
{
    // Checks if player has Desert Eagle on their inventory.
    // If the ammo for Desert Eagle exceeds 150, It will be setted back to 150.
    SetPlayerAmmo(playerid, weapons[2][0], 150);
}
return 1;
}
I put this under OnGameModeInit() I put the timer to check SetTimer("OruzjeRuka",1000,1);

OruzjeRuka=WeaponHand

I want to put other weapons too.
Simply do this

PHP код:
if(weapons[weaponslot][0] == weaponid && weapons[weaponslot][1] > ammo)
{
    
// Code here
    
SetPlayerAmmo(playeridweapons[weaponslot][0], ammo);

Weapon Slots for each WeaponIDs can be found here