Need help! (+rep)
#1

So I came up with a way to "Hard Cap Ammo Capacity" on players. Problem is its not working.



pawn Код:
public IsAtAmmoLimit(playerid, gun, ammo)
{
    new weaponid, ammo2;
    GetPlayerWeaponData(playerid, gun, weaponid, ammo2);
    switch(gun)
    {
        case 0:
        {
            if(PlayerInfo[playerid][pGunAmmo0] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo0] == ammo2) { return 1; }
        }
        case 1:
        {
            if(PlayerInfo[playerid][pGunAmmo1] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo1] == ammo2) { return 1; }
        }
        case 2:
        {
            if(PlayerInfo[playerid][pGunAmmo2] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo2] == ammo2) { return 1; }
        }
        case 3:
        {
            if(PlayerInfo[playerid][pGunAmmo3] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo3] == ammo2) { return 1; }
        }
        case 4:
        {
            if(PlayerInfo[playerid][pGunAmmo4] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo4] == ammo2) { return 1; }
        }
        case 5:
        {
            if(PlayerInfo[playerid][pGunAmmo5] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo5] == ammo2) { return 1; }
        }
        case 6:
        {
            if(PlayerInfo[playerid][pGunAmmo6] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo6] == ammo2) { return 1; }
        }
        case 7:
        {
            if(PlayerInfo[playerid][pGunAmmo7] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo7] == ammo2) { return 1; }
        }
        case 8:
        {
            if(PlayerInfo[playerid][pGunAmmo8] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo8] == ammo2) { return 1; }
        }
        case 9:
        {
            if(PlayerInfo[playerid][pGunAmmo9] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo9] == ammo2) { return 1; }
        }
        case 10:
        {
            if(PlayerInfo[playerid][pGunAmmo10] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo10] == ammo2) { return 1; }
        }
        case 11:
        {
            if(PlayerInfo[playerid][pGunAmmo11] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo11] == ammo2) { return 1; }
        }
        case 12:
        {
            if(PlayerInfo[playerid][pGunAmmo12] + ammo <= 500 && PlayerInfo[playerid][pGunAmmo12] == ammo2) { return 1; }
        }
    }
    return 0;
}
pawn Код:
if(PlayerInfo[playerid][pArmsSkill] >= 0)
                {
                    if(PlayerInfo[playerid][pCarP] >= 125 && IsAtAmmoLimit(playerid, 22, 120) == 1)
                    {
                        SafeGivePlayerWeapon(playerid, 22, 120);
                        PlayerInfo[playerid][pCarP] -= 125;
                        PlayerInfo[playerid][pArmsSkill]++;
                        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "[Legendary Gaming RolePlay]:");
                        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You successfully made a [ Pistol ] from the Gunsmith!");
                        if(PlayerInfo[playerid][pArmsSkill] == 50)
                        { SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 2, New Weapon Schematic: The Rifle."); }
                        else if(PlayerInfo[playerid][pArmsSkill] == 100)
                        { SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 3, New Weapon Schematic: The MP5."); }
                        else if(PlayerInfo[playerid][pArmsSkill] == 200)
                        { SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now LVL 4, New Weapon Schematics: The Desert Eagle."); }
                        else if(PlayerInfo[playerid][pArmsSkill] == 500)
                        { SendClientMessage(playerid, COLOR_YELLOW, "* Maximumn Level Achieved!, New Weapon Schematic: The AK-47/M4."); }
                    }
                    else
                    {
                        SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have enough Car Parts!");
                    }
                }
                else
                {
                    SendClientMessage(playerid, COLOR_LIGHTRED, "You lack the Weapon Crafting Level to Make That!");
                }
Its not creating the gun. Even with 0 Ammo/no gun in hand.
Reply
#2

You are not creating the gun with GivePlayerWeapon(payerid,weapon,ammo);
Reply
#3

Quote:
Originally Posted by HDFord
Посмотреть сообщение
You are not creating the gun with GivePlayerWeapon(payerid,weapon,ammo);
Exactly. Ford why dont you correct his code here?
Reply
#4

Since you aren't really returning anything significant you can use this instead...

pawn Код:
new pGunInfo[MAX_PLAYERS][13];
//We can set these cells to their current ammo cap for each weapon slot.

public IsAtAmmoLimit(playerid)
{
    new weapon[13][2];
    for(new i=0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, weapon[i][0], weapon[i][1]);
        if(weapon[i][1] > pGunInfo[playerid][i]) return true; //this will check if any are above that, then it will return true
    }
    return false; //if none of the weapons have more ammo than their cap it will get to this then return false
}
Reply
#5

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
Since you aren't really returning anything significant you can use this instead...

pawn Код:
new pGunInfo[MAX_PLAYERS][13];
//We can set these cells to their current ammo cap for each weapon slot.

public IsAtAmmoLimit(playerid)
{
    new weapon[13][2];
    for(new i=0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, weapon[i][0], weapon[i][1]);
        if(weapon[i][1] > pGunInfo[playerid][i]) return true; //this will check if any are above that, then it will return true
    }
    return false; //if none of the weapons have more ammo than their cap it will get to this then return false
}
Where would I put the ammo cap?
Reply
#6

