Jump to content

Bind key with clientside function onPlayerConnect


Recommended Posts

Hello, today i tried to bind a key when a player connects to the Server(client side)

but it dont worked.

Now i want to bind the Key onPlayerConnect in server side.

But the function can only run client side.

My question: how to call a client side function on server side and what is the best method to do this?

Link to comment

hello you can use events you can create an event on client side and run it with triggerClientEvent on server side

 

example:

server

addEventHandler("onPlayerJoin", root, 
	function()
       triggerClientEvent(source, "testEvent", source) -- execute event
	end
)

client

addEvent("testEvent", true)
addEventHandler("testEvent", root,
    function()
       --do something here
    end
)

or you can browse this script of IIYAMA 

 

I also suggest you to use "onPlayerJoin" Event for key binding.

Edited by Burak5312
Link to comment

Hey,

There is a chance the player to get an error - the client side event is not attached to any function.
When the "onPlayerJoin" is triggered the player might still be downloading -> the player still doesn't have the client side loaded -> error.

I don't get it why would you want to bind the key in the server side and "onPlayerConnect".
It would have had more logic if it was onPlayerLogin (i.e. to check if has enough rights but you didn't mention something like that).

Anyways you can easily put the bindKey function in the client script out of any functions and it will bind the key on client resource load.

function asd()
	-- something
end
bindKey("F1", "down", asd)

Or use the onClientResourceStart event.

Edited by SpecT
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...