Jump to content

bind key


joedajoester

Recommended Posts

Here it is :D

col  = createColTube (-1851, -3112.1000976563, 51.700000762939, 10, 3) -- enter your cooderates here  
  
for your colshape please note 10 and 3 is to do with the size of the shape. 
root = getRootElement () 
  
lift = createObject ( 3095, -1851, -3112.1000976563, 51.700000762939, 0, 0, 228.49365234375) -- enter  
  
the ID of the object followed by the coordinates 
                                 -- note the rotx y and z may not be required so you just remove these.  
  
x y and z is where you would put your cordinates. 
  
  
function Open ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" )  
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 38.900001525879)    -- here is where you  
  
enter the coordinatess of the new location of the object, 2200 = the speed of the movent. 
        end 
    end 
end   
addEventHandler ( "onColShapeHit", col, Open) 
  
function Close ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" )  
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) -- here is where you copy  
  
the coordinates of the orginal location of the object, 2951 = the timer of movent. 
        end 
    end 
end 
addEventHandler ( "onColShapeLeave", col, Close ) 

It works but as you know it has the collision zone which needs to be replaced to bind keys when in the collision zone

Link to comment

You Mean Like This ?

function Open ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" )  
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 38.900001525879)    -- here is where you  
  
enter the coordinatess of the new location of the object, 2200 = the speed of the movent. 
        end 
    end 
end   
addEventHandler ( "onColShapeHit", col, Open) 
  
function Close ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" )  
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) -- here is where you copy  
bindKey ( player, "F3", "down", Open ) 

Link to comment
function Open ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" ) 
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 38.900001525879)  
  
        end 
    end 
end   
addEventHandler ( "onColShapeHit", col, Open) 
  
function Close ( pla ) 
    if getElementType ( pla ) == "player" then 
        if isObjectInACLGroup ( "user."..getAccountName(getPlayerAccount(pla)), aclGetGroup ( "Admin" ) 
  
) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
bindKey ( player, "F3", "down", Open ) 

Obviously when copying a script from the wiki, remove the random text and comments...

Link to comment

Well it was a chaos. I decided to clean it up a bit. Make sure you got that "col" colshape there and that you're an admin, otherwise it's not going to work. I'd like to see the whole script but as you gave us this little, I can't help you much in case if an unknown error happens.

function open(hitPlayer, matchingDimension) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if hitPlayer then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
addEventHandler("onColShapeHit", col, open) 
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if getElementType(player) == "player" then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", col, close) 
  
function binding() 
    bindKey(source, ",", "down", open) 
    bindKey(source, "/", "down", close) 
end 
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), binding) 

Link to comment

who is source?

function binding() 
for i,player in ipairs(getElementsByType("player")) do 
          if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
          bindKey(player, ",", "down", open) 
          bindKey(player, "/", "down", close) 
          end 
     end 
end 
addEventHandler("onResourceStart", resourceRoot, binding) 

Link to comment

None of these work. I tried all of them, the one scozialz made i get an error..

Bad 'player' pointer at 'bindKey'(1)

Please help me the lift doesnt even spawn because of that error

*EDIT! I replaced the bindkey part with tapl 's and it didnt work but i got no error so i realized theres no part of the script that created the object so i added that back in and it works, but it does not go back up.

So it lowers and does not lift. Were makin progress :D

Link to comment

try this:

function open(hitPlayer, matchingDimension) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if hitPlayer then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
addEventHandler("onColShapeHit", col, open) 
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if getElementType(player) == "player" then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", col, close) 
  
 addEventHandler("onPlayerJoin",getRootElement(),  
function() 
    bindKey(source, ",", "down", open) 
    bindKey(source, "/", "down", close) 
end) 

Link to comment

For tapls one i edited it only lowers, and does not lift. When i press the button for lift i get this error

Bad argument @ getPlayerAccount expected element at argument 1 got nill

Bad argument @ getAccountName expected account at argument 1 got boolean

attempt to concatenate local 'acc' (a boolean value)

Link to comment

Does your server have a login system?

Try This:

  
function open(hitPlayer, matchingDimension) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if hitPlayer then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
addEventHandler("onColShapeHit", col, open) 
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if getElementType(player) == "player" then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", col, close) 
  
 addEventHandler("onPlayerLogin",getRootElement(), 
function() 
    bindKey(source, ",", "down", open) 
    bindKey(source, "/", "down", close) 
end) 

Link to comment

Anyone?? It only lowers, and get this error when i press the button to lift.

Bad argument @ getPlayerAccount expected element at argument 1 got nill

Bad argument @ getAccountName expected account at argument 1 got boolean

attempt to concatenate local 'acc' (a boolean value)

