Jump to content

Bindkey problem...


Recommended Posts

Hey whats wrong on this code i have a error?

server.lua:153: Bad argument @ 'bindKey' [Expected player at argument 1, got string 'arrow_r']

Server-Side

bindKey("arrow_r", "down",  
    function () 
        if lookDMSelection( source ) then 
        lookDDSelection( source ) 
            elseif lookDDSelection( source ) then 
            lookDMSelection( source ) 
    end 
end ) 

Link to comment

Whats wrong with this code?

Server-Side

function lookDMSelection( source ) 
setCameraMatrix(source, 2296.2890625, -1395.0576171875, 694.02215576172, 2308.0771484375, -1410.1640625, 688.58026123047) 
end 
  
  
function lookDDSelection( source ) 
setCameraMatrix(source, 2262.130859375, -1402.4462890625, 699.66162109375, 2271.5087890625, -1421.4033203125, 691.99346923828) 
end 
  
function lookHTSelection( source ) 
setCameraMatrix(source, 2248.107421875, -1400.54296875, 695.64147949219, 2232.736328125, -1411.4306640625, 696.97576904297) 
end 
  
bindKey(source, "arrow_r", "down", 
function() 
if lookDMSelection() then 
    lookDDSelection() 
elseif lookDDSelection() then 
    lookHTSelection() 
elseif lookHTSelection() then 
    lookDMSelection() 
    end 
end 
) 

Link to comment

client

cam = 0 
  
function lookDMSelection( source ) 
setCameraMatrix(source, 2296.2890625, -1395.0576171875, 694.02215576172, 2308.0771484375, -1410.1640625, 688.58026123047) 
end 
  
  
function lookDDSelection( source ) 
setCameraMatrix(source, 2262.130859375, -1402.4462890625, 699.66162109375, 2271.5087890625, -1421.4033203125, 691.99346923828) 
end 
  
function lookHTSelection( source ) 
setCameraMatrix(source, 2248.107421875, -1400.54296875, 695.64147949219, 2232.736328125, -1411.4306640625, 696.97576904297) 
end 
  
bindKey( "arrow_r", "down",function(source) 
if cam == 0 then 
    lookDDSelection(source) 
    cam = cam+1 
elseif cam == 1 then 
    lookHTSelection(source) 
    cam = cam+1 
elseif cam == 2 then 
    lookDMSelection(source) 
    cam = 0 
    end 
end) 
  

?

Edited by Guest
Link to comment
  • Moderators

Here is an example of what you could do:

Becarefull ! It's a client-side script !

client-side:

local camerasSelection = { 
    {2296.2890625, -1395.05761718, 694.02215576172, 2308.077148437, -1410.1640625, 688.58026123047}, -- DM 
    {2262.1308593, -1402.44628906, 699.66162109375, 2271.508789062, -1421.4033203, 691.99346923828}, -- DD 
    {2248.1074218, -1400.54296875, 695.64147949219, 2232.736328125, -1411.4306640, 696.97576904297}  -- HT 
} 
local currentSelection = 1 -- means it will be DM by default 
  
function updateCameraSelection() 
    local c, i = camerasSelection, currentSelection -- making temp aliases so it's shorter 
    local x, y, z = c[i][1], c[i][2], c[i][3] 
    local tx, ty , tz = c[i][4], c[i][5], c[i][6] 
    setCameraMatrix( x, y, z, tx, ty, tz ) 
end 
  
function nextSelection() 
    currentSelection = currentSelection + 1 
    if currentSelection > #camerasSelection then currentSelection = 1 end 
    updateCameraSelection() 
end 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    bindKey("arrow_r", "down", nextSelection) -- bind when just joined the server 
    updateCameraSelection() 
end) 
  
addEventHandler("onClientPlayerSpawn", localPlayer, function() 
    if getKeyBoundToFunction(nextSelection) ~= "arrow_r" then return end -- prevent unbinding if already unbound 
    unbindKey("arrow_r", "down", nextSelection) -- unbind when spawned 
end) 

I have tested it and it works ! So make sure you copy-paste correctly (and in the right file).

Regards,

Citizen

Link to comment
  • Moderators

Yeah exactly:

