SA-MP Forums Archive
How to check if player is crouching? - 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: How to check if player is crouching? (/showthread.php?tid=512840)



How to check if player is crouching? - Mavis100 - 13.05.2014

I need it and make it fully of my weapon pick system


Re: How to check if player is crouching? - Dignity - 13.05.2014

Something like this;

pawn Код:
new bool: crouching[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_CROUCH)
    {
        crouching[playerid] = true;
    }

    if(newkeys & KEY_SPRINT) || (newkeys & KEY_CROUCH) && (newkeys & KEY_FIRE))
    {
        if(crouching[playerid])
        {
            crouching[playerid] = false;
        }
    }

    return 1;
}
If anyone else knows a more efficient way, please reply.


Re: How to check if player is crouching? - ChuckyBabe - 13.05.2014

Do you want a filterscript if player is using c-bug they will be kick ? here

pawn Код:
#include <a_samp>

#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTRED 0xFF6347AA

#undef MAX_PLAYERS
#define MAX_PLAYERS 30 // Change to you're servers max player count.

#define MAX_SLOTS 100

new NotMoving[MAX_PLAYERS];
new WeaponID[MAX_PLAYERS];
new CheckCrouch[MAX_PLAYERS];
new Ammo[MAX_PLAYERS][MAX_SLOTS];

