Cocodrilo Posted January 23, 2014 Posted January 23, 2014 I want to destroy an object and a colSphere when i hit the col but it doesn't work What is wrong ? items = { { "Tire!", 1073, -1428.4814453125, 2666.4931640625, 55.6875 , 1}, { "Engine!", 929, -1425.5595703125, 2654.69140625, 55.6875, 0.3}, { "Hamburguer!", 2768, -1411.2607421875, 2635.3916015625, 55.6875, 1}, } function createFunction ( ) outputChatBox ("New items has been created!", player, 0,255,0) for i, v in ipairs ( items ) do object = createObject ( v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ]- 0.875, 0, 0, math.random ( 0, 360 ) ) setObjectScale(object, v [ 6 ] ) setElementCollisionsEnabled(object, false) setElementFrozen(object, true) setElementData ( object, v [ 1 ], true ) marker = createColSphere(v[3],v[4],v[5], 0.75) setElementData ( marker, "item", v [ 1 ] ) setElementData ( marker, "parent", object ) end end addEventHandler ( "onResourceStart", getRootElement(), createFunction) function claymoreHit ( player, matchingDimension ) if (getElementData (source,"item") == "Tire!" ) then setTimer ( function ( ) outputChatBox ("Tire!", player, 0,255,0) for i, v in ipairs ( items ) do object = createObject ( v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ]- 0.875, 0, 0, math.random ( 0, 360 ) ) setObjectScale(object, v [ 6 ] ) setElementCollisionsEnabled(object, false) setElementFrozen(object, true) setElementData ( object, v [ 1 ], true ) marker = createColSphere(v[3],v[4],v[5], 0.75) setElementData ( marker, "item", v [ 1 ] ) setElementData ( marker, "parent", object ) --[[ 1st Problem : ]] destroyElement(object) destroyElement(marker) --[[ Why elements are not destroyed? ]] end end ,50, 1 ) end end addEventHandler ( "onColShapeHit", getRootElement (), claymoreHit ) function respawnFunction ( ) --[[ 2nd problem: this would works if the problem 1 works ]] if ( not isElement ( object)) and ( not isElement ( marker)) then ---- setTimer ( function ( ) outputChatBox ("Respawn Items!", player, 0,255,0) for i, v in ipairs ( items ) do object = createObject ( v [ 2 ], v [ 3 ], v [ 4 ], v [ 5 ]- 0.875, 0, 0, math.random ( 0, 360 ) ) setObjectScale(object, v [ 6 ] ) setElementCollisionsEnabled(object, false) setElementFrozen(object, true) setElementData ( object, v [ 1 ], true ) marker = createColSphere(v[3],v[4],v[5], 0.75) setElementData ( marker, "item", v [ 1 ] ) setElementData ( marker, "parent", object ) end end ,5000, 0 ) end end respawnFunction ( )
Castillo Posted January 23, 2014 Posted January 23, 2014 You have to store all the objects and colshapes in a table, else you won't be able to destroy them without problems.
Cocodrilo Posted January 23, 2014 Author Posted January 23, 2014 Well, that's done. But now then i hit the marker i use setTimer to re-create the object and marker and that seems fine. The problem is: When i hit the marker all elements from the table are re created. coco2 = { { -1428.4814453125, 2666.4931640625, 55.6875}, {-1434.5478515625, 2668.42578125, 55.6875}, } function crearNeumatico ( ) outputChatBox ("respawn!", player, 0,255,0) for i, v in ipairs ( coco2 ) do local data = "Neumatico!" local clay = "clayN" local id = 1073 local scale = 1 local x,y,z = v[1],v[2],v[3] object = createObject ( id, x, y, z- 0.875, 0, 0, math.random ( 0, 360 ) ) setObjectScale(object, scale ) setElementCollisionsEnabled(object, false) setElementFrozen(object, true) marker = createMarker(x,y,z - 0.875, "cylinder",1,143,143,17,80) setElementData ( marker, data, true ) setElementData ( marker, clay, object ) end end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()), function () setTimer(crearNeumatico, 50, 1) end) function golpe( hitElement ) local marca = source local elem = getElementData (source, "clayN") if (getElementType( hitElement ) == "player" ) and (getElementData (source, "Neumatico!") == true ) then setTimer ( function() destroyElement(elem) destroyElement( marca ) outputChatBox ("hit", player, 0,255,0) end , 50, 1 ) setTimer(crearNeumatico, 10000, 1) end end addEventHandler( "onMarkerHit", getRootElement(), golpe ) I want to re create only the elements i hit. what is the right way to do?
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