SA-MP Forums Archive
Count how many bullets fired. - 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: Count how many bullets fired. (/showthread.php?tid=456487)



Count how many bullets fired. - Slepur - 06.08.2013

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;
}



Re: Count how many bullets fired. - Slepur - 06.08.2013

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


Re: Count how many bullets fired. - Vanter - 06.08.2013

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


Re: Count how many bullets fired. - RedFusion - 06.08.2013

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!


Re: Count how many bullets fired. - Slepur - 06.08.2013

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-")


Re: Count how many bullets fired. - RedFusion - 06.08.2013

Edited


Re: Count how many bullets fired. - Konstantinos - 06.08.2013

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.


Re: Count how many bullets fired. - Slepur - 06.08.2013

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;
}



Re: Count how many bullets fired. - Konstantinos - 06.08.2013

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


Re: Count how many bullets fired. - Slepur - 06.08.2013

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.