new aWeaponNames[][32] = {
    {"Fist"}, // 0
    {"Brass Knuckles"}, // 1
    {"Golf Club"}, // 2
    {"Night Stick"}, // 3
    {"Knife"}, // 4
    {"Baseball Bat"}, // 5
    {"Shovel"}, // 6
    {"Pool Cue"}, // 7
    {"Katana"}, // 8
    {"Chainsaw"}, // 9
    {"Purple Dildo"}, // 10
    {"Vibrator"}, // 11
    {"Vibrator"}, // 12
    {"Vibrator"}, // 13
    {"Flowers"}, // 14
    {"Cane"}, // 15
    {"Grenade"}, // 16
    {"Teargas"}, // 17
    {"Molotov"}, // 18
    {" "}, // 19
    {" "}, // 20
    {" "}, // 21
    {"Colt 45"}, // 22
    {"Silenced Pistol"}, // 23
    {"Deagle"}, // 24
    {"Shotgun"}, // 25
    {"Sawns"}, // 26
    {"Spas"}, // 27
    {"Uzi"}, // 28
    {"MP5"}, // 29
    {"AK47"}, // 30
    {"M4"}, // 31
    {"Tec9"}, // 32
    {"Country Rifle"}, // 33
    {"Sniper Rifle"}, // 34
    {"Rocket Launcher"}, // 35
    {"Heat-Seeking Rocket Launcher"}, // 36
    {"Flamethrower"}, // 37
    {"Minigun"}, // 38
    {"Satchel Charge"}, // 39
    {"Detonator"}, // 40
    {"Spray Can"}, // 41
    {"Fire Extinguisher"}, // 42
    {"Camera"}, // 43
    {"Night Vision Goggles"}, // 44
    {"Infrared Vision Goggles"}, // 45
    {"Parachute"}, // 46
    {"Fake Pistol"} // 47
};

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Simple & Accurate Anti-C-Bug by Whitetiger.");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_FIRE) && (oldkeys & KEY_CROUCH) && !((oldkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) || (oldkeys & KEY_FIRE) && (newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ) {
        switch(GetPlayerWeapon(playerid)) {
            case 23..25, 27, 29..34, 41: {
                if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                    OnPlayerCBug(playerid);
                }
                return 1;
            }
        }
    }

    if(CheckCrouch[playerid] == 1) {
        switch(WeaponID[playerid]) {
            case 23..25, 27, 29..34, 41: {
                if((newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK ) {
                    if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                        OnPlayerCBug(playerid);
                    }
                }
            }
        }
    }

    //if(newkeys & KEY_CROUCH || (oldkeys & KEY_CROUCH)) return 1;

    else if(((newkeys & KEY_FIRE) && (newkeys & KEY_HANDBRAKE) && !((newkeys & KEY_SPRINT) || (newkeys & KEY_JUMP))) ||
    (newkeys & KEY_FIRE) && !((newkeys & KEY_SPRINT) || (newkeys & KEY_JUMP)) ||
    (NotMoving[playerid] && (newkeys & KEY_FIRE) && (newkeys & KEY_HANDBRAKE)) ||
    (NotMoving[playerid] && (newkeys & KEY_FIRE)) ||
    (newkeys & KEY_FIRE) && (oldkeys & KEY_CROUCH) && !((oldkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ||
    (oldkeys & KEY_FIRE) && (newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ) {
        SetTimerEx("CrouchCheck", 3000, 0, "d", playerid);
        CheckCrouch[playerid] = 1;
        WeaponID[playerid] = GetPlayerWeapon(playerid);
        Ammo[playerid][GetPlayerWeapon(playerid)] = GetPlayerAmmo(playerid);
        return 1;
    }

    return 1;
}

public OnPlayerUpdate(playerid)
{
    new Keys, ud, lr;
    GetPlayerKeys(playerid, Keys, ud, lr);
    if(CheckCrouch[playerid] == 1) {
        switch(WeaponID[playerid]) {
            case 23..25, 27, 29..34, 41: {
                if((Keys & KEY_CROUCH) && !((Keys & KEY_FIRE) || (Keys & KEY_HANDBRAKE)) && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK ) {
                    if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                        OnPlayerCBug(playerid);
                    }
                }
                //else SendClientMessage(playerid, COLOR_RED, "Failed in onplayer update");
            }
        }
    }

    if(!ud && !lr) { NotMoving[playerid] = 1; /*OnPlayerKeyStateChange(playerid, Keys, 0);*/ }
    else { NotMoving[playerid] = 0; /*OnPlayerKeyStateChange(playerid, Keys, 0);*/ }

    return 1;
}

forward OnPlayerCBug(playerid);
public OnPlayerCBug(playerid) {
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    new str2[128];
    format(str2, sizeof(str2), "AdmCmd: Server has kicked %s for Crouch bugging with weapon (%s!)", playername, aWeaponNames[WeaponID[playerid]]);
    SendClientMessageToAll(COLOR_LIGHTRED, str2);
    CheckCrouch[playerid] = 0;
    Kick(playerid);
    return 1;
}
forward CrouchCheck(playerid);
public CrouchCheck(playerid) {
    CheckCrouch[playerid] = 0;
    return 1;
}
//CREDITS TO WHITETIGER

+rep if i help you


Re: How to check if player is crouching? - Mavis100 - 13.05.2014

Quote:
Originally Posted by ChuckyBabe
Посмотреть сообщение
Do you want a filterscript if player is using c-bug they will be kick ? here

pawn Код:
#include <a_samp>

#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTRED 0xFF6347AA

#undef MAX_PLAYERS
#define MAX_PLAYERS 30 // Change to you're servers max player count.

#define MAX_SLOTS 100

new NotMoving[MAX_PLAYERS];
new WeaponID[MAX_PLAYERS];
new CheckCrouch[MAX_PLAYERS];
new Ammo[MAX_PLAYERS][MAX_SLOTS];

new aWeaponNames[][32] = {
    {"Fist"}, // 0
    {"Brass Knuckles"}, // 1
    {"Golf Club"}, // 2
    {"Night Stick"}, // 3
    {"Knife"}, // 4
    {"Baseball Bat"}, // 5
    {"Shovel"}, // 6
    {"Pool Cue"}, // 7
    {"Katana"}, // 8
    {"Chainsaw"}, // 9
    {"Purple Dildo"}, // 10
    {"Vibrator"}, // 11
    {"Vibrator"}, // 12
    {"Vibrator"}, // 13
    {"Flowers"}, // 14
    {"Cane"}, // 15
    {"Grenade"}, // 16
    {"Teargas"}, // 17
    {"Molotov"}, // 18
    {" "}, // 19
    {" "}, // 20
    {" "}, // 21
    {"Colt 45"}, // 22
    {"Silenced Pistol"}, // 23
    {"Deagle"}, // 24
    {"Shotgun"}, // 25
    {"Sawns"}, // 26
    {"Spas"}, // 27
    {"Uzi"}, // 28
    {"MP5"}, // 29
    {"AK47"}, // 30
    {"M4"}, // 31
    {"Tec9"}, // 32
    {"Country Rifle"}, // 33
    {"Sniper Rifle"}, // 34
    {"Rocket Launcher"}, // 35
    {"Heat-Seeking Rocket Launcher"}, // 36
    {"Flamethrower"}, // 37
    {"Minigun"}, // 38
    {"Satchel Charge"}, // 39
    {"Detonator"}, // 40
    {"Spray Can"}, // 41
    {"Fire Extinguisher"}, // 42
    {"Camera"}, // 43
    {"Night Vision Goggles"}, // 44
    {"Infrared Vision Goggles"}, // 45
    {"Parachute"}, // 46
    {"Fake Pistol"} // 47
};

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Simple & Accurate Anti-C-Bug by Whitetiger.");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if((newkeys & KEY_FIRE) && (oldkeys & KEY_CROUCH) && !((oldkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) || (oldkeys & KEY_FIRE) && (newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ) {
        switch(GetPlayerWeapon(playerid)) {
            case 23..25, 27, 29..34, 41: {
                if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                    OnPlayerCBug(playerid);
                }
                return 1;
            }
        }
    }

    if(CheckCrouch[playerid] == 1) {
        switch(WeaponID[playerid]) {
            case 23..25, 27, 29..34, 41: {
                if((newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK ) {
                    if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                        OnPlayerCBug(playerid);
                    }
                }
            }
        }
    }

    //if(newkeys & KEY_CROUCH || (oldkeys & KEY_CROUCH)) return 1;

    else if(((newkeys & KEY_FIRE) && (newkeys & KEY_HANDBRAKE) && !((newkeys & KEY_SPRINT) || (newkeys & KEY_JUMP))) ||
    (newkeys & KEY_FIRE) && !((newkeys & KEY_SPRINT) || (newkeys & KEY_JUMP)) ||
    (NotMoving[playerid] && (newkeys & KEY_FIRE) && (newkeys & KEY_HANDBRAKE)) ||
    (NotMoving[playerid] && (newkeys & KEY_FIRE)) ||
    (newkeys & KEY_FIRE) && (oldkeys & KEY_CROUCH) && !((oldkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ||
    (oldkeys & KEY_FIRE) && (newkeys & KEY_CROUCH) && !((newkeys & KEY_FIRE) || (newkeys & KEY_HANDBRAKE)) ) {
        SetTimerEx("CrouchCheck", 3000, 0, "d", playerid);
        CheckCrouch[playerid] = 1;
        WeaponID[playerid] = GetPlayerWeapon(playerid);
        Ammo[playerid][GetPlayerWeapon(playerid)] = GetPlayerAmmo(playerid);
        return 1;
    }

    return 1;
}

public OnPlayerUpdate(playerid)
{
    new Keys, ud, lr;
    GetPlayerKeys(playerid, Keys, ud, lr);
    if(CheckCrouch[playerid] == 1) {
        switch(WeaponID[playerid]) {
            case 23..25, 27, 29..34, 41: {
                if((Keys & KEY_CROUCH) && !((Keys & KEY_FIRE) || (Keys & KEY_HANDBRAKE)) && GetPlayerSpecialAction(playerid) != SPECIAL_ACTION_DUCK ) {
                    if(Ammo[playerid][GetPlayerWeapon(playerid)] > GetPlayerAmmo(playerid)) {
                        OnPlayerCBug(playerid);
                    }
                }
                //else SendClientMessage(playerid, COLOR_RED, "Failed in onplayer update");
            }
        }
    }

    if(!ud && !lr) { NotMoving[playerid] = 1; /*OnPlayerKeyStateChange(playerid, Keys, 0);*/ }
    else { NotMoving[playerid] = 0; /*OnPlayerKeyStateChange(playerid, Keys, 0);*/ }

    return 1;
}

forward OnPlayerCBug(playerid);
public OnPlayerCBug(playerid) {
    new playername[MAX_PLAYER_NAME];
    GetPlayerName(playerid, playername, sizeof(playername));
    new str2[128];
    format(str2, sizeof(str2), "AdmCmd: Server has kicked %s for Crouch bugging with weapon (%s!)", playername, aWeaponNames[WeaponID[playerid]]);
    SendClientMessageToAll(COLOR_LIGHTRED, str2);
    CheckCrouch[playerid] = 0;
    Kick(playerid);
    return 1;
}
forward CrouchCheck(playerid);
public CrouchCheck(playerid) {
    CheckCrouch[playerid] = 0;
    return 1;
}
//CREDITS TO WHITETIGER

+rep if i help you
Hi, guy, thank you for response, I want to check it on OnPlayerCommand Can i get player's animation? but i don't know that vaule of crouch


Re: How to check if player is crouching? - Corekt - 13.05.2014

pawn Код:
if (GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK) {
    // Currently crouching
}
https://sampwiki.blast.hk/wiki/SpecialActions