Jump to content

Dynamic colshapes


ds1-e

Recommended Posts

  • Scripting Moderators

Hey once again. I have encountered a issue with colshapes.

https://wiki.multitheftauto.com/wiki/OnClientColShapeHit
https://wiki.multitheftauto.com/wiki/OnClientColShapeLeave

So what's the problem with them?

- OnClientColShapeHit doesn't trigger after leaving from other colshape. Let's say i have player with colshape, inside of car which have colshape too. Firstly i hit car colsphere, then i hit player colsphere, after that i leave from player colsphere, but sadly, onClientColShapeHit doesn't trigger for car colsphere, even if i am still inside of colshape. So i am asking you guys, how can i do something like "dynamic" colshapes. Or atleast fix issue above.

 

Edited by majqq
Link to comment

It's normal, the event is triggered only when you hit the colshape bounds. In your use case, you are already in the car's col, so no new hit event is detected. You can save the interaction colshapes that are 'active' for the player by using tables.

  • Thanks 1
Link to comment
  • Scripting Moderators
16 hours ago, Zorgman said:

It's normal, the event is triggered only when you hit the colshape bounds. In your use case, you are already in the car's col, so no new hit event is detected. You can save the interaction colshapes that are 'active' for the player by using tables.

If colshape/player hit each other, save it to client-side table, and then let's say use a function to switch them, if there's more than 1, and if player is in range of it? Plus delete data from this table onClientElementDestroy? That's what you mean?

Link to comment
  • 3 weeks later...
  • Scripting Moderators

bump.

I just tried 2 different events related with colshapes, and probably i shoud use OnClientElementColShapeHit/OnClientElementColShapeLeave.

Because onClientColShapeLeave doesn't trigger after jumping out of car.

function onClientElementColShapeHit(theShape, sameDimension)
	colShape = "onClientElementColShapeHit"
end
addEventHandler("onClientElementColShapeHit", getRootElement(), onClientElementColShapeHit)

--

function onClientElementColShapeLeave(theShape, sameDimension)
	colShape = "onClientElementColShapeLeave"
end
addEventHandler("onClientElementColShapeLeave", getRootElement(), onClientElementColShapeLeave)

 

Added little state in onClientRender to be sure which event triggers.

But, still i need some help. I would like to know which way will be best for get colshape into table (only if it doesn't exist in table). Any advices?

Link to comment

Assuming that you can interact with only one player and one vehicle at a time - just create two client-side variables to handle it (e.g. currentVehicleInteractCol and currentPlayerInteractCol) and update them on hit and on leave events.

 

 

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