Bean666 Posted February 12, 2021 Share Posted February 12, 2021 (edited) Hello, i attached a marker to a vehicle, and I have an onMarkerHit function on the marker that's attached to the vehicle, but whenever it changes position, like i drive the car somewhere else, the onMarkerHit only works where the vehicle was created. the Marker moved with the vehicle but its just the onMarkerHit, the marker on the vehicle does not work anymore, only where the marker was created the onmarkerhit works despite the marker moving with the vehicle. function createveh() testveh = createVehicle(456, -1497.548828125, 2576.759765625, 56.061462402344, 0, 0, 357.63516235352) setVehicleDamageProof(testveh,true) bx, by, bz = getElementPosition(testveh) testmarker = createMarker(bx, by, bz, "cylinder", 5.5, 0, 255, 0, 255) testmarker2 = createMarker(bx, by, bz, "cylinder", 10, 0, 255, 0, 255) attachElements(testmarker, testveh) attachElements(testmarker2, testveh) end addEventHandler("onResourceStart", resourceRoot, createveh) addEventHandler("onMarkerHit", resourceRoot, function(hitPlayer) if source == defusemarker then if hitPlayer and getElementType ( hitPlayer ) == 'player' then local theVehicle = getPedOccupiedVehicle(hitPlayer) if theVehicle then return end local playerTeam = getPlayerTeam ( hitPlayer ) if getPlayerTeam ( hitPlayer ) and getPlayerTeam ( hitPlayer ) == getTeamFromName("Red Team") then outputChatBox("Works", hitPlayer, 180, 0, 0, true) end end end end) EDIT: just noticed, that this is giving the problem since I have 2 markers attached to the vehicle, How do i make for the two of them to attach? is there anyway to attach 2 markers at a vehicle? I mean it's weird both markers go with the vehicle but only one works, the other one's location is stuck where it was created, but the marker itself was going with the vehicle. EX: i move the vehicle, i step in marker1 , it works, but when i step in marker 2, it doesnt, then when I go where the markers, vehicle was created, the marker 2 works, its stuck in the location where it was created. Edited February 12, 2021 by Shaman123 Link to comment
Bean666 Posted February 12, 2021 Author Share Posted February 12, 2021 (edited) the defusemarker is testmarker2 btw, sorry for bump. Edited February 12, 2021 by Shaman123 Link to comment
Bean666 Posted February 12, 2021 Author Share Posted February 12, 2021 (edited) Solved. EDIT: my bad, still not solved Edited February 12, 2021 by Shaman123 still not solved Link to comment
SpecT Posted February 12, 2021 Share Posted February 12, 2021 (edited) You can see here that there is an issue with attaching elements for the onMarkerHit event. The issue has been on for many years and yet it's still not fully solved. It still kinda works tho but only for 1 marker. I don't know what exactly you want to do with those markers but there could be other ways of achieving what's on your mind. Unfortunately you can't rely on this method if you want to attach 2 or more markers to a vehicle. EDIT: Nvm found a solution. Send both of the markers to the clients (after you create and attach them) and then manage the marker hit with onClientMarkerHit. Edited February 12, 2021 by SpecT Link to comment
Bean666 Posted February 12, 2021 Author Share Posted February 12, 2021 24 minutes ago, SpecT said: You can see here that there is an issue with attaching elements for the onMarkerHit event. The issue has been on for many years and yet it's still not fully solved. It still kinda works tho but only for 1 marker. I don't know what exactly you want to do with those markers but there could be other ways of achieving what's on your mind. Unfortunately you can't rely on this method if you want to attach 2 or more markers to a vehicle. EDIT: Nvm found a solution. Send both of the markers to the clients (after you create and attach them) and then manage the marker hit with onClientMarkerHit. I managed to create a solution but it's not so clean but can you please tell me how I can send both of them / what functions to use after creating them? it seems cleaner Thanks. Link to comment
SpecT Posted February 12, 2021 Share Posted February 12, 2021 (edited) Server: function createveh() testveh = createVehicle(500, -1497.548828125, 2576.759765625, 56.061462402344, 0, 0, 357.63516235352) setVehicleDamageProof(testveh,true) bx, by, bz = getElementPosition(testveh) testmarker = createMarker(bx, by, bz, "cylinder", 10, 0, 255, 0, 255) testmarker2 = createMarker(bx, by, bz, "cylinder", 5.5, 255, 0, 0, 255) attachElements(testmarker, testveh) attachElements(testmarker2, testveh) setTimer(function() -- using a timer to wait the client to load the script triggerClientEvent(root, "getMarkers", root, testmarker, testmarker2) end, 1000,1) end addEventHandler("onResourceStart", resourceRoot, createveh) Client: local testmarker local testmarker2 function getMarkers(marker1, marker2) testmarker = marker1 testmarker2 = marker2 end addEvent("getMarkers",true) addEventHandler("getMarkers", root, getMarkers) function markerHit() if source == testmarker then outputChatBox("just hit marker 1") elseif source == testmarker2 then outputChatBox("just hit marker 2") end end addEventHandler("onClientMarkerHit", root, markerHit) *This is just an example, could be done better Note: This is not so secure way to do it tho. Remember to not fully trust what the client sends! Edited February 12, 2021 by SpecT 1 Link to comment
Ayush Rathore Posted February 18, 2021 Share Posted February 18, 2021 You can make use of Col Shapes 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