SA-MP Forums Archive
Disable keys - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Disable keys (/showthread.php?tid=183332)



Disable keys - Buwla - 15.10.2010

Is it possible to disable keys like KEY_FIRE?
ex. to make a fighting free zone.


Re: Disable keys - Austin - 15.10.2010

Could apply an animation when they do that? Wouldn't stop them, doing it, but it will stop the fight.


Re: Disable keys - Toni - 15.10.2010

You could check the player's key under OnPlayerUpdate; then if they pressed it, return 0.

E.g
pawn Код:
OnPlayerUpdate(playerid)
{
if(PRESSED(KEY_FIRE)) return 0;
return 1;
}



Re: Disable keys - Austin - 15.10.2010

But if I'm not wrong The Toni, that means if the guys holds that key, he could use it to run away because nobody would see his location, no?


Re: Disable keys - Rachael - 15.10.2010

I would suggest creating a global boolean variable which is set to true if the player is in the area that you want to be 'fight free' ( because I don't like putting proximity checks in onplayerupdate )

pawn Код:
new bool:inzone[MAX_PLAYERS];
...
public OnPlayerUpdate(playerid)
{
     if(inzone[playerid])
     {
          SetPlayerArmedWeapon(playerid, 0);
     }
     return 1;
}
or, as Austin suggested, applying an animation when the player presses fire is worth testing too.


Re: Disable keys - Rac3r - 15.10.2010

OnPlayerKeyStateChange, check if the player presses KEY_FIRE, check if he's in range of the zone, if so TogglePlayerControllable(playerid, true), or as Rachael suggested SetPlayerArmedWeapon(playerid, 0).

Using OnPlayerUpdate, you can imagine how many times SetPlayerArmedWeapon(playerid, 0) would be called, way too much.


Re: Disable keys - CrucixTM - 15.10.2010

Quote:
Originally Posted by The Toni
Посмотреть сообщение
You could check the player's key under OnPlayerUpdate; then if they pressed it, return 0.

E.g
pawn Код:
OnPlayerUpdate(playerid)
{
if(PRESSED(KEY_FIRE)) return 0;
return 1;
}
Returning 0 on Keys does not stop them from triggering the action...