pGunInfo[playerid][WEAPONSLOT] = 500;

Would set any weapon on that weapon slot to only be able to have 500 ammo


https://sampwiki.blast.hk/wiki/Weapons
Reply
#7

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
pGunInfo[playerid][WEAPONSLOT] = 500;

Would set any weapon on that weapon slot to only be able to have 500 ammo


https://sampwiki.blast.hk/wiki/Weapons
How would I code that in? Could you give a sample? Im kind of confused TBH.
Reply
#8

Quote:
Originally Posted by Medardo4Life
Посмотреть сообщение
How would I code that in? Could you give a sample? Im kind of confused TBH.
I noticed I messed up a little bit :P


pawn Код:
public IsAtAmmoLimit(playerid, weaponid, ammo)
{
    new weapon[13][2], ammo2;
    for(new i=0; i < 13; i++)
    {
        //GetPlayerWeaponData(playerid, SLOT, WEAPON, AMMO); is the syntax for below
        GetPlayerWeaponData(playerid, i, weapon[i][0], weapon[i][1]);
        if(weapon[i][1] == weaponid)
        {
            ammo2 = weapon[i][1]+ammo; //we store their ammo...say they have 200 but we add 300, ammo2 will be at 500
            if(ammo2 > pGunInfo[playerid][i]) return true; //if it will be above, we're going to return true
        }
    }
    return false; //if not return false
}
if(!IsAtAmmoLimit(playerid, 24, 300)) //This would be if they aren't going to be above the ammo limit
if(IsAtAmmoLimit(playerid, 24, 300))  //This would be if they are going to be above the limit


if(PlayerInfo[playerid][pArmsSkill] >= 0)
{
    if(PlayerInfo[playerid][pCarP] >= 125 && !IsAtAmmoLimit(playerid, 22, 120)) //an example on how to use it
    {
        SafeGivePlayerWeapon(playerid, 22, 120);
        PlayerInfo[playerid][pCarP] -= 125;
        PlayerInfo[playerid][pArmsSkill]++;
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "[Legendary Gaming RolePlay]:");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You successfully made a [ Pistol ] from the Gunsmith!");
        if(PlayerInfo[playerid][pArmsSkill] == 50) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 2, New Weapon Schematic: The Rifle.");
        else if(PlayerInfo[playerid][pArmsSkill] == 100) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 3, New Weapon Schematic: The MP5.");
        else if(PlayerInfo[playerid][pArmsSkill] == 200) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now LVL 4, New Weapon Schematics: The Desert Eagle.");
        else if(PlayerInfo[playerid][pArmsSkill] == 500) SendClientMessage(playerid, COLOR_YELLOW, "* Maximumn Level Achieved!, New Weapon Schematic: The AK-47/M4.");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have enough Car Parts!");
}
else return SendClientMessage(playerid, COLOR_LIGHTRED, "You lack the Weapon Crafting Level to Make That!");

