bravo351 Posted December 8, 2009 Share Posted December 8, 2009 I am experiencing much fail in my latest mission script, where I'm trying to trigger the Point A to Point B with "onVehicleEnter". If any of you have 5 minutes to review this script, I'd appreciate any feedback you may have. --boat drug function Load ( name ) if name ~= getThisResource() then return else createObject ( 6300, 5003.75, -2586.6298828125, 10.101668357849 ) createObject ( 3620, 4979.0913085938, -2631.3962402344, 31.267587661743 ) createObject ( 3620, 4968.3295898438, -2588.1796875, 31.267587661743, 0, 0, 270.67498779297 ) createObject ( 3620, 5018.798828125, -2541.947265625, 31.267587661743, 0, 0, 177.37524414063 ) createObject ( 3620, 5023.5815429688, -2600.3518066406, 31.267587661743, 0, 0, 336.17370605469 ) createObject ( 3620, 4996.599609375, -2567.1616210938, 31.267587661743, 0, 0, 83.35986328125 ) createObject ( 3427, 4996.9228515625, -2605.7299804688, 18.185813903809 ) createObject ( 3256, 5011.9150390625, -2602.1533203125, 18.551418304443 ) createObject ( 3255, 4995.6938476563, -2553.3493652344, 18.156356811523 ) createObject ( 3255, 4995.6752929688, -2568.9877929688, 18.156356811523 ) createObject ( 3255, 4995.8032226563, -2584.6606445313, 18.156356811523 ) createObject ( 3258, 4996.9965820313, -2601.5166015625, -11.843643188477 ) createObject ( 1383, 5027.5815429688, -2619.6652832031, 50.680812835693 ) createObject ( 1384, 5027.7055664063, -2619.6687011719, 82.882995605469 ) createObject ( 3361, 4982.8603515625, -2580.0056152344, 16.143913269043, 0, 0, 98.434936523438 ) createObject ( 3361, 4981.9912109375, -2574.1572265625, 12.243919372559, 0, 0, 98.432006835938 ) createObject ( 3361, 4981.1274414063, -2568.2854003906, 8.268949508667, 0, 0, 98.432006835938 ) createObject ( 3361, 4980.2485351563, -2562.2912597656, 4.2439475059509, 0, 0, 98.432006835938 ) createObject ( 3361, 4979.3408203125, -2556.3525390625, 0.24394765496254, 0, 0, 98.432006835938 ) local drugboat = createVehicle ( 446, 4964.63, -2521.94, 1.92, 0, 0, 275 ) local destination = createBlip ( 4964.63, -2521.94, 0, 19, 2, 255, 0, 0, 255, 0, 99999.0 ) end end addEventHandler ( "onResourceStart", getRootElement(), Load ) function drugboatJob ( theDriver) local theDriver = getVehicleOccupant ( source, 0 ) if ( theDriver ) and ( source == drugboat ) then outputChatBox ("Deliver the drugs to the storehouse!.", theDriver, 255, 0, 0, false) theEndMarker = createMarker ( -1862.27, -1511.58, 0, "cylinder", 16, 0, 255, 0, 90, theDriver ) theEndBlip = createBlip ( -1862.27, -1511.58, 0, 53, 2, 255, 0, 0, 255, 0, 99999.0, theDriver ) end end addEventHandler ("onVehicleEnter", drugboat, drugboatJob) function drugboatJobEnd ( hitPlayer, matchingDimension ) theMarkerID = getElementID (theEndMarker) if (source == theEndMarker) then givePlayerMoney ( hitPlayer, 20000 ) destroyElement ( theEndMarker ) destroyElement ( theEndBlip ) respawnVehicle ( drugboat ) outputChatBox ( "You succeeded, and earned $20000 for your trouble!", hitPlayer, 255, 0, 0, false ) end end addEventHandler ("onMarkerHit", theEndMarker, drugboatJobEnd) function drugboatJobFailed ( theDriver ) removeEventHandler ("onMarkerHit", theEndMarker, drugboatJobEnd) local theDriver = getVehicleOccupant ( source, 0 ) destroyElement ( theEndMarker ) destroyElement ( theEndBlip ) respawnVehicle ( drugboat ) outputChatBox ( "You n00b.", theDriver, 0, 255, 255, false ) end addEventHandler("onVehicleExplode", drugboat, drugboatJobFailed) Any thoughts? I'm thinking my problem lies in Line 32. Link to comment
robhol Posted December 8, 2009 Share Posted December 8, 2009 How does one post 60 lines of code but no errors.. Link to comment
Remp Posted December 8, 2009 Share Posted December 8, 2009 your drugboat variable is local, so it doesnt exist in your drugboatJob function. It also doesnt exist when you add your onVehicleEnter event handler (anything outside a function is run as soon as the code is loaded). Make your vehicle and marker variables global and move your events inside the functions that define the variables they use: ... createObject ( 3361, 4979.3408203125, -2556.3525390625, 0.24394765496254, 0, 0, 98.432006835938 ) drugboat = createVehicle ( 446, 4964.63, -2521.94, 1.92, 0, 0, 275 ) destination = createBlip ( 4964.63, -2521.94, 0, 19, 2, 255, 0, 0, 255, 0, 99999.0 ) addEventHandler ("onVehicleEnter", drugboat, drugboatJob) -- move the event handler here end end addEventHandler ( "onResourceStart", getRootElement(), Load ) ... ... function drugboatJob ( thePlayer, seat) if ( thePlayer ) and ( seat == 0 ) and ( source == drugboat ) then outputChatBox ("Deliver the drugs to the storehouse!.", thePlayer, 255, 0, 0, false) theEndMarker = createMarker ( -1862.27, -1511.58, 0, "cylinder", 16, 0, 255, 0, 90, thePlayer ) theEndBlip = createBlip ( -1862.27, -1511.58, 0, 53, 2, 255, 0, 0, 255, 0, 99999.0, thePlayer ) addEventHandler ("onMarkerHit", theEndMarker, drugboatJobEnd) -- move the event handler here ... There should be no need to use getVehicleOccupant either as onVehicleEnter has player and seat parameters already try doing something like this instead: function drugboatJob ( thePlayer, seat) if ( thePlayer ) and ( seat == 0 ) and ( source == drugboat ) then outputChatBox ("Deliver the drugs to the storehouse!.", thePlayer, 255, 0, 0, false) ... you should always try debugging problems like this first, simply adding some outputChatBox lines at various points in the code will give you a better idea of where the problem lies and make solving it much easier Link to comment
eAi Posted December 8, 2009 Share Posted December 8, 2009 outputDebugString is perhaps a better choice for outputting debug messages. That way you can leave them in without disrupting player's chat. Link to comment
bravo351 Posted December 8, 2009 Author Share Posted December 8, 2009 R3mp, you are a saint. I got it working, even made it expandable. But there's still a few issues in the functionality (e.g., the finish marker can be stolen by anyone in the server who knows where it is, despite it not being visible to them on the radar). Here's the new code: --boat drug function Load ( name ) if name ~= getThisResource() then return else createObject ( 6300, 5003.75, -2586.6298828125, 10.101668357849 ) createObject ( 3620, 4979.0913085938, -2631.3962402344, 31.267587661743 ) createObject ( 3620, 4968.3295898438, -2588.1796875, 31.267587661743, 0, 0, 270.67498779297 ) createObject ( 3620, 5018.798828125, -2541.947265625, 31.267587661743, 0, 0, 177.37524414063 ) createObject ( 3620, 5023.5815429688, -2600.3518066406, 31.267587661743, 0, 0, 336.17370605469 ) createObject ( 3620, 4996.599609375, -2567.1616210938, 31.267587661743, 0, 0, 83.35986328125 ) createObject ( 3427, 4996.9228515625, -2605.7299804688, 18.185813903809 ) createObject ( 3256, 5011.9150390625, -2602.1533203125, 18.551418304443 ) createObject ( 3255, 4995.6938476563, -2553.3493652344, 18.156356811523 ) createObject ( 3255, 4995.6752929688, -2568.9877929688, 18.156356811523 ) createObject ( 3255, 4995.8032226563, -2584.6606445313, 18.156356811523 ) createObject ( 3258, 4996.9965820313, -2601.5166015625, -11.843643188477 ) createObject ( 1383, 5027.5815429688, -2619.6652832031, 50.680812835693 ) createObject ( 1384, 5027.7055664063, -2619.6687011719, 82.882995605469 ) createObject ( 3361, 4982.8603515625, -2580.0056152344, 16.143913269043, 0, 0, 98.434936523438 ) createObject ( 3361, 4981.9912109375, -2574.1572265625, 12.243919372559, 0, 0, 98.432006835938 ) createObject ( 3361, 4981.1274414063, -2568.2854003906, 8.268949508667, 0, 0, 98.432006835938 ) createObject ( 3361, 4980.2485351563, -2562.2912597656, 4.2439475059509, 0, 0, 98.432006835938 ) createObject ( 3361, 4979.3408203125, -2556.3525390625, 0.24394765496254, 0, 0, 98.432006835938 ) drugboat = createVehicle ( 446, 4964.63, -2521.94, 1, 0, 0, 244.87 ) destination = createBlip ( 4964.63, -2521.94, 0, 19, 2, 255, 0, 0, 255, 0, 99999.0 ) addEventHandler ("onVehicleEnter", drugboat, drugboatJob) end end addEventHandler ( "onResourceStart", getRootElement(), Load ) function drugboatJob ( thePlayer, seat ) if ( thePlayer ) and ( seat == 0 ) and ( source == drugboat ) then setPlayerWantedLevel ( thePlayer, 4 ) outputChatBox ("Deliver the drugs to the storehouse.", thePlayer, 255, 0, 0, false) theEndMarker = createMarker ( -1862.27, -1511.58, 0, "cylinder", 16, 0, 255, 0, 90, thePlayer ) theEndBlip = createBlip ( -1862.27, -1511.58, 0, 53, 2, 255, 0, 0, 255, 0, 99999.0, thePlayer ) addEventHandler ("onMarkerHit", theEndMarker, drugboatJobMarkerHit) end end function drugboatJobMarkerHit ( hitPlayer, matchingDimension ) theMarkerID = getElementID (theEndMarker) if (source == theEndMarker) then setPlayerWantedLevel ( hitPlayer, 6 ) givePlayerMoney ( hitPlayer, 20000 ) setTimer ( destroyElement, 2000, 1, theEndMarker ) setTimer ( destroyElement, 2000, 1, theEndBlip ) setTimer ( respawnVehicle, 5000, 1, drugboat ) drugvan = createVehicle ( 456, -1857.13, -1620.78, 23, 0, 0, 180 ) outputChatBox ( "Your storehouse is now loaded with coke!", hitPlayer, 255, 0, 0, false ) end end function drugboatJobFailed ( thePlayer ) destroyElement ( theEndMarker ) destroyElement ( theEndBlip ) setTimer ( respawnVehicle, 5000, 1, drugboat ) end addEventHandler("onVehicleExplode", drugboat, drugboatJobFailed) So the mission does work, but what can I do to tighten it and shore up the exploits? Line 48: When drugboat respawns in its original location, if the player has not exited the driver seat, they are teleported as well. If they get out and back in, they get the mission again (line 26). Link to comment
Wojak Posted December 8, 2009 Share Posted December 8, 2009 (e.g., the finish marker can be stolen by anyone in the server who knows where it is, despite it not being visible to them on the radar). to fix this problem your line 43 should look like this: if (source == theEndMarker) and (hitPlayer == getLocalPlayer() ) then Link to comment
Remp Posted December 8, 2009 Share Posted December 8, 2009 getLocalPlayer() only exists clientside and this is a serverside script the easiest way is probably to just check which vehicle is triggering the event (vehicles trigger onMarkerHit as well as players): function drugboatJobMarkerHit ( hitElement, matchingDimension ) theMarkerID = getElementID (theEndMarker) if (source == theEndMarker) and ( hitElement == drugboat ) then local hitPlayer = getVehicleOccupant(hitElement,0) if hitPlayer then setPlayerWantedLevel ( hitPlayer, 6 ) ... you can use removePedFromVehicle to force the player out of the vehicle before it respawns, and you could use setVehicleLocked in onPlayerVehicleExit if they get out voluntarily to stop them getting back in you will probably also want to watch out for people jacking the boat, or the player leaving the boat and/or dying mid-way through (perhaps automatically failing and resetting the mission if you leave the boat) 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