SA-MP Forums

Go Back   SA-MP Forums > SA-MP > Bug Reports

Reply
 
Thread Tools Display Modes
Old 08/01/2015, 07:11 PM   #1
PaulDinam
Gangsta
 
Join Date: Jun 2011
Posts: 887
Reputation: 45
Default OnPlayerWeaponShot

It doesn't sync well when a player is firing from an MP5, i've tested every single weapon and this one turned out to have flaws.
PaulDinam is offline   Reply With Quote
Old 08/01/2015, 07:45 PM   #2
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: OnPlayerWeaponShot

Can you explain what you mean by syncing well? You mean sometimes the shots don't trigger the callback?
Abagail is offline   Reply With Quote
Old 08/01/2015, 08:19 PM   #3
PaulDinam
Gangsta
 
Join Date: Jun 2011
Posts: 887
Reputation: 45
Default Re: OnPlayerWeaponShot

Here's my entire callback:
I made a server-side weapon system and made this callback to update the player's ammo every time he fires a bullet, however the only weapon that i've come across that doesn't function well is the MP5 and it does not set the ammo accurately.

pawn Code:
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ)
{
    if( hittype != BULLET_HIT_TYPE_NONE ) // Bullet Crashing uses just this hittype
    {
        if( !( -1000.0 <= fX <= 1000.0 ) || !( -1000.0 <= fY <= 1000.0 ) || !( -1000.0 <= fZ <= 1000.0 ) ) // a valid offset, it's impossible that a offset bigger than 1000 is legit (also less than -1000.0 is impossible, not used by this hack, but still, let's check for it, just for the future, who knows what hacks will appear). The object with biggest offset is having ~700-800 radius.
        {
            Kick(playerid);
            return 0; // let's desynchronize that bullet, so players won't crash
        }
    }
    new beforeAmmo = PVar:playerid[WeaponAmmo][weaponid];
    new leftAmmo = GetWeaponAmmo(playerid, weaponid) - 1;
   
    if(PlayerHasWeapon(playerid, weaponid))
    {
        if(beforeAmmo - leftAmmo == 1)
        {
            if(!PVar:playerid[SpawnedWeapon][weaponid])
            {
                if(IsPrimaryWeapon(weaponid))
                {
                    if(weaponid == PVar:playerid[Weapons][PRIME_WEP])
                    {
                        if(leftAmmo == 0)
                        {
                            PVar:playerid[Weapons][PRIME_WEP] = 0;
                        }
                        PVar:playerid[Weapons][PRIME_AMMO] = leftAmmo;
                    }
                }
                else if(IsSecondaryWeapon(weaponid))
                {
                    if(weaponid == PVar:playerid[Weapons][SECOND_WEP])
                    {
                        if(leftAmmo == 0)
                        {
                            PVar:playerid[Weapons][SECOND_WEP] = 0;
                        }
                        PVar:playerid[Weapons][SECOND_AMMO] = leftAmmo;
                    }
                }      
            }
            if(leftAmmo == 0)
            {
                if(PVar:playerid[SpawnedWeapon][weaponid])
                {
                    PVar:playerid[SpawnedWeapon][weaponid] = false;
                    RemovePlayerWeapon(playerid, weaponid);
                }
            }
            PVar:playerid[WeaponAmmo][weaponid] = leftAmmo;
        }
    }
    return 1;
}
PaulDinam is offline   Reply With Quote
Old 08/01/2015, 08:28 PM   #4
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: OnPlayerWeaponShot

GetWeaponAmmo is not a SA:MP function, and I'm gonna guess that may very well be causing an issue. Would you mind showing us that function?
Abagail is offline   Reply With Quote
Old 08/01/2015, 08:30 PM   #5
PaulDinam
Gangsta
 
Join Date: Jun 2011
Posts: 887
Reputation: 45
Default Re: OnPlayerWeaponShot

pawn Code:
GetWeaponAmmo(playerid, weaponid)
{
    new weapon, ammo;
    GetPlayerWeaponData(playerid, GetWeaponSlot(weaponid), weapon, ammo);
    return ammo;
}

pawn Code:
GetWeaponSlot(weaponid)
{
    new slot;
    switch(weaponid)
    {
        case 0,1: slot = 0;
        case 2..9: slot = 1;
        case 22..24: slot = 2;
        case 25..27: slot = 3;
        case 28,29,32: slot = 4;
        case 30,31: slot = 5;
        case 33,34: slot = 6;
        case 35..38: slot = 7;
        case 16..18,39: slot = 8;
        case 41..43: slot = 9;
        case 10..15: slot = 10;
        case 44..46: slot = 11;
        case 40: slot = 12;
        default: slot = INVALID_WEAPON_SLOT_ID;
    }
    return slot;
}
PaulDinam is offline   Reply With Quote
Old 08/01/2015, 08:36 PM   #6
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: OnPlayerWeaponShot

Try seeing if the ammo is properly returned using GetPlayerAmmo. For example:

pawn Code:
GetWeaponAmmo(playerid, weaponid)
{
    new weapon, ammo;
    if(GetPlayerWeapon(playerid) == WEAPON_MP5)
    {
         return GetPlayerAmmo(playerid);
    }
    GetPlayerWeaponData(playerid, GetWeaponSlot(weaponid), weapon, ammo);
    return ammo;
}

Try seeing if this works.
Abagail is offline   Reply With Quote
Old 08/01/2015, 08:45 PM   #7
PaulDinam
Gangsta
 
Join Date: Jun 2011
Posts: 887
Reputation: 45
Default Re: OnPlayerWeaponShot

It returns the right amount and still doesn't work properly.
I'm pretty sure that the only reason that can explain this is because the MP5 is firing rather fast and OnPlayerWeaponShot gets called slower than expected.

I first had the problem with the UZI and TEC 9 because the bullets are getting fired really fast, I simply fixed it by setting the player's weapon skill to 1 so the fire rate will slow down. But doing that for the MP5 doesn't work.

PaulDinam is offline   Reply With Quote
Old 08/01/2015, 09:10 PM   #8
Abagail
High-roller
 
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: OnPlayerWeaponShot

You can try using OnPlayerKeyStateChange to try to account for lost bullets. You can also try freezing the player for 250ms after firing an MP5.
Abagail is offline   Reply With Quote
Old 09/01/2015, 09:40 AM   #9
Burooj
Banned
 
Join Date: Dec 2014
Posts: 78
Reputation: 22
Default Re: OnPlayerWeaponShot

I think you facing c-bug xd
Burooj is offline   Reply With Quote
Old 09/01/2015, 10:02 PM   #10
Grimrandomer
Big Clucker
 
Grimrandomer's Avatar
 
Join Date: Dec 2011
Posts: 131
Reputation: 64
Default Re: OnPlayerWeaponShot

Are you a driver when your firing your gun? It only works for passenger's and not drivers.

http://wiki.sa-mp.com/wiki/OnPlayerWeaponShot - "Only passenger drive-by is supported (not driver drive-by, and not sea sparrow / hunter shots)."

Would be nice if driver drive-by was synced.
__________________
Grimrandomer is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
OnPlayerWeaponShot Rudy_ Scripting Help 21 11/10/2014 01:41 PM
OnPlayerWeaponShot audriuxxx Scripting Help 2 11/05/2014 10:38 AM
OnPlayerWeaponShot audriuxxx Scripting Help 0 18/04/2014 10:07 AM
OnPlayerWeaponShot Bug Locky_ Bug Reports 2 23/02/2014 01:14 AM
OnPlayerWeaponShot bug FRIK Scripting Help 1 14/02/2014 05:01 AM


All times are GMT. The time now is 09:55 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.