Jump to content

[SOLVED] VehicleExplode and setElementData


#RooTs

Recommended Posts

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 by Guest
Link to comment

I want the neon is destroyed when the vehicle explode. I tried in many ways. but did not succeed..... :cry::cry:

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
I want the neon is destroyed when the vehicle explode. I tried in many ways. but did not succeed..... :cry::cry:

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
--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

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

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
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

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
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
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
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 :cry::cry::cry:

Link to comment

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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...