carvalhosgamer Posted May 21, 2014 Share Posted May 21, 2014 Hello guys, i tried all night to understand my code about CreateVehicle, i'm working with Server Script, CreateVehicle and Warp, well, i want to make the localplayer create own vehicle, now, i have a problem i create my car, but the other guy creates his car then my car destroy. please hep me! thats my code: --Server Side marker = createMarker(.....) function CreateVeh(thePlayer) if (thePlayer) then heli = createVehicle( 425, 234, 1967, 17, 0,0, 90) warpPedIntoVehicle(thePlayer, heli, 0 , true) end end addEventHandler("onMarkerHit" , marker, CreateVeh) PLEASE HELP ME! THANKS! Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 how, have any example on wiki, thanks i'm noob with Lua Link to comment
justn Posted May 21, 2014 Share Posted May 21, 2014 So, when the other player hits the marker , your vehicle destroys ? If yes then try defining the variable 'heli' locally and not globally. local heli = createVehicle( 425, 234, 1967, 17, 0,0, 90) //EDIT: Sorry If I have misread what you were trying to say, Just don't understand your english very well Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 ok.. but, if i need destroy this car later? in other function? may i? Thank you! Link to comment
justn Posted May 21, 2014 Share Posted May 21, 2014 You can set a timer to destroy the vehicle when the player exits the vehicle, and when he enters again, kill the timer. Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 variable heli in local works? Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 thank you for your attention!! and sorry my English its not too good yet Link to comment
justn Posted May 21, 2014 Share Posted May 21, 2014 You're welcome and If you have problems, then you can post your code. and If I'm online then maybe I can fix it for you. Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 ok, thanks, I appreciate! Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 lol, Problem man... look this: MarcadorBus1Car = createMarker(..) addEventHandler("onMarkerHit" , MarcadorBus1Car, function(thePlayer) if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then local busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) warpPedIntoVehicle(thePlayer, busao, 0 , true) end end --///////////////////////////////////////// function qndSairBus1(thePlayer) if (thePlayer) then if getElementModel(source) == 431 then desBus1 = setTimer(destroiBus1, 5000, 1) end end end addEventHandler("onVehicleExit" , rootElement, qndSairBus1) function destroiBus1() if isElement(busao) then destroyElement(busao) end end The vehicle not destroy with local variable... helpe me please Link to comment
justn Posted May 21, 2014 Share Posted May 21, 2014 Try this MarcadorBus1Car = createMarker(..) addEventHandler("onMarkerHit" , MarcadorBus1Car, function(thePlayer) if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) warpPedIntoVehicle(thePlayer, busao, 0 , true) end end) function qndSairBus1(vehicle,seat) if seat == 0 then if getElementModel(source) == 431 then desBus1 = setTimer(destroiBus1, 5000, 1) end end end addEventHandler("onVehicleExit" , getRootElement(), qndSairBus1) function qndSairBus2(vehicle,seat) if seat == 0 or seat == 1 or seat == 2 or seat == 3 or seat == 4 then if getElementModel(source) == 431 then killTimer(desBus1) end end end addEventHandler("onVehicleEnter" , getRootElement(), qndSairBus2) function destroiBus1() if isElement(busao) then destroyElement(busao) end end Link to comment
</Mr.Tn6eL> Posted May 21, 2014 Share Posted May 21, 2014 Try this MarcadorBus1Car = createMarker(..) addEventHandler("onMarkerHit" , MarcadorBus1Car, function(thePlayer) if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) then busao = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) warpPedIntoVehicle(thePlayer, busao, 0 , true) end end) function qndSairBus1(vehicle,seat) if seat == 0 then if getElementModel(source) == 431 then desBus1 = setTimer(destroiBus1, 5000, 1) end end end addEventHandler("onVehicleExit" , getRootElement(), qndSairBus1) function qndSairBus2(vehicle,seat) if seat == 0 or seat == 1 or seat == 2 or seat == 3 or seat == 4 then if getElementModel(source) == 431 then killTimer(desBus1) end end end addEventHandler("onVehicleEnter" , getRootElement(), qndSairBus2) function destroiBus1() if isElement(busao) then destroyElement(busao) end end Fix your code MarcadorBus1Car = createMarker(x, y, z, "cylinder", 1.5, 255, 0, 0, 255) busao = { } desBus1 = { } function(thePlayer) if getElementType(thePlayer) == "player" and not getPedOccupiedVehicle(thePlayer) and source == MarcadorBus1Car then if isElement(busao[thePlayer]) then destroyElement(busao[thePlayer]) end busao[thePlayer] = createVehicle( 431, 1271, -1822, 13.5, 0,0, 175) warpPedIntoVehicle(thePlayer, busao[thePlayer], 0 ) end end function Exit(vehicle,seat) if seat == 0 then if getElementModel(source) == 431 then desBus1[vehicle] = setTimer(destroiBus1, 5000, 1, vehicle) end end end function Enter(vehicle) if getElementModel(source) == 431 then killTimer(desBus1[vehicle]) end end function destroiBus1(plr) if isElement(busao[plr]) then destroyElement(busao[plr]) end end addEventHandler("onMarkerHit", resourceRoot, Hit) addEventHandler("onVehicleExit", root, Exit) addEventHandler("onVehicleEnter", root, Enter) Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 I tried this code, works perfectly, thank you!, but i have another problem with my code. i want to make one time the event, for example the player enters into the car , do something and get the car again do other things I have functions on "onVehicleEnter" look my code: function playerEnter(thePlayer) if getElementModel(source) == 431 then // Do Something one time end end addEventHandler("onVehicleEnter" , getRootElement(), playerEnter) thnaks Link to comment
Chronic Posted May 21, 2014 Share Posted May 21, 2014 for example the player enters into the car , do something and get the car again do other things Can you explain this better? Link to comment
carvalhosgamer Posted May 21, 2014 Author Share Posted May 21, 2014 ok, theplayer got a car, the handler "onVehicleEnter" do something, for example outputChatBox("Text 1" ), ok, the player out of his vehicle and enter the his vehicle again, the handler do something new for example outputChatBox("Text 2" ) , thanks Link to comment
Arnold-1 Posted May 21, 2014 Share Posted May 21, 2014 or just use this: setElementData(thePlayer,"VEHICLE",createVehicle(...)) destroyElement(getElementData(thePlayer,"VEHICLE") 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