Bullet Count
#1

Hi, is there anyway to count how many bullets did player(s) shoot?
Reply
#2

Not exactly, but you could create an array of how many bullets are in a magazine for each weapon, then detect WEAPON_STATE_RELOADING or weapon switches.

https://sampwiki.blast.hk/wiki/GetPlayerWeaponState

I made this array a while ago:

pawn Код:
new weapon_capacity[] = { // 0-no ammo 1-any ammo      else-min ammo
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
1,
1,
1,
-1,
-1,
-1,
34,
17,
7,
1,
4,
7,
100,
30,
30,
50,
100,
1,
1,
1,
1,
50,
500,
1,
0,
500,
500,
36,
0,
0,
0
};
-1 means that weapon is invalid
0 means it doesn't have ammo i.e. a baseball bat
1 means it has 1 ammo, such as grenades or RPGs
anything above that is the magazine size.

NOTE: I think ammo will be different depending on skill, you'll have to check.
Reply
#3

Whipped this up in a few seconds. Not sure if it will work correctly, or even compile, but this should give you some sort of idea.

pawn Код:
#define     KEY_AIM     (128)

#define HOLDING(%0) \
    ((newkeys & (%0)) == (%0))
   
#define PRESSED(%0) \
    (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
   
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(HOLDING(KEY_AIM)) && PRESSED(KEY_FIRE) || HOLDING(KEY_AIM) && HOLDING(KEY_FIRE))
    {
        if(GetPlayerWeapon(playerid) == 24)
        {
            //They shot their Desert Eagle.
        }
    }
    return true;
}
Reply
#4

Your idea don't work. But i made
pawn Код:
if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
    if(GetPlayerWeapon( playerid ) == 38 )
    {
        print("Key");
    }
return true;
}
But it's counting only one time when i hold. I need to make it work, that it would count every bullet.
Reply
#5

Quote:
Originally Posted by No Fear
Посмотреть сообщение
Your idea don't work. But i made
pawn Код:
if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
    if(GetPlayerWeapon( playerid ) == 38 )
    {
        print("Key");
    }
return true;
}
But it's counting only one time when i hold. I need to make it work, that it would count every bullet.
I don't think it will be achieved using GetPlayerKey because it will not be accurate.
Reply
#6

Quote:
Originally Posted by No Fear
Посмотреть сообщение
Your idea don't work. But i made
pawn Код:
if((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
{
    if(GetPlayerWeapon( playerid ) == 38 )
    {
        print("Key");
    }
return true;
}
But it's counting only one time when i hold. I need to make it work, that it would count every bullet.
Use onplayerupdate
pawn Код:
new PlayerAmmo[MAX_PLAYERS];
public OnPlayerUpdate(playerid)
{
 new ammo = GetPlayerAmmo(playerid);
 if(ammo < PlayerAmmo[playerid])
 {
    new BulletsShot = (PlayerAmmo[playerid]-ammo);
 }
 PlayerAmmo[playerid]=ammo;
 return 1;
}
This is just the idea, you might wanna check for the weapon etc.
Reply
#7

i see, so maybe there is any other way?
Wups: thanks i''ll try
Reply
#8

Sorry not working :/
Reply
#9

Quote:
Originally Posted by No Fear
Посмотреть сообщение
Sorry not working :/
What's not working? Show me your code.
Reply
#10

It's the same as you given i printed it to show it's showing 2.... I just need a code that server could count how many bullets players shoot.

"Total bullets players shoot: 1300000000000000" like
something
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)