Limit for pressing "J" button ?

Started by Nihongo^, Aug 29, 2023, 08:43 PM

Previous topic - Next topic

Nihongo^

Hi how do i make limit for pressing "J" button ?

like player can Press only 5 or 4 times for jump or boost


function onKeyDown( player, oldKeys, newKeys )
{
  if( key == J )
    {
      if( player.Vehicle )
      {
        local vPos   = player.Vehicle.Pos;
        vPos.z = vPos.z * 1.5;
      }
    return;
    }
  }

Mohamed Boubekri

#1
Hey @Nihongo^, you can specify an array or a status, which will vary depending on the number of presses.
Here is an example: (untested)
J <- BindKey(true, 0x4A, 0, 0);
class TESTO
{
    press = 1;
}
function onScriptLoad()
{
status <- array ( GetMaxPlayers(), null );
}
function onPlayerJoin( player )
{
status[player.ID] = TESTO();
}
function onKeyDown( player, key )
{
if( key == J ) // jump or boost key
{
if ( status[player.ID].press < 5 )
{
if (!player.Vehicle) return;
status[ player.ID ].press += 1;
local vPos  = player.Vehicle.Pos;
vPos.z = vPos.z * 1.5;
}
else
{
MessagePlayer("You can't use jump button above 4 times, please wait 5 seconds !",player); //after 5 seconds, player will be able to use that key again
gta <- NewTimer("reset",5000,1,player.ID);
}
}
return;
}
function reset(p)
{
p = FindPlayer(p);
status[p.ID].press = 1;
gta.Stop();
gta.Delete();
}
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Hammam

#2
Paste this on your class PlayerClass
=================================================================
class PlayerClass
{
Jlimit = 0;
}
// PASTE THIS ON FUNCTIONS.NUT (IF YOU HAVE) OR SOMEWHERE ELSE IN MAIN.NUT
function Jreset(player)
{
stats[player.ID].Jlimit = 0;
MessagePlayer("[#00FF00]You're now able to use [ [#FF0000]J [#00FF00] ] button!", player);
Announce("You can use J button now!", player, 1);
}
function onKeyDown( player, oldKeys, newKeys )
{
  if( key == J )
    {
      if (stats[player.ID].Jlimit == 3)
       {
        MessagePlayer("[#820000]You're unable to use [#820000][ [#FF0000]J [#820000]] button. Please wait for [#00FF00]5 [#820000]seconds in-order to re-use this key!", player);
return 0;
NewTimer("Jreset", 5000, 1, player.ID);
}
      if( player.Vehicle )
      {
        local vPos   = player.Vehicle.Pos;
        vPos.z = vPos.z * 1.5;
        stats[player.ID].Jlimit += 1;
      }
    return;
    }
  }