Count how many bullets fired.
#1

I've got the script working for the most part, but there's a bug that I can't seem to get my head around.

At the moment it logs how much ammo the player has and how many shots the player has made... The problem is that when they get a weapon which over rides the previous weapon, it adds the ammo lost from that weapon onto the pTotalFired.

Say I have a regular shotgun with 500 bullets... When I get the Combat Shotgun and it removes the regular shotgun from the player it adds the 500 bullets from that shotgun to the total shots.

Код:
new pAmmo[MAX_PLAYERS];
new pTotalFired[MAX_PLAYERS];
public OnPlayerUpdate(playerid)
{
	new playerammo = GetPlayerAmmo(playerid);
	if(playerammo < pAmmo[playerid])
	{
		new ShotsFired = (pAmmo[playerid]-playerammo);
		pTotalFired[playerid]+=ShotsFired;
	}
	pAmmo[playerid]=playerammo;
	return 1;
}
Reply
#2

Still can't get my head around this after an hour of messing around >.<
Reply
#3

it's not like that, make some timer every 5 seconds maybe that counts the ammo, then subtracts the new ammo from the old (saved) ammo 5 seconds ago, then you'll come out with shots fired
Reply
#4

pawn Код:
new pAmmo[MAX_PLAYERS][13],
    pWeapon[MAX_PLAYERS][13],
    pTotalFired[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
    for(new slot = 0; slot < 13; slot++)
    {
        new ammo, weaponid;
        GetPlayerWeaponData(playerid, slot, weaponid, ammo);
        if(weaponid == pWeapon[playerid][slot] && ammo < pAmmo[playerid][slot] && GetPlayerWeapon(playerid) == weaponid)
        {
            new ShotsFired = (pAmmo[playerid][slot] - ammo);
            pTotalFired[playerid] += ShotsFired;
        }
        pAmmo[playerid][slot] = ammo;
        pWeapon[playerid][slot] = weaponid;
    }
    return 1;
}
Try this!
Reply
#5

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
pawn Код:
new pAmmo[MAX_PLAYERS][13],
    pWeapon[MAX_PLAYERS][13];
    pTotalFired[MAX_PLAYERS];

public OnPlayerUpdate(playerid)
{
    for(new slot = 0; slot < 13; slot++)
    {
        new ammo, weaponid;
        GetPlayerWeaponData(playerid, slot, weaponid, ammo);
        if(weaponid == pWeapon[playerid][slot] && ammo < pAmmo[playerid][slot)
        {
            new ShotsFired = (pAmmo[playerid][slot] - ammo);
            pTotalFired[playerid] += ShotsFired;
        }
        pAmmo[playerid][slot] = ammo;
        pWeapon[playerid][slot] = weaponid;
    }
    return 1;
}
Try this!
error 033: array must be indexed (variable "-unknown-")
Reply
#6

Edited
Reply
#7

pawn Код:
new pAmmo[MAX_PLAYERS][13],
    pWeapon[MAX_PLAYERS][13]; // << It's a semicolon, change to comma ','
    pTotalFired[MAX_PLAYERS];
And is the error from another line? If so, post it.
Reply
#8

Quote:
Originally Posted by RedFusion
Посмотреть сообщение
Edited
Still not working.

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new pAmmo[MAX_PLAYERS][13],
    pWeapon[MAX_PLAYERS][13]; // << It's a semicolon, change to comma ','
    pTotalFired[MAX_PLAYERS];
And is the error from another line? If so, post it.
Yeah, I noticed this. Already fixed it :P

The line the error is coming from is:
Код:
CMD:stats(playerid, params[])
{
	new wstring[238];
	new health = pInfo[playerid][pHealth];
	new armour = pInfo[playerid][pArmour];
	new shots = pTotalFired[playerid];
	new ammo = pAmmo[playerid];

	
	format(wstring, sizeof(wstring), "Health:[%d] Armour:[%d] Shots[%d] Ammo:[%d]",health,armour,shots,ammo);
	SendClientMessage(playerid,COLOR_WHITE, wstring);
	return 1;
}
Reply
#9

pawn Код:
new ammo = pAmmo[playerid];
Look, how it was declared before:
pawn Код:
pAmmo[MAX_PLAYERS][13]
You need somehow to pass the slot.
Reply
#10

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new ammo = pAmmo[playerid];
Look, how it was declared before:
pawn Код:
pAmmo[MAX_PLAYERS][13]
You need somehow to pass the slot.
Not too sure on how I could go about that.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)