Timiimit Posted February 3, 2012 Share Posted February 3, 2012 Hi! I want to know how "onColShapeHit" works! I read the wiki page but i still don't get it. I tried this: function test( thePlayer ) outputChatBox("it's working!!") end addEventHandler("onColShapeHit", getRootElement(), test) ...But it doesn't work. I want to make script that outputs 'it's working!!' when I touch any object. why noone knows? Link to comment
Kenix Posted February 3, 2012 Share Posted February 3, 2012 Maybe you need this? https://wiki.multitheftauto.com/wiki/OnPlayerContact Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 I want it to trigger it only once! not again when its not targeting anything. + nothing happens at this: function onPlayerTarget ( targetElem ) if getElementType ( targetElem ) == "object" then output("someone touched an object!") end end addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget ) HELP???!!!:::::-----....._____ Link to comment
mjau Posted February 3, 2012 Share Posted February 3, 2012 function onPlayerTarget ( targetElem ) if getElementType ( targetElem ) == "object" then outputChatBox("someone touched an object!") end end addEventHandler ( "onPlayerTarget", getRootElement(), onPlayerTarget ) Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 i think that is thesame. anyway it's still not working!!! Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 <meta> <info author="[GFL]TimiimiT" name="something" version="1.0"/> <script src="test.lua" /> </meta> btw I started the resource! tried onPlayerContact not working: function outputElementType ( prev, current ) if ( current ) then outputChatBox ( "You have hit an "..getElementType ( current ) ) end end addEventHandler ( "onPlayerContact", getRootElement(), outputElementType ) Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 other scripts that are in this recources are working so it must be wrong lua!!?????? (from wiki nothing is wrong gotta be BUG) Link to comment
Evil-Cod3r Posted February 3, 2012 Share Posted February 3, 2012 This is an example local hillArea = createColRectangle ( -2171.0678710938, 678.17950439453, 15, 15 ) -- add hill_Enter as a handler for when a player enters the hill area function hill_Enter ( thePlayer, matchingDimension ) if getElementType ( thePlayer ) == "player" then --if the element that entered was player --let's get the name of the player local nameOfThePlayer = getPlayerName ( thePlayer ) --announce to everyone that the player entered the hill outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 ) end end addEventHandler ( "onColShapeHit", hillArea, hill_Enter ) Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 thx! Only script that worked today!! but I want to trigger this event when i touch any object. anyone? Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 how to get all objects? Link to comment
Kenix Posted February 3, 2012 Share Posted February 3, 2012 getElementsByType( "object" ) Link to comment
Timiimit Posted February 3, 2012 Author Share Posted February 3, 2012 why is this not working?: local hillArea = getElementsByType( "object" ) -- add hill_Enter as a handler for when a player enters the hill area function hill_Enter ( thePlayer, matchingDimension ) if getElementType ( thePlayer ) == "player" then --if the element that entered was player --let's get the name of the player local nameOfThePlayer = getPlayerName ( thePlayer ) --announce to everyone that the player entered the hill outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 ) end end addEventHandler ( "onColShapeHit", hillArea, hill_Enter ) Link to comment
Castillo Posted February 3, 2012 Share Posted February 3, 2012 Maybe because instead of a colshape you're using getElementsByType... local hillArea = createColRectangle(arguments...) -- add hill_Enter as a handler for when a player enters the hill area function hill_Enter ( thePlayer, matchingDimension ) if getElementType ( thePlayer ) == "player" then --if the element that entered was player --let's get the name of the player local nameOfThePlayer = getPlayerName ( thePlayer ) --announce to everyone that the player entered the hill outputChatBox ( nameOfThePlayer.." entered the zone!", getRootElement(), 255, 255, 109 ) end end addEventHandler ( "onColShapeHit", hillArea, hill_Enter ) Link to comment
DiSaMe Posted February 3, 2012 Share Posted February 3, 2012 Objects aren't colshapes, that must be obvious. To detect player-object collisions, it's better to try something with isLineOfSightClear or processLineOfSight. 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