Heres the script im using now.

  
lift = createObject (3095, -1851, -3112.1000976563, 51.700000762939, 0, 0, 228.49365234375) 
function open(hitPlayer, matchingDimension) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if hitPlayer then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
addEventHandler("onColShapeHit", col, open) 
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
    if getElementType(player) == "player" then 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", col, close) 
  
function binding() 
for i,player in ipairs(getElementsByType("player")) do 
          if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
          bindKey(player, ",", "down", open) 
          bindKey(player, "/", "down", close) 
          end 
     end 
end 
addEventHandler("onResourceStart", resourceRoot, binding) 

Link to comment
 lift = createObject (3095, -1851, -3112.1000976563, 51.700000762939, 0, 0, 228.49365234375) 
function open(hitPlayer, matchingDimension) 
    if getElementType(hitPlayer) == "player" then 
    local acc = getAccountName(getPlayerAccount(hitPlayer)) 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
addEventHandler("onColShapeHit", col, open) 
  
function close(leaveElement, matchingDimension) 
    if getElementType(leaveElement) == "player" then 
    local acc = getAccountName(getPlayerAccount(leaveElement)) 
        if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
        end 
    end 
end 
addEventHandler("onColShapeLeave", col, close) 
  
function binding() 
for i,player in ipairs(getElementsByType("player")) do 
          if isObjectInACLGroup("user." .. getAccountName(getPlayerAccount(player)), aclGetGroup("Admin")) then 
          bindKey(player, ",", "down", open) 
          bindKey(player, "/", "down", close) 
          end 
     end 
end 
addEventHandler("onResourceStart", resourceRoot, binding) 

Link to comment

nvm yayayayayayay thank you tapl and everone else it works :D I will give u credit and try to learn this for future times. I wanna give u a cookie :D

It doesnt bind the key when i enter hte collisin zone, it allways does i dont need that. It was a misunderstanding please help with that. and i need to unbind keys when leaving?

unbindKey ( player, ",", "down", open ) 
unbindKey ( player, "/", "down", close ) 

I dont know where to place it

Link to comment

do you want the gate open when an admin hit the col?

or just bind a key to open/close the gate when the admin hit the col?

maybe this what you want?

lift = createObject (3095, -1851, -3112.1000976563, 51.700000762939, 0, 0, 228.49365234375) 
function open(player) 
    local acc = getAccountName(getPlayerAccount(player)) 
         if acc then 
         if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(player)) 
         if acc then 
         if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
              moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
         end 
    end 
end 
  
function bind(hitPlayer, matchingDimension) 
          bindKey(hitPlayer, ",", "down", open) 
          bindKey(hitPlayer, "/", "down", close) 
end 
addEventHandler("onColShapeHit", col, bind) 
  
function unbind(leaveElement, matchingDimension) 
          unbindKey(leaveElement, ",", "down", open) 
          unbindKey(leaveElement, "/", "down", close) 
end 
addEventHandler("onColShapeLeave", col, unbind) 

Link to comment
lift = createObject (3095, -1851, -3112.1000976563, 51.700000762939, 0, 0, 228.49365234375) 
function open(player) 
    local acc = getAccountName(getPlayerAccount(player)) 
         if acc then 
         if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
            moveObject(lift, 2500, -1851, -3112.1000976563, 38.900001525879) 
        end 
    end 
end   
  
function close(player) 
    local acc = getAccountName(getPlayerAccount(player)) 
         if acc then 
         if isObjectInACLGroup("user." .. acc, aclGetGroup("Admin")) then 
              moveObject (lift, 2500, -1851, -3112.1000976563, 51.700000762939) 
         end 
    end 
end 
  
function bind(hitPlayer, matchingDimension) 
if getElementType(hitPlayer) == "player" then 
          bindKey(hitPlayer, ",", "down", open) 
          bindKey(hitPlayer, "/", "down", close) 
          end 
end 
addEventHandler("onColShapeHit", col, bind) 
  
function unbind(leaveElement, matchingDimension) 
if getElementType(leaveElement) == "player" then 
          unbindKey(leaveElement, ",", "down", open) 
          unbindKey(leaveElement, "/", "down", close) 
          end 
end 
addEventHandler("onColShapeLeave", col, unbind) 

Link to comment

You forgot to add the brackets:

function bind(hitPlayer, matchingDimension) 
if (getElementType(hitPlayer) == "player") then 
          bindKey(hitPlayer, ",", "down", open) 
          bindKey(hitPlayer, "/", "down", close) 
          end 
end 
addEventHandler("onColShapeHit", col, bind) 
  
function unbind(leaveElement, matchingDimension) 
if (getElementType(leaveElement) == "player") then 
          unbindKey(leaveElement, ",", "down", open) 
          unbindKey(leaveElement, "/", "down", close) 
          end 
end 
addEventHandler("onColShapeLeave", col, unbind) 

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