xpnd Posted January 16, 2017 Share Posted January 16, 2017 (edited) function seatRumpo(theVehicle, seat, jacked) if(getElementModel(theVehicle) == 440 and getTeamName(getPlayerTeam(source)) ~= "Водители") then local x, y, z = getElementPosition(theVehicle) id = getElementModel(source) spawnPlayer(source, x-1, y-2, z, 90, id) setCameraTarget(source, source) outputChatBox("У вас нет прав для доступа в данное транспортное средство", source) elseif (getElementModel(theVehicle) == 440 and getTeamName(getPlayerTeam(source)) == "Водители") then outputChatBox("Начинаем работу", source) mark1 = createMarker(1104.0576171875, -1740.830078125, 11.5, "cylinder", 8, 255, 69, 0, 150) function mark1Func() if isElement(mark1) then destroyElement(mark1) end mark2 = createMarker(1167.412109375, -1741.021484375, 11.5, "cylinder", 8, 255, 69, 0, 150) end function mark2Func(source) if isElement(mark2) then destroyElement(mark2) end outputChatBox("Вы прибыли в точку назначения!", source) end addEventHandler("onMarkerHit", mark1, mark1Func) addEventHandler("onMarkerHit", mark2, mark2Func) end end addEventHandler("onPlayerVehicleEnter", getRootElement(), seatRumpo) I have 2 markers: mark1 and mark2. I need to delete marker, when player hit it. When I hit marker1, marker disappears, but when I hit marker2, nothing happens. WARNING: work/server.lua:20: Bad argument @ 'addEventHandler' [Expected element at argument 2, got nil] Edited January 16, 2017 by xpnd added isElement, warning with destoyElement disappeared Link to comment
ViRuZGamiing Posted January 16, 2017 Share Posted January 16, 2017 function mark1Func() if isElement(mark1) then destroyElement(mark1) end mark2 = createMarker(1167.412109375, -1741.021484375, 11.5, "cylinder", 8, 255, 69, 0, 150) addEventHandler("onMarkerHit", mark2, mark2Func) end place your event handler in the scope of your variable 1 Link to comment
xpnd Posted January 16, 2017 Author Share Posted January 16, 2017 17 minutes ago, ViRuZGamiing said: function mark1Func() if isElement(mark1) then destroyElement(mark1) end mark2 = createMarker(1167.412109375, -1741.021484375, 11.5, "cylinder", 8, 255, 69, 0, 150) addEventHandler("onMarkerHit", mark2, mark2Func) end place your event handler in the scope of your variable outputChatBox works, but mark2 doesn't disappear Link to comment
ViRuZGamiing Posted January 16, 2017 Share Posted January 16, 2017 because destroyElement(mark2) can't find mark2, write local mark2 in top of the script Link to comment
xpnd Posted January 17, 2017 Author Share Posted January 17, 2017 15 hours ago, ViRuZGamiing said: because destroyElement(mark2) can't find mark2, write local mark2 in top of the script Add local to mark2 local mark2 = createMarker(1167.412109375, -1741.021484375, 11.5, "cylinder", 8, 255, 69, 0, 150) or write local mark2 on first line of the script? I tried both of them, but result didn't change Link to comment
Moderators IIYAMA Posted January 17, 2017 Moderators Share Posted January 17, 2017 (edited) local missionData = {} function mark1Func(hitElement) if getElementType(hitElement) == "player" and missionData[hitElement] then local playerMissionData = missionData[hitElement] removeEventHandler("onMarkerHit", source, mark1Func) playerMissionData.mark1 = nil; local mark2 = createMarker(1167.412109375, -1741.021484375, 11.5, "cylinder", 8, 255, 69, 0, 150) playerMissionData.mark2 = mark2 addEventHandler("onMarkerHit", mark2, mark2Func) if isElement(source) then destroyElement(source) end end end function mark2Func(hitElement) if getElementType(hitElement) == "player" and missionData[hitElement] then local playerMissionData = missionData[hitElement] removeEventHandler("onMarkerHit", source, mark2Func) if isElement(source) then destroyElement(source) end missionData[hitElement] = nil -- clean up outputChatBox("Вы прибыли в точку назначения!", hitElement) -- finished? Can't read this... end end addEventHandler("onPlayerQuit", root, function () local playerMissionData = missionData[source] if playerMissionData then if isElement(playerMissionData.mark1) then removeEventHandler("onMarkerHit", playerMissionData.mark1, mark1Func) destroyElement(playerMissionData.mark1) end if isElement(playerMissionData.mark2) then removeEventHandler("onMarkerHit", playerMissionData.mark2, mark2Func) destroyElement(playerMissionData.mark2) end missionData[source] = nil end end) function seatRumpo(theVehicle, seat, jacked) if(getElementModel(theVehicle) == 440 and getTeamName(getPlayerTeam(source)) ~= "Водители") then local x, y, z = getElementPosition(theVehicle) local id = getElementModel(source) spawnPlayer(source, x-1, y-2, z, 90, id) setCameraTarget(source, source) outputChatBox("У вас нет прав для доступа в данное транспортное средство", source) elseif (getElementModel(theVehicle) == 440 and getTeamName(getPlayerTeam(source)) == "Водители") then outputChatBox("Начинаем работу", source) local mark1 = createMarker(1104.0576171875, -1740.830078125, 11.5, "cylinder", 8, 255, 69, 0, 150) missionData[source] = { mark1 = mark1--, -- you can add more data here for the mission } addEventHandler("onMarkerHit", mark1, mark1Func) end end addEventHandler("onPlayerVehicleEnter", getRootElement(), seatRumpo) Not tested. ALSO it doesn't work for multiple players at the same time yet. You will have to spend more time on it to fix that. (this is all I am doing for now) This will be the next step to improve your script: https://wiki.multitheftauto.com/wiki/SetElementVisibleTo Edited January 17, 2017 by IIYAMA 1 Link to comment
xpnd Posted January 17, 2017 Author Share Posted January 17, 2017 Thank you all for help, i solved my problem. 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