Jump to content

Why is this another code not working?


Recommended Posts

Nothing happens when I press W!

function playerPressedKey(button, press)
    if button == "w" then
        outputChatBox("You pressed the " .. button .. " key!")
    end
end
addEventHandler("onClientKey", root, playerPressedKey)

 

And also,

if I made a table with various buttons, for example:

movement = {"w", "s", "d", "a", "shift"}

and substituted the "w" in the first code with movement, would it work (in the fixed version that you're please gonna tell me)?

 

And is there anything wrong with this code?

function playerPressedKey(button, press, thePlayer)
    if button == "w" then
        setPedAnimation(thePlayer)
    end
end
addEventHandler("onClientKey", root, playerPressedKey)

Thanks!

Edited by Hugo_Almeidowski
Link to comment
30 minutes ago, DNL291 said:

Show your meta.xml.

Ohhhh thaanks

It was set to server. my bad!

2 minutes ago, Hugo_Almeidowski said:

Ohhhh thaanks

It was set to server. my bad!

I changed it to client, ant it work, but now I have another problem.

This function stoped working.

function toggleSit(thePlayer)
		setPedAnimation(thePlayer, "ped", "seat_down", -1, false, false, false, true)
end
addCommandHandler("sit", toggleSit)

So, I made two lua scripts. One for client and one for server.

The one above was sent to the server script.

And the one below was sent to the client script.

function playerPressedKey(button, press, thePlayer)
    if button == "w" then
        setPedAnimation(thePlayer)
    end
end
addEventHandler("onClientKey", root, playerPressedKey)

This one was supposed to stop the sit anim in the server script, but it doesn't. why?

Link to comment
function playerPressedKey(button, press)
  if press then
    if button == "w" then
        setPedAnimation(localPlayer)
    end
   end
end
addEventHandler("onClientKey", root, playerPressedKey)

I think this should work.

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