arer Posted May 12, 2017 Share Posted May 12, 2017 Hi. I have a question how to make players going through each other? I made something but this is not working. function on(el,en) for k,v in ipairs(getElementsByType("player")) do --setElementCollisionsEnabled(v, false) setElementCollidableWith(v, v, false) end end function off(el,en) for k,v in ipairs(getElementsByType("player")) do --setElementCollisionsEnabled(v, true) setElementCollidableWith(v, v, true) end end addCommandHandler ( "k", on ) addCommandHandler ( "k2", off ) Link to comment
pa3ck Posted May 12, 2017 Share Posted May 12, 2017 That doesn't make sense, you are trying to disable the collision for player1 with player1. What I would do is: local colsEnabled = true addEventHandler( "onClientElementStreamIn", getRootElement( ), function ( ) if getElementType( source ) == "player" and not colsEnabled then setElementCollidableWith(localPlayer, source, false) end end ) function toggleCollisionsForPlayer(p, enabled) for k, v in ipairs(getElementsByType("player")) do setElementCollidableWith(p, v, enabled) end end addCommandHandler("toggle_col", function() toggleCollisionsForPlayer(localPlayer, not colsEnabled) colsEnabled = not colsEnabled end) Not tested, but should work. Basically when you enter "/toggle_col", if it is enabled, it calls toggleCollisionsForPlayer that will loop thru each player and disable the collisions between them. But if a player connects to the server, the collision with that player will still be enabled, that is why I added the event onClientElementStreamIn. When that event runs, it checks if the colsEnabled = false (so collisions are disabled) and disables the collision with the source element (the element that got streamed in) 1 Link to comment
arer Posted May 12, 2017 Author Share Posted May 12, 2017 (edited) 13 minutes ago, pa3ck said: That doesn't make sense, you are trying to disable the collision for player1 with player1. What I would do is: Not tested, but should work. Basically when you enter "/toggle_col", if it is enabled, it calls toggleCollisionsForPlayer that will loop thru each player and disable the collisions between them. But if a player connects to the server, the collision with that player will still be enabled, that is why I added the event onClientElementStreamIn. When that event runs, it checks if the colsEnabled = false (so collisions are disabled) and disables the collision with the source element (the element that got streamed in) Very thank you! There is error getting in line 13 when im using /toggle_col: "attempt to call global 'setElementCollidableWith' (a nil value) Edited May 12, 2017 by arer Link to comment
pa3ck Posted May 12, 2017 Share Posted May 12, 2017 This is a client-side script, make sure you set the type="client" in your meta.xml 1 Link to comment
arer Posted May 12, 2017 Author Share Posted May 12, 2017 2 minutes ago, pa3ck said: This is a client-side script, make sure you set the type="client" in your meta.xml Yeah, it's working now! Very thank you! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now