NPCs don't detect crouching players - 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: NPCs don't detect crouching players (
/showthread.php?tid=620570)
NPCs don't detect crouching players -
NealPeteros - 31.10.2016
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(playerid, newkeys, oldkeys)
{
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", 5000, false, "i", playerid);
}
}
else if(newkeys & KEY_SPRINT && GetVictimTimerStatus[playerid] == 0)
{
GetVictimDetectRange[playerid] = (ZOMBIE_DETECT * 2);
GetVictimTimerStatus[playerid] = 1;
GetVictimResetTimer[playerid] = SetTimerEx("ResetDetectRange", 5000, false, "i", playerid);
}
}
return 1;
}
Re: NPCs don't detect crouching players -
Threshold - 31.10.2016
PHP код:
if(GetPlayerSpecialAction(playerid) == SPECIAL_ACTION_DUCK) GetVictimDetectRange[playerid] = 0.0;
https://sampwiki.blast.hk/wiki/GetPlayerSpecialAction
Re: NPCs don't detect crouching players -
NealPeteros - 31.10.2016
In what callback should I add this? OnPlayerUpdate?
Re: NPCs don't detect crouching players -
Threshold - 31.10.2016
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.