denny199 Posted August 17, 2011 Posted August 17, 2011 Hi there I've just has got getted an idea a automatic pilot =D but I IDK how to attach a object to an car: needs to add it server side or else i can't move it Server Side: vliegtuigenn = { [592]=true, [511]=true, [512]=true, [593]=true, [520]=true, [553]=true, [593]=true, [476]=true, [519]=true, [460]=true, [513]=true, [577]=true } addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in pairs(getElementsByType("player")) do bindKey(v,"b","down",autopiloot) end end) function autopiloot ( player ) local vliegtuig = getPedOccupiedVehicle(player) if ( vliegtuigenn[getElementModel(vliegtuig)] ) then triggerClientEvent ( "deGui", getRootElement(), vliegtuigen ) end end function moveLV ( player ) local car = getPedOccupiedVehicle(player) local object = createObject ( 980, 0, 0, 3 ) attachElements ( object, car ) moveObject ( object, 10000, 0, 0, 6 ) end addEvent( "LV", true ) addEventHandler( "LV", getRootElement(), moveLV ) Client Side: GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Memo = {} GUIEditor_Window[1] = guiCreateWindow(206,160,216,320,"Auto piloot",false) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) guiSetVisible (GUIEditor_Window[1],false) GUIEditor_Button[1] = guiCreateButton(15,32,192,29,"San Fiero Airport",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(15,80,192,29,"Las Venturas Airport",false,GUIEditor_Window[1]) GUIEditor_Button[3] = guiCreateButton(15,129,192,29,"Verdant Meadows Airport",false,GUIEditor_Window[1]) GUIEditor_Button[4] = guiCreateButton(15,178,192,29,"Los Santos Airport",false,GUIEditor_Window[1]) GUIEditor_Memo[1] = guiCreateMemo(13,224,194,87,"\nDeze Autopiloot script is gemaakt bij [DenR]Danny \n Heb veel plezier ermee \n zitten er bugs in gebruik dan /report",false,GUIEditor_Window[1]) function deGui() guiSetVisible (GUIEditor_Window[1],true) showCursor(true) end addEvent("deGui",true) addEventHandler("deGui",getRootElement(),deGui) addEvent("deGuiWeg",true) addEventHandler("deGuiWeg",getRootElement(), function () guiSetVisible(GUIEditor_Window[1],false) showCursor (false) end) function move () triggerServerEvent ( "LV", getLocalPlayer(), "LV" ) end function clicked (player, vehicle) if (source == GUIEditor_Button[2]) then player = getLocalPlayer () setTimer ( move, 1000, 1 ) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) outputChatBox ("Auto Piloot: Oke, U wordt naar Las Venturas Airport gebracht",225,225,0) elseif (source == GUIEditor_Button[1]) then outputChatBox ("Auto Piloot: Oke, U wordt naar San Fiero Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) elseif (source == GUIEditor_Button[3]) then outputChatBox ("Auto Piloot: Oke, U wordt naar Verdant Meadows Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) elseif (source == GUIEditor_Button[4]) then outputChatBox ("Auto Piloot: Oke, U wordt naar Los Santos Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) end end addEventHandler("onClientGUIClick",getRootElement(), clicked )
Axel Posted August 17, 2011 Posted August 17, 2011 U can use attachElements. # attachElements ( object, car,0,0,3.9 )
denny199 Posted August 17, 2011 Author Posted August 17, 2011 21.attachElements ( object, car ) U see that? ^^
TAPL Posted August 17, 2011 Posted August 17, 2011 function move () triggerServerEvent ( "LV", getLocalPlayer() ) end
JR10 Posted August 17, 2011 Posted August 17, 2011 (edited) server: vliegtuigenn = { [592]=true, [511]=true, [512]=true, [593]=true, [520]=true, [553]=true, [593]=true, [476]=true, [519]=true, [460]=true, [513]=true, [577]=true } addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), function () for i,v in pairs(getElementsByType("player")) do bindKey(v,"b","down",autopiloot) end end) function autopiloot ( player ) local vliegtuig = getPedOccupiedVehicle(player) if ( vliegtuigenn[getElementModel(vliegtuig)] ) then triggerClientEvent ( "deGui", getRootElement(), vliegtuigen ) end end function moveLV ( ) local car = getPedOccupiedVehicle ( source ) local object = createObject ( 980, 0, 0, 3 ) attachElements ( object, car ) moveObject ( object, 10000, 0, 0, 6 ) end addEvent( "LV", true ) addEventHandler( "LV", getRootElement(), moveLV ) client: GUIEditor_Window = {} GUIEditor_Button = {} GUIEditor_Memo = {} GUIEditor_Window[1] = guiCreateWindow(206,160,216,320,"Auto piloot",false) guiWindowSetMovable(GUIEditor_Window[1],false) guiWindowSetSizable(GUIEditor_Window[1],false) guiSetVisible (GUIEditor_Window[1],false) GUIEditor_Button[1] = guiCreateButton(15,32,192,29,"San Fiero Airport",false,GUIEditor_Window[1]) GUIEditor_Button[2] = guiCreateButton(15,80,192,29,"Las Venturas Airport",false,GUIEditor_Window[1]) GUIEditor_Button[3] = guiCreateButton(15,129,192,29,"Verdant Meadows Airport",false,GUIEditor_Window[1]) GUIEditor_Button[4] = guiCreateButton(15,178,192,29,"Los Santos Airport",false,GUIEditor_Window[1]) GUIEditor_Memo[1] = guiCreateMemo(13,224,194,87,"\nDeze Autopiloot script is gemaakt bij [DenR]Danny \n Heb veel plezier ermee \n zitten er bugs in gebruik dan /report",false,GUIEditor_Window[1]) function deGui() guiSetVisible (GUIEditor_Window[1],true) showCursor(true) end addEvent("deGui",true) addEventHandler("deGui",getRootElement(),deGui) addEvent("deGuiWeg",true) addEventHandler("deGuiWeg",getRootElement(), function () guiSetVisible(GUIEditor_Window[1],false) showCursor (false) end) function move () triggerServerEvent ( "LV", getLocalPlayer()) end function clicked (button) if (source == GUIEditor_Button[2]) then setTimer ( move, 1000, 1 ) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) outputChatBox ("Auto Piloot: Oke, U wordt naar Las Venturas Airport gebracht",225,225,0) elseif (source == GUIEditor_Button[1]) then outputChatBox ("Auto Piloot: Oke, U wordt naar San Fiero Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) elseif (source == GUIEditor_Button[3]) then outputChatBox ("Auto Piloot: Oke, U wordt naar Verdant Meadows Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) elseif (source == GUIEditor_Button[4]) then outputChatBox ("Auto Piloot: Oke, U wordt naar Los Santos Airport gebracht",225,225,0) guiSetVisible (GUIEditor_Window[1],false) showCursor (false) end end addEventHandler("onClientGUIClick",getRootElement(), clicked ) Edited August 17, 2011 by Guest
TAPL Posted August 17, 2011 Posted August 17, 2011 is this need ? i think no 37. player = getLocalPlayer ()
denny199 Posted August 18, 2011 Author Posted August 18, 2011 Well, it's working fine the attachment, but now it doesn't goes to the example place ( 0, 0, 6 ) Help? Ah, JR10 andTapl thnx for attaching
JR10 Posted August 18, 2011 Posted August 18, 2011 It's not moving, because, it's attached to the car. If it's not attached it will move. The way you are making this isn't working. I tried doing that before it didn't work.
arezu Posted August 18, 2011 Posted August 18, 2011 if you cant move object when its attached, then you can use: addEventHandler("onClientRender", getRootElement(), function() local objX, objY, objZ = getElementPosition(theObject) local vehicle = getPedOccupiedVehicle(theVehicle) setElementPosition(theVehicle, objX, objY, objZ) end) ...instead of attachElements btw, am i the only on who cant tab here?
denny199 Posted August 18, 2011 Author Posted August 18, 2011 btw, am i the only on who cant tab here? What do you mean exactly?
denny199 Posted August 19, 2011 Author Posted August 19, 2011 if you cant move object when its attached, then you can use: addEventHandler("onClientRender", getRootElement(), function() local objX, objY, objZ = getElementPosition(theObject) local vehicle = getPedOccupiedVehicle(theVehicle) setElementPosition(theVehicle, objX, objY, objZ) end) So... and how can I do this? I'm not realy good with onCleintRender, I never did it before so please help
arezu Posted August 19, 2011 Posted August 19, 2011 After the moveObject function in your server sided script, add a triggerClientEvent to add onClientRender event for the player, clientsided. also add a setTimer after moveObject servesided to remove the event handler for the player.. so that the vehicle is not attached to the vehicle anymore... example: -- server sided function moveLV ( ) local car = getPedOccupiedVehicle ( source ) local object = createObject ( 980, 0, 0, 3 ) moveObject ( object, 10000, 0, 0, 6 ) triggerClientEvent("onRequestChangeAttachementState", source, true, object) setTimer(removeAttachement, 10000, 1, source) end function removeAttachement(thePlayer) triggerClientEvent("onRequestChangeAttachementState", thePlayer, false) end --client sided local attachSource = nil addEvent("onRequestChangeAttachementState", true) addEventHandler("onRequestChangeAttachementState", getRootElement(), function(attach, theObject) if(source ~= getLocalPlayer())then return end attachSource = theObject if(attach)then addEventHandler("onClientRender", getRootElement(), attach) else removeEventHandler("onClientRender", getRootElement(), attach) end end) function attach() local vehicle = getPedOccupiedVehicle(getLocalPlayer()) if(vehicle == false)then return end local posX, posY, posZ = getElementPosition(attachSource) setElementPosition(vehicle, posX, posY, posZ) end i cant press tab here so it may be hard to read the code..
denny199 Posted August 20, 2011 Author Posted August 20, 2011 Tnx Arezu and the other, I had a mistake in attachElements, I need attach the vehicle to the object, now it ill move correct but tnx arezu for you fantastic help and the others ofcourse. Regards, Danny!
arezu Posted August 20, 2011 Posted August 20, 2011 oh.. lololo i didn't notice that you actually attached the object to the vehicle and tried to move the object .
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