local camerasSelection = { 
    {2296.2890625, -1395.05761718, 694.02215576172, 2308.077148437, -1410.1640625, 688.58026123047}, -- DM 
    {2262.1308593, -1402.44628906, 699.66162109375, 2271.508789062, -1421.4033203, 691.99346923828}, -- DD 
    {2248.1074218, -1400.54296875, 695.64147949219, 2232.736328125, -1411.4306640, 696.97576904297}  -- HT 
} 
local currentSelection = 1 -- means it will be DM by default 
  
function updateCameraSelection() 
    local c, i = camerasSelection, currentSelection -- making temp aliases so it's shorter 
    local x, y, z = c[i][1], c[i][2], c[i][3] 
    local tx, ty , tz = c[i][4], c[i][5], c[i][6] 
    setCameraMatrix( x, y, z, tx, ty, tz ) 
end 
  
function nextSelection() 
    currentSelection = currentSelection + 1 
    if currentSelection > #camerasSelection then currentSelection = 1 end 
    updateCameraSelection() 
end 
  
function prevSelection() 
    currentSelection = currentSelection - 1 
    if currentSelection < 1 then currentSelection = #camerasSelection end 
    updateCameraSelection() 
end 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    bindKey("arrow_l", "down", prevSelection) -- bind when just joined the server 
    bindKey("arrow_r", "down", nextSelection) -- bind when just joined the server 
    updateCameraSelection() 
end) 
  
addEventHandler("onClientPlayerSpawn", localPlayer, function() 
    if getKeyBoundToFunction(nextSelection) ~= "arrow_r" then return end -- prevent unbinding if already unbound 
    unbindKey("arrow_l", "down", prevSelection) -- unbound when spawning 
    unbindKey("arrow_r", "down", nextSelection) -- unbound when spawning 
end) 

Link to comment
Yeah exactly:

@Citizen

local camerasSelection = { 
    {2296.2890625, -1395.05761718, 694.02215576172, 2308.077148437, -1410.1640625, 688.58026123047}, -- DM 
    {2262.1308593, -1402.44628906, 699.66162109375, 2271.508789062, -1421.4033203, 691.99346923828}, -- DD 
    {2248.1074218, -1400.54296875, 695.64147949219, 2232.736328125, -1411.4306640, 696.97576904297}  -- HT 
} 
local currentSelection = 1 -- means it will be DM by default 
  
function updateCameraSelection() 
    local c, i = camerasSelection, currentSelection -- making temp aliases so it's shorter 
    local x, y, z = c[i][1], c[i][2], c[i][3] 
    local tx, ty , tz = c[i][4], c[i][5], c[i][6] 
    setCameraMatrix( x, y, z, tx, ty, tz ) 
end 
  
function nextSelection() 
    currentSelection = currentSelection + 1 
    if currentSelection > #camerasSelection then currentSelection = 1 end 
    updateCameraSelection() 
end 
  
function prevSelection() 
    currentSelection = currentSelection - 1 
    if currentSelection < 1 then currentSelection = #camerasSelection end 
    updateCameraSelection() 
end 
  
addEventHandler("onClientResourceStart", resourceRoot, function() 
    bindKey("arrow_l", "down", prevSelection) -- bind when just joined the server 
    bindKey("arrow_r", "down", nextSelection) -- bind when just joined the server 
    updateCameraSelection() 
end) 
  
addEventHandler("onClientPlayerSpawn", localPlayer, function() 
    if getKeyBoundToFunction(nextSelection) ~= "arrow_r" then return end -- prevent unbinding if already unbound 
    unbindKey("arrow_l", "down", prevSelection) -- unbound when spawning 
    unbindKey("arrow_r", "down", nextSelection) -- unbound when spawning 
end) 

this returns the camera 1

currentSelection = #camerasSelection  

this returns the correct camera 3

currentSelection = currentSelection+#camerasSelection 

Link to comment
  • Moderators
this returns the camera 1
currentSelection = #camerasSelection  

this returns the correct camera 3

currentSelection = currentSelection+#camerasSelection 

No sir, #camerasSelection returns the number of rows of the camerasSelection table which is 3.

Did you even tested it ? I guess not :wink:

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