myonlake Posted April 6, 2011 Share Posted April 6, 2011 (edited) Hello, I've been trying to drive a car on a moving ship, but when I move the ship, the car doesn't stay on it. I heard that you should make a marker and when you drive in it it attachs the car there. Well, it sounds easy, but I don't know where to start? Maybe from the marker? I am not sure about the detach, because I would like to do it that when you just drive in the marker it attaches it, when you type a command it detaches. So, does someone have a attach script already or can you help me with this? Okay so if anybody needs the WORKING script, here it is (thanks for everybody who helped me): arrow1 = createObject(1318, 0, 0, 3, 0, 0, 0) theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 0 ) -- the last 0 is the Alpha ( 255 = full visible, 0 = invisible ) function attach ( hitElement ) if ( getElementType( hitElement ) == "vehicle" ) then attachElements ( hitElement, arrow1 ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local pVehicle = getPedOccupiedVehicle( thePlayer ) detachElements ( pVehicle ) end addCommandHandler ( "detach", detach ) Edited May 30, 2019 by myonlake Link to comment
Moderators Citizen Posted April 6, 2011 Moderators Share Posted April 6, 2011 You need those functions/events: onMarkerHit attachElements addCommandHandler detachElements But the problem with the attachElements, is to find the correct Offsets ! So see this page to fix the problem Link to comment
myonlake Posted April 7, 2011 Author Share Posted April 7, 2011 You need those functions/events: onMarkerHit attachElements addCommandHandler detachElements But the problem with the attachElements, is to find the correct Offsets ! So see this page to fix the problem Hello, Thanks for your help for now, but please do not laugh at my script if it looks like nothing working in it... So this is how far I am now. It creates a marker to the center of the map (the farm at 0,0,3), but it doesn't attach vehicles. It just tells me that lines 5 and 6 have errors like: "Bad Argument @ 'getPedOccupiedVehicle'" "Bad Argument @ 'attachElements'" local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local vehicle = getPedOccupiedVehicle ( vehicle ) attachElements ( vehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( vehicle, source ) end addCommandHandler ( "detach", detach ) So, can someone help me? Have I missed something? Link to comment
Kenix Posted April 7, 2011 Share Posted April 7, 2011 You need those functions/events: onMarkerHit attachElements addCommandHandler detachElements But the problem with the attachElements, is to find the correct Offsets ! So see this page to fix the problem Hello, Thanks for your help for now, but please do not laugh at my script if it looks like nothing working in it... So this is how far I am now. It creates a marker to the center of the map (the farm at 0,0,3), but it doesn't attach vehicles. It just tells me that lines 5 and 6 have errors like: "Bad Argument @ 'getPedOccupiedVehicle'" "Bad Argument @ 'attachElements'" local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local vehicle = getPedOccupiedVehicle ( vehicle ) attachElements ( vehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( vehicle, source ) end addCommandHandler ( "detach", detach ) So, can someone help me? Have I missed something? try this local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local Pvehicle = getPedOccupiedVehicle ( vehicle ) attachElements ( Pvehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( Pvehicle, source ) end addCommandHandler ( "detach", detach ) Link to comment
myonlake Posted April 7, 2011 Author Share Posted April 7, 2011 You need those functions/events: onMarkerHit attachElements addCommandHandler detachElements But the problem with the attachElements, is to find the correct Offsets ! So see this page to fix the problem Hello, Thanks for your help for now, but please do not laugh at my script if it looks like nothing working in it... So this is how far I am now. It creates a marker to the center of the map (the farm at 0,0,3), but it doesn't attach vehicles. It just tells me that lines 5 and 6 have errors like: "Bad Argument @ 'getPedOccupiedVehicle'" "Bad Argument @ 'attachElements'" local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local vehicle = getPedOccupiedVehicle ( vehicle ) attachElements ( vehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( vehicle, source ) end addCommandHandler ( "detach", detach ) So, can someone help me? Have I missed something? try this local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local Pvehicle = getPedOccupiedVehicle ( vehicle ) attachElements ( Pvehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( Pvehicle, source ) end addCommandHandler ( "detach", detach ) It doesn't work either. Same error coming up: "Bad Argument @ 'getPedOccupiedVehicle'" "Bad Argument @ 'attachElements'" Link to comment
Castillo Posted April 7, 2011 Share Posted April 7, 2011 local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local Pvehicle = getPedOccupiedVehicle ( getVehicleOccupant(hitElement) ) attachElements ( Pvehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( Pvehicle, source ) end addCommandHandler ( "detach", detach ) Not tested. Link to comment
myonlake Posted April 7, 2011 Author Share Posted April 7, 2011 local theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement ) if (getElementType(hitElement) == "vehicle" ) then local Pvehicle = getPedOccupiedVehicle ( getVehicleOccupant(hitElement) ) attachElements ( Pvehicle, theMarker ) elseif (getElementType(hitElement) == "player" ) then outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach () local attachedElements = getAttachedElements ( source ) detachElements ( Pvehicle, source ) end addCommandHandler ( "detach", detach ) Not tested. Yeah, it doesn't work either. It still whines about the 5 and 6 lines. Link to comment
CowTurbo Posted April 7, 2011 Share Posted April 7, 2011 theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) -- maybe remove that 'local' thing ? not sure function attach ( hitElement, matchingDim ) if ( isPedInVehicle ( hitElement)) then local Pvehicle = getpedOccupiedVehicle ( hitElement ) attachElements ( Pvehicle, theMarker ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach (thePlayer, commandName) local attachedElements = getAttachedElements ( getPedOccupiedVehicle ( thePlayer )) -- why was here source ? detachElements ( Pvehicle, attachedElements ) -- why was here source too? end addCommandHandler ( "detach", detach ) if i was sure then someone in the irc chat told me that getElementType on corona marker hit doesnt work or something like that.. maybe now it works ? Link to comment
myonlake Posted April 7, 2011 Author Share Posted April 7, 2011 theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement, matchingDim ) if ( isPedInVehicle ( hitElement)) then local Pvehicle = getpedOccupiedVehicle ( hitElement ) attachElements ( Pvehicle, theMarker ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach (thePlayer, commandName) local attachedElements = getAttachedElements ( getPedOccupiedVehicle ( thePlayer )) detachElements ( Pvehicle, attachedElements ) end addCommandHandler ( "detach", detach ) if i was sure then someone in the irc chat told me that getElementType on corona marker hit doesnt work or something like that.. maybe now it works ? Hello, It doesn't work, but looks better. I fixed some typos there. Errors: on line 4: Bad 'ped' pointer @ 'isPedInVehicle'(1) on line 15: Bad argument @ 'detachElements' EDIT: Would freeze/unfreeze work as good as attaching the element? theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement, matchingDim ) if ( isPedInVehicle ( hitElement )) then local Pvehicle = getPedOccupiedVehicle ( hitElement ) attachElements ( Pvehicle, theMarker ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local attachedElements = getAttachedElements ( getPedOccupiedVehicle ( thePlayer )) detachElements ( Pvehicle, attachedElements ) end addCommandHandler ( "detach", detach ) Link to comment
Moderators Citizen Posted April 7, 2011 Moderators Share Posted April 7, 2011 theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement, matchingDim ) if ( getElementType( hitElement ) == "vehicle" ) then -- if the element is a vehicle attachElements ( hitElement, source ) -- attach the element ( the vehicle ) to the marker hited ( the source is the marker hited ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local Pvehicle = getPedOccupiedVehicle( thePlayer ) -- we get the player's vehicle detachElements ( pVehicle ) -- the second argument is not compulsory end addCommandHandler ( "detach", detach ) Link to comment
myonlake Posted April 7, 2011 Author Share Posted April 7, 2011 theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 255 ) function attach ( hitElement, matchingDim ) if ( getElementType( hitElement ) == "vehicle" ) then -- if the element is a vehicle attachElements ( hitElement, source ) -- attach the element ( the vehicle ) to the marker hited ( the source is the marker hited ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local Pvehicle = getPedOccupiedVehicle( thePlayer ) -- we get the player's vehicle detachElements ( pVehicle ) -- the second argument is not compulsory end addCommandHandler ( "detach", detach ) Doesn't work either. But now it doesn't give me any errors either, lol. Are we missing something? Link to comment
Moderators Citizen Posted April 9, 2011 Moderators Share Posted April 9, 2011 Ok I made some test, and you can't attach a vehicle to a marker but you can attach a marker to a vehicle so try to attach the vehicle to your boat Link to comment
myonlake Posted April 9, 2011 Author Share Posted April 9, 2011 Ok I made some test, and you can't attach a vehicle to a marker but you can attach a marker to a vehicle so try to attach the vehicle to your boat Alright. I used the same script but changed the marker as an arrow object 1318. It doesn't work yet, can you look if I missed something? arrow1 = createObject(1318, 0, 0, 3, 0, 0, 0) function attach ( hitElement ) if ( getElementType( hitElement ) == "vehicle" ) then attachElements ( hitElement, arrow1 ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "hitElement", arrow1, attach ) function detach ( thePlayer, commandName ) local Pvehicle = getPedOccupiedVehicle( thePlayer ) detachElements ( pVehicle ) end addCommandHandler ( "detach", detach ) Something like this? Link to comment
Moderators Citizen Posted April 9, 2011 Moderators Share Posted April 9, 2011 addEventHandler ( "hitElement", arrow1, attach ) What the hell ?! See this before: onMarkerHit Keep the marker, because it's the marker ( invisible if you want ) which detects a player or a vehicle: arrow1 = createObject(1318, 0, 0, 3, 0, 0, 0) theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 0 ) -- the last 0 is the Alpha ( 255 = full visible, 0 = invisible ) function attach ( hitElement ) if ( getElementType( hitElement ) == "vehicle" ) then attachElements ( hitElement, arrow1 ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local pVehicle = getPedOccupiedVehicle( thePlayer ) detachElements ( pVehicle ) end addCommandHandler ( "detach", detach ) Link to comment
myonlake Posted April 10, 2011 Author Share Posted April 10, 2011 What the hell ?! See this before: onMarkerHitKeep the marker, because it's the marker ( invisible if you want ) which detects a player or a vehicle: arrow1 = createObject(1318, 0, 0, 3, 0, 0, 0) theMarker = createMarker ( 0, 0, 3, "cylinder", 5, 255, 255, 255, 0 ) -- the last 0 is the Alpha ( 255 = full visible, 0 = invisible ) function attach ( hitElement ) if ( getElementType( hitElement ) == "vehicle" ) then attachElements ( hitElement, arrow1 ) else outputChatBox ( "Only vehicles can be attached here" ) end end addEventHandler ( "onMarkerHit", theMarker, attach ) function detach ( thePlayer, commandName ) local pVehicle = getPedOccupiedVehicle( thePlayer ) detachElements ( pVehicle ) end addCommandHandler ( "detach", detach ) It works! Thanks all of you! Link to comment
Moderators Citizen Posted April 10, 2011 Moderators Share Posted April 10, 2011 No 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