Jump to content

Unbind key


KariiiM

Recommended Posts

Hey guys,

i face a small problem in same time a big one, i tried to make a resource for camera system,i want to release it to the community since there's no resource like that,

Everything scripted fine,but i got a problem in unbinding a key, the key of returning with setCameraTarget.

So, when the player press "accept" the function "bind" will be binded, untill now everything is fine , but when the Camera Points shows, after pressing the key "X", it doesn't be unbinded, so here's the problem.

~Regards.

--Part of my code: (this problem is on Client side,server side is fine)

addEventHandler ("onClientGUIClick", root, 
function () 
        if (source == cancel) then 
        guiSetVisible(window,false) 
        showCursor(false) 
        unbindKey("X", "down", bind) 
         elseif (source == accept) then 
   local row,col = guiGridListGetSelectedItem(camGrid) 
      if row and col and row ~= -1 and col ~= -1 then 
      guiSetVisible(window,false) 
      showCursor(true) 
      outputChatBox ("Camera: Press X to stop the camera.",0,255,0) 
      local x = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),3) 
      local y = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),4) 
      local z = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),5) 
      local cx = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),6) 
      local cy = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),7) 
      local cz = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),8) 
      triggerServerEvent("Camera:watch",localPlayer,guiGridListGetSelectedItem(camGrid)+1) 
      bindKey("X", "down", bind) 
      else  
     outputChatBox ("Camera System: You didn't selecte the item.",0,180,23)        
      end 
   end 
end) 
  
function bind(key) 
        if key == "X" then  
        setCameraTarget(localPlayer)  
        showChat(true) 
   end 
end 

Edited by Guest
Link to comment
  • Moderators

Maybe you can try something cleaner like this:

addEventHandler ("onClientGUIClick", root, 
function () 
    if (source == cancel) then 
        exitCamera() 
    elseif (source == accept) then 
        local row,col = guiGridListGetSelectedItem(camGrid) 
        if row and col and row ~= -1 and col ~= -1 then 
            guiSetVisible(window,false) 
            showCursor(true) 
            outputChatBox ("Camera: Press X to stop the camera.",0,255,0) 
            local x = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),3) 
            local y = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),4) 
            local z = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),5) 
            local cx = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),6) 
            local cy = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),7) 
            local cz = guiGridListGetItemText (camGrid, guiGridListGetSelectedItem (camGrid),8) 
            triggerServerEvent("Camera:watch",localPlayer,guiGridListGetSelectedItem(camGrid)+1) 
            bindKey("X", "down", exitCamera) 
        else 
            outputChatBox ("Camera System: You didn't select the item.",0,180,23)       
        end 
   end 
end) 
  
function exitCamera() 
    guiSetVisible(window, false) 
    showCursor(false) 
    unbindKey("X", "down", exitCamera) 
    setCameraTarget(localPlayer) 
    showChat(true) 
end 

Yyou were doing the unbindKey call only if the user clicked on the cancel button, but not when you pressed the "X" key

See if it works like this.

Link to comment
  • Moderators

Are you using the setElementPosition function for the player ?

If so, make sure you do not set the Z position too low.

If you are sure it's not the problem, then it might be a streaming issue (objects that are far from the camera are "streamed out" for better performance, so the buildings, ground etc, are kinda unloaded) just freeze the player for 1 or 2 seconds to let the game enough time to reload the unloaded objects and then unfreeze him.

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