trux_yt Posted July 18, 2021 Share Posted July 18, 2021 How can I do that if the vehicle touched the model with id 2892, execute the event? addEventHandler("onClientColShapeHit", root, function(hit,dim) if dim and getElementType(hit) == 'vehicle' then if getElementModel(hit) == 2892 then triggerServerEvent("pierceWheel", vehicle) end end end) Link to comment
Scripting Moderators ds1-e Posted July 20, 2021 Scripting Moderators Share Posted July 20, 2021 (edited) As long as it have collision it should be retrievable with https://wiki.multitheftauto.com/wiki/OnClientVehicleCollision With either hitElement or model parameter. However i think that's not a case for stinger - which you are trying to do i guess? Have a look at this resource which might help you: https://community.multitheftauto.com/index.php?p=resources&s=details&id=125 Edited July 20, 2021 by srslyyyy Link to comment
trux_yt Posted July 21, 2021 Author Share Posted July 21, 2021 (edited) --create spikes registerEvent("createSpike", root, function(id, data) createdSpike[id] = {} -- OID: 2892 createdSpike[id].object = createObject(data.objectId, data.posX, data.posY, data.posZ, 0, 0, data.rotZ) local x, y, z = getElementPosition( createdSpike[id].object ) -- get vehicle position local a = getElementRotation( createdSpike[id].object ) -- get player facing angle x = x + math.sin( math.rad(a) ) * 4 y = y - math.cos( math.rad(a) ) * 4 theColShapes = createColRectangle( (x - 2.0), (y - 2.0), 4.0, 4.0 ) -- set a colshape to check when a car hits the stinger setElementData( theColShapes, "amistinger", "yesplz" ) -- set the colshape as a stinger colshape if isElement(sound) then stopSound(sound) end sound = playSound3D("spike.wav", data.posX, data.posY, data.posZ + 0.1, false) print(getSoundLength(sound), getSoundLength(sound) * 1000) initAnimation("spikeAnim" .. id , false, {0, 0, 0}, {1, 0, 0}, 2450, "Linear", function(id, data) local rotated_x1, rotated_y1 = rotateAround(data.rotZ, -spikeDetails[data.objectId].width/ 2, -spikeDetails[data.objectId].length / 2) local rotated_x2, rotated_y2 = rotateAround(data.rotZ, spikeDetails[data.objectId].width / 2, -spikeDetails[data.objectId].length / 2) local rotated_x3, rotated_y3 = rotateAround(data.rotZ, spikeDetails[data.objectId].width / 2, spikeDetails[data.objectId].length / 2) local rotated_x4, rotated_y4 = rotateAround(data.rotZ, -spikeDetails[data.objectId].width / 2, spikeDetails[data.objectId].length / 2) createdSpike[id].col = createColPolygon( data.posX, data.posY, -- Center data.posX + rotated_x1, data.posY + rotated_y1, data.posX + rotated_x2, data.posY + rotated_y2, data.posX + rotated_x3, data.posY + rotated_y3, data.posX + rotated_x4, data.posY + rotated_y4 ) if isElement(sound) then stopSound(sound) end end, {id, data}) end) --wheels addEventHandler("onClientColShapeHit", root, function(vehicle, dimMatch) if vehicle and getElementType(vehicle) == "vehicle" and getElementData( source, "amistinger" ) == "yesplz" then triggerServerEvent("pierceWheel", vehicle) end end) the wheels puncture in only one corner Edited July 21, 2021 by trux_yt 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