Jump to content

cancel bind


#RooTs

Recommended Posts

Posted

is there any way for me to cancel the "w" and "space" for me I get to create a stamina system.

I want to cancel so I can not run. ( "w" and "space" )

Posted
unbindKey 

As far as I know, cancelEvent is used for events not for functions and "bindKey" is a function not an event

I will cancel the bind of an event that I do not know what it is?

Posted

I think. I did not express myself right.

when I press w + space. it runs faster. I want to cancel it and after a while activate again

Posted

Try this,

addEventHandler("onClientKey", root,  
function ( key, press ) 
    if (key == "w") then  
        if (getKeyState("space")) then 
            cancelEvent() 
        end 
    end 
end) 

Posted
Try this,
addEventHandler("onClientKey", root,  
function ( key, press ) 
    if (key == "w") then  
        if (getKeyState("space")) then 
            cancelEvent() 
        end 
    end 
end) 

server or clientSide ?

Posted

@KariiiM, nothing happens. :lol::lol::lol:

addEventHandler("onClientKey", root, 
function ( key, press ) 
    if (key == "w") then 
        if (getKeyState("space")) then 
        cancelEvent() 
        outputChatBox ( "test" ) 
        end 
    end 
end) 

Posted
client side:
bindKey( "w", "down", "cancel", 
function () 
    if (getKeyState("space") == true) then 
        cancelEvent () 
    end 
end) 

It is not possible to cancel bindKey function, only via event.

Posted
Rly men, just do like you did toggleControl it will work...

my attempt was this. but it did not work

function test(thePlayer, command) 
toggleControl("sprint", false) 
outputChatBox ( "test1" ) 
end 
  
addCommandHandler ( "test", test ) 

Posted

Try this @Root:

addEventHandler ( "onClientKey", getRootElement(), 
function (button, press) 
    if (button == "w") then 
        setElementData (getLocalPlayer(), "w", press) 
    else  
        return false 
    end 
    if (button == "space" and press) then 
        if (getElementData (getLocalPlayer(), "w")) then 
            cancelEvent() --cancel the event 
        end 
    end 
end) 

Posted

@KariiiM, not work.

maybe with??:

toggleControl("sprint", false) 

addEventHandler ( "onClientKey", getRootElement(), 
function (button, press) 
    if (button == "w") then 
        setElementData (getLocalPlayer(), "w", press) 
    else 
        return false 
    end 
    if (button == "space" and press) then 
        if (getElementData (getLocalPlayer(), "w")) then 
            toggleControl("sprint", false) 
        end 
    end 
end) 

but it also did not work :cry::cry:

Posted
addEventHandler("onClientKey", getRootElement(), function(button, press) 
    if(button == "space") then 
        local keyState = getKeyState("w") 
        if(keyState) then 
            cancelEvent() 
        end 
    end 
end) 

Posted

@Hornet. worked, thx.

I can now improve. and create a stamina system. thanks!

You want to join me to complete the system?

Posted
Rly men, just do like you did toggleControl it will work...

my attempt was this. but it did not work

function test(thePlayer, command) 
toggleControl("sprint", false) 
outputChatBox ( "test1" ) 
end 
  
addCommandHandler ( "test", test ) 

sprint is running, it will only stop running, but if u want to stop walk u can use theese.

  
toggleControl("forwards", false) 
toggleControl("backwards", false) 
toggleControl("left", false) 
toggleControl("right", false) 
  

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...