Jump to content

Disable players collisions?


arer

Recommended Posts

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

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)

  • Like 1
Link to comment
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 by arer
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...