Jump to content

bindKey bad argument ? :s


DarkLink

Recommended Posts

Posted

Guys i am trying to use a bind key to turn on and off lights of vehicle.. but it says always on console : bad argument @ 'bindKey '

i have this code for bindKey :

  
bindKey ( keyPresser, "l", "down", VehicleLights ) 
  

can u guys explain me what i am doing wrong ?

thanks.

Edit: VehicleLights is my other function that turn on and off lights .

Posted

you can't just put that,

you have to put:

  
addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (keyPresser, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (keyPresser, "l", "down", VehicleLights ) 
end 
end) 
  

So when the player joins they could press the button.

Posted

wrong,

addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (keyPresser, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (keyPresser, "l", "down", VehicleLights ) 
end 
end) 

keyPresser is not defined,

you should

addEventHandler ( "onPlayerJoin", getRootElement(), 
function() 
bindKey (source, "l", "down", VehicleLights ) 
end) 
  
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), 
function() 
for index, player in pairs(getElementsByType("player")) do 
unbindKey (player, "l", "down", VehicleLights ) 
end 
end) 

Posted

keyPresser is player argument, was you know that ?

Try to do add something like

function onPlayerJoinBind () 
  bindKey ( source, "l", "down", VehicleLights ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), onPlayerJoinBind  ) 
  
function onResourceStartBind  () 
  for i,v in ipairs ( getElementsByType("player")) do 
  bindKey ( v, "l", "down", VehicleLights ) 
end 
addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), onResourceStartBind ) 
  

EDIT: someone was before me..

EDIT2: Why you guys unbinding key on start?

Posted

but jay why the handler when resource start?

there is no problem if they press the key and are not in vehicle.. because the function only does something if player is on vehicle

Posted

Are you sure about that karlis ?

I had a script for lighting up the headlights and the key from the script was "l" and it was working.

Posted
Are you sure about that karlis ?

I had a script for lighting up the headlights and the key from the script was "l" and it was working.

im sure lowercase doesn't work with /bind. afaik bindKey is same as /bind

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