NPCs don't detect crouching players
#1

So, I had an idea where NPCs don't detect crouching players. I just don't know how to add it. Here's the only info from my server that I can give.

PHP код:
#define ZOMBIE_DETECT 15
public OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(!
IsPlayerNPC(playerid))
    {
        if(
newkeys KEY_FIRE)
        {
            if(
GetPlayerWeapon(playerid) >= 22 && GetPlayerWeapon(playerid) <= 38)
            {
                
GetVictimDetectRange[playerid] = (ZOMBIE_DETECT 4);
                if(
GetVictimTimerStatus[playerid] == 1) { KillTimer(GetVictimResetTimer[playerid]); }
                
GetVictimTimerStatus[playerid] = 1;
                
GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange"5000false"i"playerid);
            }
        }
        else if(
newkeys KEY_SPRINT && GetVictimTimerStatus[playerid] == 0)
        {
            
GetVictimDetectRange[playerid] = (ZOMBIE_DETECT 2);
            
GetVictimTimerStatus[playerid] = 1;
            
GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange"5000false"i"playerid);
        }
    }
    return 
1;

Reply
#2

PHP код:
if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCKGetVictimDetectRange[playerid] = 0.0
https://sampwiki.blast.hk/wiki/GetPlayerSpecialAction
Reply
#3

In what callback should I add this? OnPlayerUpdate?
Reply
#4

Well you could technically use OnPlayerKeyStateChange as they have to press KEY_CROUCH to get in the crouched stance anyway, but GetPlayerSpecialAction may not return the expected result 100% of the time. A repeating timer would be good too, but would work just as well as OnPlayerUpdate.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)