You'll need to set their max ammo when they log in.

pawn Код:
pGunInfo[playerid][1] = 1; //Will set those melee weapons to 1 ammo max
as an example
Reply
#9

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
I noticed I messed up a little bit :P


pawn Код:
public IsAtAmmoLimit(playerid, weaponid, ammo)
{
    new weapon[13][2], ammo2;
    for(new i=0; i < 13; i++)
    {
        //GetPlayerWeaponData(playerid, SLOT, WEAPON, AMMO); is the syntax for below
        GetPlayerWeaponData(playerid, i, weapon[i][0], weapon[i][1]);
        if(weapon[i][1] == weaponid)
        {
            ammo2 = weapon[i][1]+ammo; //we store their ammo...say they have 200 but we add 300, ammo2 will be at 500
            if(ammo2 > pGunInfo[playerid][i]) return true; //if it will be above, we're going to return true
        }
    }
    return false; //if not return false
}
if(!IsAtAmmoLimit(playerid, 24, 300)) //This would be if they aren't going to be above the ammo limit
if(IsAtAmmoLimit(playerid, 24, 300))  //This would be if they are going to be above the limit


if(PlayerInfo[playerid][pArmsSkill] >= 0)
{
    if(PlayerInfo[playerid][pCarP] >= 125 && !IsAtAmmoLimit(playerid, 22, 120)) //an example on how to use it
    {
        SafeGivePlayerWeapon(playerid, 22, 120);
        PlayerInfo[playerid][pCarP] -= 125;
        PlayerInfo[playerid][pArmsSkill]++;
        SendClientMessage(playerid, COLOR_LIGHTYELLOW, "[Legendary Gaming RolePlay]:");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "You successfully made a [ Pistol ] from the Gunsmith!");
        if(PlayerInfo[playerid][pArmsSkill] == 50) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 2, New Weapon Schematic: The Rifle.");
        else if(PlayerInfo[playerid][pArmsSkill] == 100) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now Level 3, New Weapon Schematic: The MP5.");
        else if(PlayerInfo[playerid][pArmsSkill] == 200) SendClientMessage(playerid, COLOR_YELLOW, "* Weapon Crafter Skill is now LVL 4, New Weapon Schematics: The Desert Eagle.");
        else if(PlayerInfo[playerid][pArmsSkill] == 500) SendClientMessage(playerid, COLOR_YELLOW, "* Maximumn Level Achieved!, New Weapon Schematic: The AK-47/M4.");
    }
    else return SendClientMessage(playerid, COLOR_LIGHTRED, "You don't have enough Car Parts!");
}
else return SendClientMessage(playerid, COLOR_LIGHTRED, "You lack the Weapon Crafting Level to Make That!");

You'll need to set their max ammo when they log in.

pawn Код:
pGunInfo[playerid][1] = 1; //Will set those melee weapons to 1 ammo max
as an example
Do I need to add pGunInfo to each player's save file? or just add it under /playerlogin and/or connect?
Reply
#10

It depends...Do you want it to change per player (like a skill or something) or do you want it to just be a global max ammo...If it's global just add it under ongamemodeinit, if it's per player i would do it in a save file then load it or do it when they log in based on their current skill level

pawn Код:
public OnGameModeInit()
{
    for(new player=0; player < MAX_PLAYERS; player++)
    {
        pGunInfo[player][1] = 1; //melee weapons
        pGunInfo[player][2] = 200; //pistols
        pGunInfo[player][3] = 200; //shotguns
        pGunInfo[player][4] = 600; //SMGs
        pGunInfo[player][5] = 400; //M4/AK
        pGunInfo[player][6] = 100; //Sniper/Country
        pGunInfo[player][7] = 0; //RPG/Flamethrower/Minigun
        pGunInfo[player][8] = 0; //satchel, nades, molotovs, tear gas
        pGunInfo[player][9] = 30; //camera, fire extinguisher, spraycan
        pGunInfo[player][10] = 1; //other melee weapons
        pGunInfo[player][11] = 1; //para/goggles
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)