MisterQuestions Posted October 8, 2014 Share Posted October 8, 2014 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
Anubhav Posted October 8, 2014 Share Posted October 8, 2014 Arguement one should be A PLAYER! Link to comment
MisterQuestions Posted October 9, 2014 Author Share Posted October 9, 2014 Mmm...so how yo use it? Link to comment
joaosilva099 Posted October 9, 2014 Share Posted October 9, 2014 If u wanna bind when every player joins use event onPlayerJoin. Else could loop through all players with for _, p in ipairs (getElementsByType("player")) do bindKey(p, "arrow_r", "down", DaFunction) end Link to comment
MisterQuestions Posted October 14, 2014 Author Share Posted October 14, 2014 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
ZL|LuCaS Posted October 14, 2014 Share Posted October 14, 2014 (edited) 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 October 14, 2014 by Guest Link to comment
MisterQuestions Posted October 14, 2014 Author Share Posted October 14, 2014 Whats wrong on that code? Should change camera with the arrow_r Link to comment
ZL|LuCaS Posted October 14, 2014 Share Posted October 14, 2014 Whats wrong on that code?Should change camera with the arrow_r Your code does not make sense, See my post again. Link to comment
MisterQuestions Posted October 15, 2014 Author Share Posted October 15, 2014 Doenst change the camera Link to comment
Moderators Citizen Posted October 15, 2014 Moderators Share Posted October 15, 2014 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
MisterQuestions Posted October 15, 2014 Author Share Posted October 15, 2014 And how to make with arrow_l to return camera modes? I should chance - instead of + ? ? Link to comment
Moderators Citizen Posted October 15, 2014 Moderators Share Posted October 15, 2014 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
Fabioxps Posted October 17, 2014 Share Posted October 17, 2014 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 Citizen Posted October 21, 2014 Moderators Share Posted October 21, 2014 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 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