Jump to content

bindKey (server)


Mojko

Recommended Posts

Hey I need some help, regarding "bindKey"

so what I basicly want to do is check if the player is pressing down a button, and when he does, I want to return a boolean value.

 

function keyInput(player, key, keyState)
	if(keyState == "down") then
	end
	
	outputChatBox("Pressing: " .. key)
end

function bindKeysWhenPlayerJoin()
	bindKey(source, "lalt", "down", keyInput)
end
addEventHandler("onPlayerJoin", getRootElement(), bindKeysWhenPlayerJoin)

So basicly I have the basics down, when the player joins the server the keys will bind, and when I press "lalt" then it gets printed out to the player's chat box.

The issue here is though, that I can't use this, for like anything, since I cannot return a value that I can later use.

Let me give an example.

 

Psuedo code:

I want to check if

- The player is colliding with a static pickup

- The player is pressing lalt

then print a message

 

Code:

function playerPickupCollision(pickup, dimension)
    -- Jobs
    for i = 1, #pickupInformation do
        if(pickup == pickupInformation[i][PICKUP_ID]) then
            outputChatBox(i, source)
            if(pickupInformation[i][TYPE] == "Job" && pressing_key("lalt")) then
                outputChatBox("Press LALT to become a " .. pickupInformation[i][DESCRIPTION], source)
            end
            if(pickupInformation[i][TYPE] == "Property" && pressing_key("lalt")) then
                outputChatBox("This is the " .. pickupInformation[i][DESCRIPTION], source)
            end
        end
    end
end
addEventHandler("onPlayerPickupHit", getRootElement(), playerPickupCollision)

(pressing_key isn't an actual function. it's the kind of function I want to create)

 

Thank you!

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