Set Ammo
#1

How can I make it so it sets the players ammo to -30-30 when they get in a car? I've tryed SetPlayerAmmo(playerid,gun,-30);
GivePlayerWeapon(playerid,gun,-30);

Also how could I make it so when the player is looking left/right in a car, and they try and fire, it will like, slap them out of the car? <<-- Nevermind I figured that out

But I still need help figuring out the -30 ammo thing.
Reply
#2

Quote:
Originally Posted by Lars_Frederiksen
Посмотреть сообщение
How can I make it so it sets the players ammo to -30-30 when they get in a car? I've tryed SetPlayerAmmo(playerid,gun,-30);
GivePlayerWeapon(playerid,gun,-30);

Also how could I make it so when the player is looking left/right in a car, and they try and fire, it will like, slap them out of the car? <<-- Nevermind I figured that out

But I still need help figuring out the -30 ammo thing.
you could remove the weapon and let it remember the ammo it had, then add the same weapon with the remembered ammo - 30
Reply
#3

You should use:
pawn Код:
new ammo = GetPlayerAmmo(playerid);
ammo -=30;
SetPlayerAmmo(playerid,gun,ammo);
Reply
#4

Neither of those two work... I think the SetPlayerAmmo thing is bugged or something, here's my code.

pawn Код:
switch(GetPlayerWeapon(playerid)) // mp5, tech 9, mac 10 by lars
        {
            case 29, 28, 32:
            {
                new gun = GetPlayerWeapon(playerid);
                new ammo = GetPlayerAmmo(playerid);
                ammo -=30;
                SetPlayerAmmo(playerid,gun,ammo);
                //RemovePlayerWeapon(playerid, gun);
                PlayerInfo[playerid][pHadGun] = 1;
                PlayerInfo[playerid][pHadGunID] = gun;
            }
        }
This literally doesn't do anything, player still has all his ammo.
Reply
#5

Just set it's ammo to 0.

Or make a variable saving the players weapons and ammo, then you reset hes ammo, and when they get out of their car you give his weapons again..
Reply
#6

Okay which gun slot would the MP5, Tech 9, Mac 10 save in? I have pAmmo1, pAmmo2, pAmmo3, pAmmo4, pAmmo5
Reply
#7

The guns are slot 4, if you need anymore slots here:
https://sampwiki.blast.hk/wiki/Weapons
Reply
#8

pawn Код:
new gun = GetPlayerWeapon(playerid);
                new ammo = -30;
                RemovePlayerWeapon(playerid, gun);
                PlayerInfo[playerid][pAmmo4] = ammo;
                GivePlayerWeapon(playerid, gun, ammo);
                PlayerInfo[playerid][pHadGun] = 1;
                PlayerInfo[playerid][pHadGunID] = gun;
Nah not workin.
Reply
#9

pawn Код:
new Weapon[MAX_PLAYERS][13];
new Ammo[MAX_PLAYERS][13];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER)
    {
        for(new i = 0; i < 13; i++)
        {
            GetPlayerWeaponData(playerid, i, Weapon[playerid][i], Ammo[playerid][i]);
            ResetPlayerWeapons(playerid);
        }
    }
    else if(newstate == PLAYER_STATE_ONFOOT)
    {
        for(new i = 0; i < 13; i++)
        {
            GivePlayerWeapon(playerid, Weapon[playerid][i], Ammo[playerid][i]);
        }
    }
    return 1;
}
There you go.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)