SuperM Posted August 16, 2018 Share Posted August 16, 2018 Hello, I have the following code: local cuboidarea1 = createColCuboid(1268.4200439453, -838.69525146484, 75.494804382324, 26.5, 18.3, 23.7) local cuboidarea2 = createColCuboid(1203.875, -839.14135742188, 75.190124511719, 48.2, 18.6, 24.2) local cuboidarea3 = createColCuboid(1203.3291015625, -820.44226074219, 78.420753479004, 35.7, 20.2, 20.8) local cuboidarea4 = createColCuboid(1239.1188964844, -820.3447265625, 75.279731750488, 69.9, 53.100000000001, 23.9) function ColShapeHit ( thePlayer, matchingDimension ) local detection = isElementWithinColShape ( thePlayer, cuboidarea1, cuboidarea2, cuboidarea3, cuboidarea4) detection = detection and getElementDimension( thePlayer ) == getElementDimension( cuboidarea1 ) or getElementDimension( cuboidarea2 ) or getElementDimension( cuboidarea3 ) or getElementDimension( cuboidarea4 ) if detection then outputChatBox ( getPlayerName(thePlayer).." is inside the col shape" ) end end addEventHandler ( "onColShapeHit", root, ColShapeHit ) When one player get's inside of one of the 4 col shapes it sends one message to the chat "Player is inside the col shape" each time he get's inside of one col shape. Is there any way to make it show the message only one time? I mean for example the col shapes are like the following image: When player get's inside COL 1 shots the message on the chat, if he walks for example in this direction: He starts outside of COL 1 and stops inside of COL 4, it will show the message 3 times, one for COL 1 another for COL 2 and another for COL 4, is there any way to only show the message 1 time? if he is already inside the col shape 1, 2, 3 or 4, don't show the message. Or if is there any way to make "custom" shapes to make one format like the example images, for example, would probably be easy, instead of creating many col shapes. Thanks in advance for reading the topic and trying to understand what I need. GN everyone. Link to comment
Skream Posted August 16, 2018 Share Posted August 16, 2018 (edited) I'm not sure but maybe createColPolygon() would fit better what you intend. If its not the case try with getTickCount() just use getTickCount after he leaves the colshape and check the time diff after he enters the new one 16 minutes ago, SuperM said: Hello, I have the following code: local cuboidarea1 = createColCuboid(1268.4200439453, -838.69525146484, 75.494804382324, 26.5, 18.3, 23.7) local cuboidarea2 = createColCuboid(1203.875, -839.14135742188, 75.190124511719, 48.2, 18.6, 24.2) local cuboidarea3 = createColCuboid(1203.3291015625, -820.44226074219, 78.420753479004, 35.7, 20.2, 20.8) local cuboidarea4 = createColCuboid(1239.1188964844, -820.3447265625, 75.279731750488, 69.9, 53.100000000001, 23.9) function ColShapeHit ( thePlayer, matchingDimension ) local detection = isElementWithinColShape ( thePlayer, cuboidarea1, cuboidarea2, cuboidarea3, cuboidarea4) detection = detection and getElementDimension( thePlayer ) == getElementDimension( cuboidarea1 ) or getElementDimension( cuboidarea2 ) or getElementDimension( cuboidarea3 ) or getElementDimension( cuboidarea4 ) if detection then outputChatBox ( getPlayerName(thePlayer).." is inside the col shape" ) end end addEventHandler ( "onColShapeHit", root, ColShapeHit ) When one player get's inside of one of the 4 col shapes it sends one message to the chat "Player is inside the col shape" each time he get's inside of one col shape. Is there any way to make it show the message only one time? I mean for example the col shapes are like the following image: When player get's inside COL 1 shots the message on the chat, if he walks for example in this direction: He starts outside of COL 1 and stops inside of COL 4, it will show the message 3 times, one for COL 1 another for COL 2 and another for COL 4, is there any way to only show the message 1 time? if he is already inside the col shape 1, 2, 3 or 4, don't show the message. Or if is there any way to make "custom" shapes to make one format like the example images, for example, would probably be easy, instead of creating many col shapes. Thanks in advance for reading the topic and trying to understand what I need. GN everyone. I was thinking about it again and I think a bettter approach that would detect would be use onClientRender and loop through all your shapes. If hes not inside of one of those then he just leaved. You don't have to trigger a function for this all the time, just when he enters. If hes not inside of any of those shapes then you remove it. When he enters one of those you add it again. Thats more efficient Edited August 16, 2018 by Skream Link to comment
SuperM Posted August 16, 2018 Author Share Posted August 16, 2018 5 minutes ago, Skream said: I'm not sure but maybe createColPolygon() would fit better what you intend. If its not the case try with getTickCount() just use getTickCount after he leaves the colshape and check the time diff after he enters the new one I was thinking about it again and I think a bettter approach that would detect would be use onClientRender and loop through all your shapes. If hes not inside of one of those then he just leaved. You don't have to trigger a function for this all the time, just when he enters. If hes not inside of any of those shapes then you remove it. When he enters one of those you add it again. Thats more efficient I was checking and I would like to do it with createColPolygon() I think it's the thing I was looking for since I can do weird shapes with it, do you know if is there any script to help me getting the cords to createColPolygon() Link to comment
Skream Posted August 16, 2018 Share Posted August 16, 2018 (edited) 10 minutes ago, SuperM said: I was checking and I would like to do it with createColPolygon() I think it's the thing I was looking for since I can do weird shapes with it, do you know if is there any script to help me getting the cords to createColPolygon() https://wiki.multitheftauto.com/wiki/CreateColPolygon wiki says: Tip: To visualize a colshape when writing scripts, use the client console command showcol You just made me curious, can I ask what are you trying to do with that area? Edited August 16, 2018 by Skream Link to comment
WorthlessCynomys Posted August 16, 2018 Share Posted August 16, 2018 You can do it with a variable, two events, an if and a table containing the colshapes and a for cycle. On the event onColShapeHit you cycle through the table containing the colShapes, check if the variable is true or false and set the so called variable to true if the player entered one of the shapes in the table, then break out of the cycle and continoue on with the planned procedures. On the leave you do the exact same thing, only you set the variable to false now. Link to comment
SuperM Posted August 16, 2018 Author Share Posted August 16, 2018 1 hour ago, Skream said: https://wiki.multitheftauto.com/wiki/CreateColPolygon wiki says: Tip: To visualize a colshape when writing scripts, use the client console command showcol You just made me curious, can I ask what are you trying to do with that area? Just trying to make some kind of alarm system around vinewood houses, like the area of the property where you have "motion sensors" would activate the alarm when someone enters in the area 1 Link to comment
Discord Moderators Pirulax Posted August 17, 2018 Discord Moderators Share Posted August 17, 2018 Making that much colshapes can cause lag. Especially when created server-side. 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