Xwad Posted April 15, 2015 Share Posted April 15, 2015 Hi is it possible to make a script that will make an explosion when a player hit an object? becaouse i will make a trip mine. Thanks. Link to comment
xXMADEXx Posted April 15, 2015 Share Posted April 15, 2015 Yes, it's definitely possible. Instead of doing it so when you hit the object, you should create a small colshape around the object, this way you will be able to use the onClientColShapeHit event. Use these functions: getElementPosition createColCuboid createExplosion Link to comment
Enargy, Posted April 15, 2015 Share Posted April 15, 2015 createObject createColSphere createExplosion onColShapeHit --- when players touch Sphere Link to comment
Enargy, Posted April 15, 2015 Share Posted April 15, 2015 Yes, it's definitely possible. Instead of doing it so when you hit the object, you should create a small colshape around the object, this way you will be able to use the onClientColShapeHit event. Use these functions: getElementPosition createColCuboid createExplosion You were fastest Link to comment
Xwad Posted April 15, 2015 Author Share Posted April 15, 2015 Thanks:D I will make it tomorow. One question: if I make a colsphere then wil the players see it on the map? Link to comment
ALw7sH Posted April 15, 2015 Share Posted April 15, 2015 no, but you can create Radar-area in the same position of the col shape so players can see it in radar Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 i made it but only the createObject is working:/ function Mine(thePlayer, matchingDimension) createColSphere ( -1467, -1467, 99.15, 1 ) local pX, pY, pZ = getElementPosition ( source ) -- get the player's position createExplosion ( pX, pY, pZ, 6, source ) -- and create an explosion there outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox end addEventHandler("onColShapeHit",root,Mine) function Object ( name ) createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object end addEventHandler ( "onResourceStart", resourceRoot, Object ) Link to comment
ALw7sH Posted April 16, 2015 Share Posted April 16, 2015 the col shape should be out the hit function function Object ( name ) createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object colShape = createColSphere ( -1467, -1467, 99.15, 1 ) end addEventHandler ( "onResourceStart", resourceRoot, Object ) function Mine(thePlayer, matchingDimension) local pX, pY, pZ = getElementPosition ( source ) -- get the player's position createExplosion ( pX, pY, pZ, 6, source ) -- and create an explosion there outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox end addEventHandler("onColShapeHit",colShape,Mine) Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 not working:/ bad argumentum @ 'addEventHandler' [Expected element at argument 2, got nil] Link to comment
ALw7sH Posted April 16, 2015 Share Posted April 16, 2015 function Object ( name ) createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object colShape = createColSphere ( -1467, -1467, 99.15, 1 ) end addEventHandler ( "onResourceStart", resourceRoot, Object ) function Mine(thePlayer, matchingDimension) if source == colShape then local pX, pY, pZ = getElementPosition ( thePlayer ) -- get the player's position createExplosion ( pX, pY, pZ, 6, source ) -- and create an explosion there outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox end end addEventHandler("onColShapeHit",root,Mine) Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 its not working only the createObject and no debugscript. Link to comment
ALw7sH Posted April 16, 2015 Share Posted April 16, 2015 Make sure that your colshape positions is right you can use this command showcol Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 the command is not working. But how can i set the height and the width?? Link to comment
ALw7sH Posted April 16, 2015 Share Posted April 16, 2015 you should enable the DevelopmentMode using this function setDevelopmentMode before you use the command then use the command like that showcol 1 Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 i enabled and its not working:(( But can i not set the width and the height for the colosphere? Link to comment
ALw7sH Posted April 16, 2015 Share Posted April 16, 2015 the command is working but you cant see the colshape because the colshape position is worng and you cannot choose the width and high you have used sphere colshaope anyway try that code it should works fine function Object ( name ) createObject ( 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 ) -- this creates an object colShape = createColSphere ( -1467, -1287.6701, 99.15, 2 ) -- the last argument is the size of the colshape end addEventHandler ( "onResourceStart", resourceRoot, Object ) function Mine(thePlayer, matchingDimension) if source == colShape then local pX, pY, pZ = getElementPosition ( thePlayer ) -- get the player's position createExplosion ( pX, pY, pZ, 6, source ) -- and create an explosion there outputChatBox("You stepped on a Mine!",colShape,255,109 ,109 ) -- outputs a chatbox end end addEventHandler("onColShapeHit",root,Mine) Link to comment
Xwad Posted April 16, 2015 Author Share Posted April 16, 2015 WTF not working!! no debugscript nothing i dont know whats the problem!! pls help. Is it server side?? Link to comment
Maurize Posted April 16, 2015 Share Posted April 16, 2015 local mines = { { 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 } }; -- all mines over here! addEventHandler( "onResourceStart", resourceRoot, -- if resource started the function starts to work! function() for i, v in ipairs( mines ) do -- loop the table above. you can add more mines if you add more data { { id, x, y, z, rx, ry, rz }, { same here and so on } } local mine = createObject( v[1], v[2], v[3], v[4], v[5], v[6], v[7] ); -- lets create it setElementData( mine, "mine", true ); -- lets set a data to remember it is a mine end setTimer( function() for i, p in ipairs( getElementsByType( "player" ) ) do -- loop through all players and check position pX, pY, pZ = getElementPosition( p ); -- get position for i, o in ipairs( getElementsByType( "object" ) ) do -- loop through all objects and check position if ( getElementData( o, "mine" ) == true ) then -- check if it really a mine and not for example fence oX, oY, oZ = getElementPosition( o ); -- get position if ( getDistanceBetweenPoints3D( pX, pY, pZ, oX, oY, oZ ) < 2 ) then -- now lets see if player is near enough outputChatBox( "Kaboooohm! Mine over here!", p, 255, 0, 0 ); createExplosion( oX, oY, oZ, 6 ); -- more realistic if explosion comes from mine. end end end end end, 1000, 0 ); -- lets check every second if someone is near mine. end ) untested but should work Link to comment
Enargy, Posted April 17, 2015 Share Posted April 17, 2015 it work perfectly. (tested) function Object ( name ) setElementCollisionsEnabled(createObject ( 1211, -1467.2827, -1287.6701, 99.1, 0, 0, 0 ), false) -- this creates an object colShape = createColSphere ( -1467.2827, -1287.6701, 99.1, 2) end addEventHandler ( "onResourceStart", resourceRoot, Object ) function Mine(thePlayer, matchingDimension) if getElementType ( thePlayer ) == "player" then if source == colShape then local pX, pY, pZ = getElementPosition ( thePlayer ) -- get the player's position createExplosion ( pX, pY, pZ, 6, thePlayer ) -- and create an explosion there outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox end end end addEventHandler("onColShapeHit",root,Mine) Link to comment
Enargy, Posted April 17, 2015 Share Posted April 17, 2015 local mines = { { 1211, -1467.2827, -1287.6701, 99.15, 0, 0, 0 } }; -- all mines over here! addEventHandler( "onResourceStart", resourceRoot, -- if resource started the function starts to work! function() for i, v in ipairs( mines ) do -- loop the table above. you can add more mines if you add more data { { id, x, y, z, rx, ry, rz }, { same here and so on } } local mine = createObject( v[1], v[2], v[3], v[4], v[5], v[6], v[7] ); -- lets create it setElementData( mine, "mine", true ); -- lets set a data to remember it is a mine end setTimer( function() for i, p in ipairs( getElementsByType( "player" ) ) do -- loop through all players and check position pX, pY, pZ = getElementPosition( p ); -- get position for i, o in ipairs( getElementsByType( "object" ) ) do -- loop through all objects and check position if ( getElementData( o, "mine" ) == true ) then -- check if it really a mine and not for example fence oX, oY, oZ = getElementPosition( o ); -- get position if ( getDistanceBetweenPoints3D( pX, pY, pZ, oX, oY, oZ ) < 2 ) then -- now lets see if player is near enough outputChatBox( "Kaboooohm! Mine over here!", p, 255, 0, 0 ); createExplosion( oX, oY, oZ, 6 ); -- more realistic if explosion comes from mine. end end end end end, 1000, 0 ); -- lets check every second if someone is near mine. end ) untested but should work for i, v in ipairs( mines ) do -- code end 'ipairs' only works if the table has string, as fair i know. you must use: pairs Link to comment
Xwad Posted April 17, 2015 Author Share Posted April 17, 2015 Enargy its working! Thanks! And thanks for all answer thanks:D Link to comment
Xwad Posted April 17, 2015 Author Share Posted April 17, 2015 wait its not demaging i think its becaouse my spawn script! Link to comment
Xwad Posted April 17, 2015 Author Share Posted April 17, 2015 yes its becaouse my spawn script!! So i used SetElementHealth for the script but dosent work function Object ( name ) setElementCollisionsEnabled(createObject ( 1211, -1467.2827, -1287.6701, 99.1, 0, 0, 0 ), false) -- this creates an object colShape = createColSphere ( -1746, -1743, 28, 2) end addEventHandler ( "onResourceStart", resourceRoot, Object ) function Mine(thePlayer, matchingDimension) if getElementType ( thePlayer ) == "player" then if source == colShape then local pX, pY, pZ = getElementPosition ( thePlayer ) -- get the player's position createExplosion ( pX, pY, pZ, 6, thePlayer ) -- and create an explosion there if ( theHealth < 100 ) then setElementHealth ( source, theHealth - 70) outputChatBox("You stepped on a Mine!",thePlayer,255,109 ,109 ) -- outputs a chatbox end end end end addEventHandler("onColShapeHit",root,Mine) Link to comment
Enargy, Posted April 17, 2015 Share Posted April 17, 2015 local theHealth = getElementHealth(thePlayer); if ( theHealth < 100 ) then setElementHealth(thePlayer, theHealth - 70); end 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