theus.py Posted September 30, 2023 Share Posted September 30, 2023 Can someone help me? I'm trying to create a script for the MTA that prevents the player from using CTRL and using the left mouse button, what can I do??? Link to comment
Shady1 Posted October 1, 2023 Share Posted October 1, 2023 3 hours ago, theus.py said: Can someone help me? I'm trying to create a script for the MTA that prevents the player from using CTRL and using the left mouse button, what can I do??? https://wiki.multitheftauto.com/wiki/GetKeyState and https://wiki.multitheftauto.com/wiki/CancelEvent Link to comment
alex17" Posted October 1, 2023 Share Posted October 1, 2023 addEventHandler("onClientKey", root, function(key) if key == "lctrl" or key == "mouse1" then cancelEvent() end end ) Link to comment
Hydra Posted October 1, 2023 Share Posted October 1, 2023 4 hours ago, alex17" said: addEventHandler("onClientKey", root, function(key) if key == "lctrl" or key == "mouse1" then cancelEvent() end end ) Shouldn't it be? if key == "lctrl" and key == "mouse1" then cancelEvent() end Link to comment
Shady1 Posted October 1, 2023 Share Posted October 1, 2023 48 minutes ago, Hydra said: Shouldn't it be? if key == "lctrl" and key == "mouse1" then cancelEvent() end that's true Link to comment
alex17" Posted October 1, 2023 Share Posted October 1, 2023 1 hour ago, Hydra said: Shouldn't it be? if key == "lctrl" and key == "mouse1" then cancelEvent() end When you press a key, it can be control or mouse 1, but it can never be both at the same time. Link to comment
Addlibs Posted October 1, 2023 Share Posted October 1, 2023 (edited) 1 hour ago, Hydra said: Shouldn't it be? if key == "lctrl" and key == "mouse1" then cancelEvent() end No. Since "lctrl" and "mouse1" are not equal to each other, If key is "lctrl" then by definition it cannot be "mouse1", therefore this conditional always evaluates false, and cancelEvent is never called. If you want to block either lctrl or mouse1, keep the logical connective as or. addEventHandler("onClientKey", root, function(key, pressState) if key == "lctrl" or key == "mouse1" then -- block the use of either key cancelEvent(true) end end ) If you want to block both from being used at the same time, you instead have to use an internal state to remember whether the other key is pressed. For example, have a variable (bool) remember whether lctrl is currently pressed or not, and when key == "mouse1" you can test local lctrlIsPressed = -- assigned at previous invocation of onClientKey addEventHandler("onClientKey", root, function(key, pressState) if key == "lctrl" then lctrlIsPressed = pressState -- remember the pressState of lctrl elseif key == "mouse1" and pressState and lctrlIsPressed == true then -- only if mouse1 was now pressed and lctrl is already pressed cancelEvent(true) end end ) Note the example above is only half correct; it prevents the detection of pressing mouse1 while lctrl is pressed, but not the opposite; if one clicks and holds mouse1 and only then presses lctrl, this will not be prevented from detection by the game. Edited October 1, 2023 by Addlibs 1 Link to comment
theus.py Posted October 3, 2023 Author Share Posted October 3, 2023 On 30/09/2023 at 20:46, theus.py said: Can someone help me? I'm trying to create a script for the MTA that prevents the player from using CTRL and using the left mouse button, what can I do??? NOTE: This is while the player is moving, if he is moving 'run' he will not be able to use CTRL and the left mouse button Just now, theus.py said: NOTE: This is while the player is moving, if he is moving 'run' he will not be able to use CTRL and the left mouse button On 30/09/2023 at 20:46, theus.py said: Link to comment
alex17" Posted October 3, 2023 Share Posted October 3, 2023 2 hours ago, theus.py said: NOTE: This is while the player is moving, if he is moving 'run' he will not be able to use CTRL and the left mouse button function checkisPlayerRunning(_, state) if state == "down" then addEventHandler("onClientKey", root, cancelControls) else removeEventHandler("onClientKey", root, cancelControls) end end bindKey("sprint", "up", checkisPlayerRunning) bindKey("sprint", "down", checkisPlayerRunning) function cancelControls(key, pressState) if key == "lctrl" or key == "mouse1" then -- block the use of either key cancelEvent(true) end end try this, maybe it will help I'm not too sure 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now