Baseplate Posted July 30, 2013 Share Posted July 30, 2013 I need some little help with this code, when I hit the marker, nothing happens. c.lua function startJob() local id = getElementModel(source) if (id == 403) or (id == 515) or (id == 456) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) end end addEventHandler("onClientVehicleEnter", root, startJob) addEventHandler("onClientMarkerHit", root, function(hitElement, matchingDimension) if (isPedInVehicle(hitElement)) and (getElementType(hitElement) == "vehicle") and (source == jobMarker) then local car = getElementModel(hitElement) if (car == 403) or (car == 515) or (car == 514) then triggerServerEvent("payTrucker", localPlayer) if isElement(jobMarker) then destroyElement(jobMarker) end if isElement(jobBlip) then destroyElement(jobBlip) end startJob() end end end ) s.lua addEvent("payTrucker", true) addEventHandler ("payTrucker", root, function() money = math.random(350, 1020) givePlayerMoney(source, money) outputChatBox("You succesfully delivered the goods and got $" ..money, source, 0, 255, 0 ) fadeCamera(source, false) setTimer ( fadeCamera, 5000, 1, source, true, 0.5 ) end ) function onlyForMe(marker, blip) setElementVisibleTo(marker, source, true) setElementVisibleTo(marker, getRootElement(), false) -- setElementVisibleTo(blip, source, true) setElementVisibleTo(blip, getRootElement(), false) end addEvent("visibleTruck", true) addEventHandler("visibleTruck", root, onlyForMe) Link to comment
DNL291 Posted July 30, 2013 Share Posted July 30, 2013 Try removing: (getElementType(hitElement) == "vehicle") Link to comment
Baseplate Posted July 30, 2013 Author Share Posted July 30, 2013 I want it to hit the vehicle while being in a veh which has an id from the ones specified in the script. Link to comment
xXMADEXx Posted July 30, 2013 Share Posted July 30, 2013 You can try this: function startJob ( p ) local id = getElementModel(source) if ( p == localPlayer ) and (id == 403) or (id == 515) or (id == 456) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) addEventHandler("onClientMarkerHit", jobMarker, function ( p ) if ( p and getElementType ( p ) == "vehicle" ) then local id = getElementModel ( p ) if ( id == 403 or id == 515 or id == 514 ) then local driver = getVehicleOccupant ( p ) triggerServerEvent("payTrucker", driver) destroyElement ( source ) if ( isElement ( jobBlip ) ) then destroyElement ( jobBlip ) end end end end ) end end addEventHandler("onClientVehicleEnter", root, startJob) Link to comment
Blaawee Posted July 30, 2013 Share Posted July 30, 2013 Where is the 'unpackMarkers' function ? Link to comment
Baseplate Posted July 30, 2013 Author Share Posted July 30, 2013 I didn't give the full code, the marker and blip shows up, but when I hit the marker nothing happens. Link to comment
aim-killer Posted July 30, 2013 Share Posted July 30, 2013 onClientMarkerHit is triggered when a player enters a marker not a vehicle. onClientMarkerHit player hitPlayer, bool matchingDimension you tried to get ElementModel using hitElement which is not a vehicle..and no need of (getElementType(hitElement) == "vehicle") because isPedinVehicle will be true only if the player is in a vehicle... i think it will work now .. function startJob() local id = getElementModel(source) if (id == 403) or (id == 515) or (id == 456) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) end end addEventHandler("onClientVehicleEnter", root, startJob) addEventHandler("onClientMarkerHit", root, function(hitElement, matchingDimension) if (isPedInVehicle(hitElement)) and (source == jobMarker) then local vehicle = getPedOccupiedVehicle(hitElement) local car = getElementModel(vehicle) if (car == 403) or (car == 515) or (car == 514) then triggerServerEvent("payTrucker", localPlayer) if isElement(jobMarker) then destroyElement(jobMarker) end if isElement(jobBlip) then destroyElement(jobBlip) end startJob() end end end ) Link to comment
Baseplate Posted July 30, 2013 Author Share Posted July 30, 2013 Another problem, when I hit the marker I want it to trigger startJob() function, but nothing happens. Link to comment
aim-killer Posted July 31, 2013 Share Posted July 31, 2013 addEvent("StartJobTrigger",true) addEventHandler("StartJobTrigger",root,startJob) this after the function and then triggerEvent bool triggerEvent ( string eventName, element baseElement, [ var argument1, ... ] ) Link to comment
Baseplate Posted July 31, 2013 Author Share Posted July 31, 2013 Tried doing that before, but same problem function startJob() local id = getElementModel(source) if (id == 403) or (id == 515) or (id == 514) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) end end addEventHandler("onClientVehicleEnter", root, startJob) addEvent("StartJobTrigger",true) addEventHandler("StartJobTrigger",root,startJob) addEventHandler("onClientMarkerHit", root, function(hitElement, matchingDimension) if (isPedInVehicle(hitElement)) and (source == jobMarker) then local vehicle = getPedOccupiedVehicle(hitElement) local car = getElementModel(vehicle) if (car == 403) or (car == 515) or (car == 514) then triggerServerEvent("payTrucker", localPlayer) theVehicle = vehicle if isElement(jobMarker) then destroyElement(jobMarker) end if isElement(jobBlip) then destroyElement(jobBlip) end triggerEvent("StartJobTrigger", localPlayer) end end end ) Link to comment
Wei Posted July 31, 2013 Share Posted July 31, 2013 Source is not defined if you startJob function as startJob()ž Try that: function startJob() if (isElement(source)) then local id = getElementModel(source) if (id == 403) or (id == 515) or (id == 456) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) end else if getPedOccupiedVehicle(localPlayer) then local id = getElementModel(getPedOccupiedVehicle(localPlayer) ) if (id == 403) or (id == 515) or (id == 456) then local x, y, z = unpackMarkers() jobMarker = createMarker(x, y, z, "cylinder", 4, 255, 255, 0, 255) jobBlip = createBlipAttachedTo(jobMarker, 41) triggerServerEvent("visibleTruck", getLocalPlayer(), jobMarker, jobBlip) end end end end addEventHandler("onClientVehicleEnter", root, startJob) addEventHandler("onClientMarkerHit", root, function(hitElement, matchingDimension) if (isPedInVehicle(hitElement)) and (source == jobMarker) then local vehicle = getPedOccupiedVehicle(hitElement) local car = getElementModel(vehicle) if (car == 403) or (car == 515) or (car == 514) then triggerServerEvent("payTrucker", localPlayer) if isElement(jobMarker) then destroyElement(jobMarker) end if isElement(jobBlip) then destroyElement(jobBlip) end startJob() end end 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