#RooTs Posted January 31, 2016 Share Posted January 31, 2016 (edited) because when the vehicle of a player blows my neon is reset? addEventHandler("onClientVehicleExplode", getRootElement(), function() -- or root, or getLocalPlayer setElementData( localPlayer, "neon", 0 ) -- Zerar local theVehicle = getPedOccupiedVehicle ( localPlayer ) triggerServerEvent ("detachNeon", getLocalPlayer(), theVehicle) end) Edited February 3, 2016 by Guest Link to comment
#RooTs Posted January 31, 2016 Author Share Posted January 31, 2016 I want the neon is destroyed when the vehicle explode. I tried in many ways. but did not succeed..... function detachNeon( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) for i,v in ipairs ( attachedElements ) do detachElements ( v, theVehicle ) destroyElement ( v ) end end addEventHandler( "onPlayerVehicleExit", getRootElement(), detachNeon ) addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) function onPlayerQuit() local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local getNeonType = getElementData(source, "neon") if ( getNeonType ) then setAccountData ( playeraccount, "neon", getNeonType) local theVehicle = getPedOccupiedVehicle ( source ) if ( getNeonType ~= 0 ) and ( theVehicle ) then detachNeon( theVehicle ) end end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local getNeonTypeAccData = getAccountData ( playeraccount, "neon" ) if ( getNeonTypeAccData ~= 0 ) then setElementData(source, "neon", getNeonTypeAccData) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) Link to comment
KariiiM Posted January 31, 2016 Share Posted January 31, 2016 When the vehicle explode or when the player quit? Link to comment
#RooTs Posted January 31, 2016 Author Share Posted January 31, 2016 When the vehicle explode or when the player quit? When the vehicle explode Link to comment
KariiiM Posted January 31, 2016 Share Posted January 31, 2016 I want the neon is destroyed when the vehicle explode. I tried in many ways. but did not succeed..... Try that, it may works and tell me the result --client side addEventHandler("onClientVehicleExplode", getRootElement(), function() -- or root, or getLocalPlayer setElementData( localPlayer, "neon", 0 ) -- Zerar local theVehicle = getPedOccupiedVehicle ( localPlayer ) triggerServerEvent ("detachNeon", getLocalPlayer(), theVehicle) end) --server side local neons = {} function detachNeon( theVehicle ) for index, v in pairs(neons[theVehicle]) do if v and isElement(v) then destroyElement(v) end end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) function onPlayerQuit() local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local getNeonType = getElementData(source, "neon") if ( getNeonType ) then setAccountData ( playeraccount, "neon", getNeonType) local theVehicle = getPedOccupiedVehicle ( source ) if ( getNeonType ~= 0 ) and ( theVehicle ) then detachNeon( theVehicle ) end end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local getNeonTypeAccData = getAccountData ( playeraccount, "neon" ) if ( getNeonTypeAccData ~= 0 ) then setElementData(source, "neon", getNeonTypeAccData) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) Link to comment
#RooTs Posted January 31, 2016 Author Share Posted January 31, 2016 add "onPlayerVehicleExit" pls Link to comment
#RooTs Posted January 31, 2016 Author Share Posted January 31, 2016 Is my code worked? not tested yet, but I noticed that removed the event "onPlayerVehicleExit" Link to comment
KariiiM Posted January 31, 2016 Share Posted January 31, 2016 --client side addEventHandler("onClientVehicleExplode", getRootElement(), function() -- or root, or getLocalPlayer setElementData( localPlayer, "neon", 0 ) -- Zerar local theVehicle = getPedOccupiedVehicle ( localPlayer ) triggerServerEvent ("detachNeon", getLocalPlayer(), theVehicle) end) --server side local neons = {} function detachNeon( theVehicle ) for index, v in pairs(neons[theVehicle]) do if v and isElement(v) then destroyElement(v) end end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) addEventHandler( "onPlayerVehicleExit", getRootElement(), detachNeon ) function onPlayerQuit() local playeraccount = getPlayerAccount ( source ) if ( playeraccount ) and not isGuestAccount ( playeraccount ) then local getNeonType = getElementData(source, "neon") if ( getNeonType ) then setAccountData ( playeraccount, "neon", getNeonType) local theVehicle = getPedOccupiedVehicle ( source ) if ( getNeonType ~= 0 ) and ( theVehicle ) then detachNeon( theVehicle ) end end end end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) function onPlayerLogin (_, playeraccount ) if ( playeraccount ) then local getNeonTypeAccData = getAccountData ( playeraccount, "neon" ) if ( getNeonTypeAccData ~= 0 ) then setElementData(source, "neon", getNeonTypeAccData) end end end addEventHandler ( "onPlayerLogin", getRootElement ( ), onPlayerLogin ) Link to comment
#RooTs Posted January 31, 2016 Author Share Posted January 31, 2016 I will test it later Link to comment
#RooTs Posted February 1, 2016 Author Share Posted February 1, 2016 this event worked addEventHandler("onClientVehicleExplode", getRootElement(), function() setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), source) end) This event not more. when the passenger exit of my vehicle, my neon is removed.. the neon only to be removed when I leave my vehicle addEventHandler("onClientPlayerVehicleExit", getRootElement(),function() local theVehicle = getPedOccupiedVehicle(localPlayer) if theVehicle and getVehicleController(theVehicle) == localPlayer then setElementData( localPlayer, "neon", 0 ) -- Zerar local theVehicle = getPedOccupiedVehicle ( localPlayer ) triggerServerEvent ("detachNeon", getLocalPlayer(), theVehicle) end end) Link to comment
KariiiM Posted February 1, 2016 Share Posted February 1, 2016 Should works, try it correctly and tell me the result addEventHandler("onClientPlayerVehicleExit", getRootElement(),function() if (isPedInVehicle(localPlayer)) then local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) if (driver == localPlayer) then setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), vehicle) end end end end) Link to comment
#RooTs Posted February 1, 2016 Author Share Posted February 1, 2016 Should works, try it correctly and tell me the result addEventHandler("onClientPlayerVehicleExit", getRootElement(),function() if (isPedInVehicle(localPlayer)) then local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) if (driver == localPlayer) then setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), vehicle) end end end end) no work Link to comment
#RooTs Posted February 1, 2016 Author Share Posted February 1, 2016 server side function detachNeon( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) for i,v in ipairs ( attachedElements ) do detachElements ( v, theVehicle ) destroyElement ( v ) end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) client side addEventHandler("onClientVehicleExplode", getRootElement(), function() -- the event perfect work setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), source) end) addEventHandler("onClientPlayerVehicleExit", getRootElement(),function() if (isPedInVehicle(localPlayer)) then local vehicle = getPedOccupiedVehicle(localPlayer) if vehicle then local driver = getVehicleController(vehicle) if (driver == localPlayer) then setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), vehicle) end end end end) Link to comment
KariiiM Posted February 1, 2016 Share Posted February 1, 2016 Is detachneon part worked? -- server side and tell me where's the problem now? which side client or server Link to comment
#RooTs Posted February 1, 2016 Author Share Posted February 1, 2016 Is detachneon part worked? -- server sideand tell me where's the problem now? which side client or server the passenger when exit my car, it removes the neon Link to comment
KariiiM Posted February 1, 2016 Share Posted February 1, 2016 function detachNeon( vehicle ) local attachedElements = getAttachedElements ( vehicle ) for i,v in ipairs ( attachedElements ) do detachElements ( v, vehicle ) destroyElement ( v ) end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) addEventHandler("onClientVehicleExplode", getRootElement(), function() -- the event perfect work setElementData( localPlayer, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), vehicle) end) addEventHandler("onClientPlayerVehicleExit", getRootElement(),function(vehicle, seat) if vehicle then local driver = getVehicleController(vehicle) if (driver == localPlayer) then setElementData( driver, "neon", 0 ) -- Zerar triggerServerEvent ("detachNeon", getLocalPlayer(), vehicle) end end end) Link to comment
#RooTs Posted February 2, 2016 Author Share Posted February 2, 2016 (edited) , Edited February 3, 2016 by Guest Link to comment
KariiiM Posted February 3, 2016 Share Posted February 3, 2016 function detachNeon( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) --line 809 if (attachedElements) then --Maybe if you made a check if table created to be ready for loop it may solve it, try it. for i,v in ipairs ( attachedElements ) do -- line 810 detachElements ( v, theVehicle ) destroyElement ( v ) end end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) function onPlayerQuit() local theVehicle = getPedOccupiedVehicle ( source ) detachNeon( theVehicle ) end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) Link to comment
#RooTs Posted February 3, 2016 Author Share Posted February 3, 2016 function detachNeon( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) --line 809 if (attachedElements) then --Maybe if you made a check if table created to be ready for loop it may solve it, try it. for i,v in ipairs ( attachedElements ) do -- line 810 detachElements ( v, theVehicle ) destroyElement ( v ) end end end addEvent( "detachNeon", true ) addEventHandler( "detachNeon", getRootElement(), detachNeon ) function onPlayerQuit() local theVehicle = getPedOccupiedVehicle ( source ) detachNeon( theVehicle ) end addEventHandler ( "onPlayerQuit", getRootElement ( ), onPlayerQuit ) the problem still remains Link to comment
#RooTs Posted February 3, 2016 Author Share Posted February 3, 2016 @KariiiM, look my MP someone besides of @KariiiM, can help me? Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 Why use clientside?! local playerInVehicle = {} local vehicleGotPlayer = {} local function detachNeon ( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) for i,v in pairs ( attachedElements ) do --detachElements ( v, theVehicle ) is this even needed? If yes then activate it destroyElement ( v ) end end local function removeNeonOnEvent ( vehicle ) local vehicle = vehicle or getElementType ( source ) == "vehicle" and source or playerInVehicle[source] local player = getElementType ( source ) == "player" and source or vehicleGotPlayer[vehicle] detachNeon ( vehicle ) playerInVehicle[player] = nil vehicleGotPlayer[vehicle] = nil setElementData ( player, "neon", 0 ) removeEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) removeEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) removeEventHandler ( "onVehicleExplode", vehicle, removeNeonOnEvent ) end ) addEventHandler ( "onVehicleEnter", root, function ( player, seat ) if seat == 0 then playerInVehicle[player] = source vehicleGotPlayer[source] = player addEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) addEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) addEventHandler ( "onVehicleExplode", source, removeNeonOnEvent ) end end ) Link to comment
#RooTs Posted February 3, 2016 Author Share Posted February 3, 2016 Why use clientside?! local playerInVehicle = {} local vehicleGotPlayer = {} local function detachNeon ( theVehicle ) local attachedElements = getAttachedElements ( theVehicle ) for i,v in pairs ( attachedElements ) do --detachElements ( v, theVehicle ) is this even needed? If yes then activate it destroyElement ( v ) end end local function removeNeonOnEvent ( vehicle ) local vehicle = vehicle or getElementType ( source ) == "vehicle" and source or playerInVehicle[source] local player = getElementType ( source ) == "player" and source or vehicleGotPlayer[vehicle] detachNeon ( vehicle ) playerInVehicle[player] = nil vehicleGotPlayer[vehicle] = nil setElementData ( player, "neon", 0 ) removeEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) removeEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) removeEventHandler ( "onVehicleExplode", vehicle, removeNeonOnEvent ) end ) addEventHandler ( "onVehicleEnter", root, function ( player, seat ) if seat == 0 then playerInVehicle[player] = source vehicleGotPlayer[source] = player addEventHandler ( "onPlayerQuit", player, removeNeonOnEvent ) addEventHandler ( "onPlayerVehicleExit", player, removeNeonOnEvent ) addEventHandler ( "onVehicleExplode", source, removeNeonOnEvent ) end end ) fail my botton function neonVermelho (_, state) if painel == true then if state == "down" then if isCursorOnElement (botX+sizeX+680, 390, 42, 42) then local theVehicle = getPedOccupiedVehicle(localPlayer) if theVehicle and getVehicleController(theVehicle) == localPlayer then setElementData( localPlayer, "neon", idModel[1] ) -- Vermelho local theVehicle = getPedOccupiedVehicle ( localPlayer ) triggerServerEvent ("detachNeon", getLocalPlayer(), theVehicle) triggerServerEvent ("attachNeon", getLocalPlayer(), theVehicle) playSound(neonClick) end end end end end addEventHandler ("onClientClick", root, neonVermelho) Link to comment
Bonus Posted February 3, 2016 Share Posted February 3, 2016 And why did you post this code now?! Did you try the code I sent to you? 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