Jump to content

bindKey Problem


bogdyutzu

Recommended Posts

Hello, I have a problem with bindKey. I've tried to bind a player (client-side) when enter in colshape (also client-side) and unbind the player when he leave the colshape. But the problem is bindKey because is bind all players.

This is the code:

  
function onClientColShapeHit(element)   
    if element == localPlayer then bindKey("mouse2", "up", onClientExitProp, getElementData(source, "pickup")) end   
end   
   
function onClientColShapeLeave(element)   
    if element == localPlayer then unbindKey("mouse2", "up") end   
end 

Link to comment
function onClientColShapeHit(element)   
    if element == localPlayer then bindKey(source, "mouse2", "up", onClientExitProp, getElementData(source, "pickup")) end   
end   
  
function onClientColShapeLeave(element)   
    if element == localPlayer then unbindKey(source, "mouse2", "up") end   
end 

Link to comment

try this ..

function onClientColShapeHit()   
     bindKey(localPlayer, "mouse2", "up" )  
end  
addEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeHit) 
  
function onClientColShapeLeave()   
     unbindKey(localPlayer, "mouse2", "up")  
end 
addEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave) 

Link to comment

try this ..
function onClientColShapeHit()  
     bindKey(localPlayer, "mouse2", "up" )
end
addEventHandler("onClientColShapeHit",getRootElement(),onClientColShapeHit)
 
function onClientColShapeLeave()  
     unbindKey(localPlayer, "mouse2", "up")
end
addEventHandler("onClientColShapeLeave",getRootElement(),onClientColShapeLeave)

this does not make any sense

in clinent side

player element not Required

Required Arguments

should be

bindKey (key,  keyState, function)
 

more info :

  
[url=https://wiki.multitheftauto.com/wiki/BindKey]https://wiki.multitheftauto.com/wiki/BindKey[/url] 
[url=https://wiki.multitheftauto.com/wiki/UnBindKey]https://wiki.multitheftauto.com/wiki/UnBindKey[/url] 

Link to comment
He should check though, if the hit element is the local player, else, it'll bind the key when a remote player hits it.

Is this true?

function ShowGui() 
    guiSetVisible(GUIEditor_Window[1],not guiGetVisible(GUIEditor_Window[1])) 
    showCursor(guiGetVisible(GUIEditor_Window[1])) 
    guiSetInputEnabled(guiGetVisible(GUIEditor_Window[1])) 
end 
bindKey("F1","down",ShowGui) 

  
  
ColShape = createColRectangle (x, y, Width, Height ) -- Create ColShape 
  
addEventHandler( "onClientColShapeHit", ColShape, -- Event On Hit 
    function ( thePlayer ) 
        if ( thePlayer == localPlayer ) then -- Check LocalPlayer 
             unbindKey (  "F1", "down", ShowGui ) -- UnbindKey 
  
        end 
    end 
) 
  
addEventHandler( "onClientColShapeLeave", ColShape,-- OnLeave 
    function ( thePlayer ) 
        if ( thePlayer == localPlayer ) then -- LocalPlayer 
            bindKey (  "F1", "down", ShowGui ) --BindTheKey 
        end 
    end 
) 
  
  

Link to comment

you all are wrong complete wrong...

Red dod Is the wrong probleme

only player 1 must be bind if he enter is hes con 1

so probleme is when you bind a player he bind all the player on server... strange think is because is work from client script to althor player one...

wrong

6dCHNXOYBxOCQNSEs9RBNUHHpI8QH.jpg

good

6dCIy7KSW1CwWP4CVSyEwXZ7GV9Ib.jpg

the player 1 don't have to bind player 2

to explain the real probleme

function onClientPickupHit() 
    bindKey("mouse2", "up", onClientEnterProp, source) 
end 
  
function onClientPickupLeave() 
    unbindKey("mouse2", "up") 
end 
  
addEventHandler("onClientElementStreamIn", g_Root, function() 
  
    if getElementData(source, "owner") then  
         
        table.insert(g_streamedProps, source) 
          
        -- Hook when player hit the enter-pickup and bind him 
        addEventHandler("onClientPickupHit", source, onClientPickupHit) 
         
        -- Hook when player leave the enter-pickup and unbind him (pickups use shapes, so we can hook leave event) 
        addEventHandler("onClientPickupLeave", source, onClientPickupLeave) 
   end 
end 

Is only happen is sourceElement is create on server side

Edited by Guest
Link to comment
you all are wrong complete wrong...

Red dod Is the wrong probleme

only player 1 must be bind if he enter is hes con 1

so probleme is when you bind a player he bind all the player on server... strange think is because is work from client script to althor player one...

wrong

6dCHNXOYBxOCQNSEs9RBNUHHpI8QH.jpg

good

6dCIy7KSW1CwWP4CVSyEwXZ7GV9Ib.jpg

the player 1 don't have to bind player 2

With Mr.Pres[T]ege's script it'll only bind the key to the one who hit it.

Link to comment

I explain the reason of his probleme

...

to explain the real probleme

function onClientPickupHit() 
    bindKey("mouse2", "up", onClientEnterProp, source) 
end 
  
function onClientPickupLeave() 
    unbindKey("mouse2", "up") 
end 
  
addEventHandler("onClientElementStreamIn", g_Root, function() 
  
    if getElementData(source, "owner") then  
         
        table.insert(g_streamedProps, source) 
          
        -- Hook when player hit the enter-pickup and bind him 
        addEventHandler("onClientPickupHit", source, onClientPickupHit) 
         
        -- Hook when player leave the enter-pickup and unbind him (pickups use shapes, so we can hook leave event) 
        addEventHandler("onClientPickupLeave", source, onClientPickupLeave) 
   end 
end 

Is only happen is sourceElement is create on server side

ps: bindKey should have a playerSource on clientside like server one

Link to comment

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...