SA-MP Forums Archive
[HELP] stock - 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: [HELP] stock (/showthread.php?tid=312705)



[HELP] stock - tomsalmon - 22.01.2012

hey, someone can give me a stock of when player shoot with his gun?


**no OnPlayerShootPlayer **

When Player Shoot every where with his gun

thanks for helpers


Respuesta: [HELP] stock - [Nikk] - 22.01.2012

Meabe you can use the public OnPlayerKeyStateChange.


Re: [HELP] stock - [XST]O_x - 22.01.2012

Althogh it's pretty useless you can use this:
pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if ((newkeys & KEY_FIRE) && !(oldkeys & KEY_FIRE))
    {
        new Weapon = GetPlayerWeapon(playerid);
        if((Weapon >= 22) && (Weapon <= 38)){
        return OnPlayerShoot(playerid,Weapon);}
    }
    return 1;
}

forward OnPlayerShoot(playerid, gunid);
public OnPlayerShoot(playerid, gunid)
{
    //do stuff here
    return 1;
}



Re: [HELP] stock - Gh05t_ - 22.01.2012

There is a more efficient method through the use of OnPlayerTakeDamage. https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage


AW: [HELP] stock - Nero_3D - 22.01.2012

He doesnt want a OnPlayerShotPlayer
He just wants a public which gets called each time the player fires his weapon
And not if he hits somebody

pawn Код:
new
    pAmmo[MAX_PLAYERS],
    pWeapon[MAX_PLAYERS],
    bool: pShooting[MAX_PLAYERS];

forward OnPlayerShot(playerid, weaponid);
pawn Код:
//OnPlayerKeyStateChange
    if(pShooting[playerid] == false) {
        if((pShooting[playerid] = bool: (newkeys & KEY_FIRE))) {
            OnPlayerShoot(playerid, (pWeapon[playerid] = GetPlayerWeapon(playerid)));
            pAmmo[playerid] = GetPlayerAmmo(playerid);
        }
    } else {
        pShooting[playerid] = bool: (newkeys & KEY_FIRE);
    }
pawn Код:
//OnPlayerUpdate
    if(pShooting[playerid]) {
        new
            ammo = GetPlayerAmmo(playerid),
            weapon = GetPlayerWeapon(playerid);
        if(pWeapon[playerid] != weapon) {
            pWeapon[playerid] = weapon;
            pAmmo[playerid] = ammo;
        } else {
            if(pAmmo[playerid] != ammo) {
                OnPlayerShot(playerid, weapon);
                pAmmo[playerid] = ammo;
            }
        }
    }
Not tested, no time :S