Author Topic: How do I make function for keybinds?  (Read 1162 times)

Like if I wanted to make the player do something by the press of a key (Like do a 180), what do I do? Im trying to learn functions to make a useful addon.
Also, I would be extra helpful if you were to list some of the functions Ik theres a thread about functions, but still, please list some of the functions that control the player
« Last Edit: July 07, 2015, 09:21:46 AM by Bow »

Player::setYaw(%this, %yaw);
Player::setPitch(%this, %pitch);

Ex: %client.player.setYaw(%yaw);


I'd like to correct myself from before, I remembered it's not Player::setYaw or Player::setPitch that you're looking for, client-side it's just yaw(%yaw); and pitch(%pitch); . Not sure what I was thinking.
« Last Edit: July 07, 2015, 02:24:54 PM by Dannu »

Quote from: hedcreb zumbie
function Armor::onTrigger(%this,%player,%slot,%val)
{
   if(%slot == )
   {
      if(%val)
         //do stuff when button is pressed
      else
         //do stuff when button is let go off
      
   }
}

Quote from: portified
0: activate
1: use
2: jump
3: crouch
4: jet
(put the number after the == in if(%slot == ))

i think this is what you mean unless you're talking about other keys in which case you'll need a client sided addon too

The answer depends on what key you want to detect and whether your why to do it clientside or serverside

Server side you can't truly "detect keys pressed," that's the client's job, but you can modify the functions triggered by them: the method posted above for fire, jet, jump, and crouch; anything else the related serverCmd (serverCmdLight for light)

Clientside, what you should do is add the option as a binding in the controls menu so players can bind whether they want to it. Someone else will need to post a reference on how to do that, or you can find an add-on that does (something that adds a GUI would be a good place to look) as I don't feel like digging through stuff on phone

For a reference to setting keybinds client-side, see Client_SniperOverlay.

I want it to be like this: If if press the keybinded key, it activates the key and stays activated untill the keybinded key is pressed.

For that the perfect reference would be Script_RapidFire. It's what I used for my first project with keybinds.


I can't check out the file since I'm on my phone but try to execute it with exec(%path); in console to check if there are any syntax errors, if not try restarting and if nothing else helps, make sure everything has its own unique name such as keybind menu category, variables, functions, etc. If no one beats me to it, I'll be able to check it out myself soon since I'm on my way home.

I can't check out the file since I'm on my phone but try to execute it with exec(%path); in console to check if there are any syntax errors, if not try restarting and if nothing else helps, make sure everything has its own unique name such as keybind menu category, variables, functions, etc. If no one beats me to it, I'll be able to check it out myself soon since I'm on my way home.
Code: [Select]
$remapDivision[$remapCount] = "Crouch Holder";
$remapName[$remapCount] = "Press to use";
$remapCmd[$remapCount] = "toggleSpam";
$remapCount++;
function toggleSpam(%this,%player,%slot,%value,)
{
if(%slot == 3)
{
if(%value)

else



}
}

toggleSpam will only be called with one argument, you can get rid of the last 3(4? that comma is misleading)

try
Code: [Select]
$ToggleCrouching = 0;
function toggleSpam(%value)
{
   if(!%value)
   {
      crouch($ToggleCrouching = !$ToggleCrouching);
   }
}
mostly ripped from my first addon which was editing that
%value will be true when held down, false when let go
not sure how to detect if you're crouching, so it just uses a variable to do that

you'll still need the same keybind code

Well the problem with your code is the syntax errors. You can't leave if and else statements blank like that. It just didn't execute.

I'd like to correct myself from before, I remembered it's not Player::setYaw or Player::setPitch that you're looking for, client-side it's just yaw(%yaw); and pitch(%pitch); . Not sure what I was thinking.

This function (still clientside) adds a keybind to an existing 'division' instead of having to make a new one. Excerpt from 'Auto Wrench', original by Randy.
Code: [Select]
function AddBind(%division, %name, %command)
{
for(%i=0;%i<$remapCount;%i++)
{
if($remapDivision[%i] $= %division)
{
%foundDiv = 1;
continue;
}
if(%foundDiv && $remapDivision[%i] !$= "")
{
%position = %i;
break;
}
}
if(!%foundDiv)
{
error("Division not found: " @ %division);
return;
}
if(!%position)
{
$remapName[$remapCount] = %name;
$remapCmd[$remapCount] = %command;
$remapCount++;
return;
}
for(%i=$remapCount;%i>%position;%i--)
{
$remapDivision[%i] = $remapDivision[%i - 1];
$remapName[%i] = $remapName[%i - 1];
$remapCmd[%i] = $remapCmd[%i - 1];
}
$remapDivision[%position] = "";
$remapName[%position] = %name;
$remapCmd[%position] = %command;
$remapCount++;
}
if(!$addedAutoWrenchBinds)
{
AddBind("Recording","Toggle Automatic Wrench","toggleAutoWrench");
$addedAutoWrenchBinds = true;
}