Jump to content

destroyElement


TorNix~|nR

Recommended Posts

Hello guys, I have a marker of spawning a car, I made when a player wasted, it destroy, but I want to make it only for source

not for all players, please help, I already used the

 destroyElement(source, vehicles99ui)

but it didn't work, help please :/

Code:

    addEventHandler("onPlayerWasted", root,
    function()
         if isElement(vehicles99ui) then
              destroyElement(source, vehicles99ui)
              vehicles99ui = nil
         end
    end)

 

Edited by TorNix~|nR
Link to comment

You should use not only server side...
I don't know well, what you want to make, but here is, how I understand your problem:
Make a marker for all:
Server side:
 

car_marker = createMarker( 0,0,0 , "checkpoint",4,0,0,255,255)
setElementData(car_marker,"type","car")

You can check the hit on client side:

addEventHandler ( "onClientMarkerHit", getRootElement(), function()
    if getElementData(source,"type") == "car" then
      	local x,y,z = getElementPosition(getLocalPlayer())
      	triggerServerEvent("createVeh",root,getLocalPlayer(),x,y,z)
    end    
end)

Now create veh on Server:

addEvent("createVeh",true)

addEventHandler("createVeh",getRootElement(),function(player,x,y,z)
    local veh = createVehicle ( 432,x+10,y+10,z+3)
    triggerClientEvent(player,"synMyVeh",player,veh)
 end)

Receive and save the car element on client and write a death handler:

addEvent("synMyVeh",true)

local myCar = nil
addEventHandler("synMyVeh",root,function(veh)
    myCar = veh    
 end)

addEventHandler("onClientPlayerWasted",root,function()
    triggerServerEvent("deleteMyVeh",root,myCar)    
    end)

And delete only the client car in server side(maybe you can solve this in client side, not tested)

addEvent("deleteMyVeh",true)
  
  addEventHandler("deleteMyVeh",getRootElement(),function(vehicle)
    destroyElement(vehicle)
   end)

All the code not tested.... 
 

Edited by Awang
  • Confused 1
Link to comment

the same :/ here is the full code

    mark = createMarker( x,y,z, "cylinder", 2, 169, 199, 29, 150 ) 

vehicles99ui = {}	
	
	function fun(hitPlayer)
        local x, y, z = getElementPosition(source)
    if hitPlayer and getElementType(hitPlayer) == "player" and not isPedInVehicle (hitPlayer) then
        if ( getPlayerTeam ( hitPlayer ) == getTeamFromName ( "team" ) ) then
			        if isElement(vehicles99ui) then destroyElement(vehicles99ui) end
		        vehicles99ui = createVehicle(522, 1680.89, 957.67, 10.70)
		setVehicleColor (vehicles99ui, 169, 199, 29, 169, 199, 29)
        warpPedIntoVehicle(hitPlayer, vehicles99ui)
        else
            outputChatBox ("fail",hitPlayer, 169, 199, 29, true)
        end
    end
end
addEventHandler("onMarkerHit",mark,fun)

    addEventHandler("onPlayerWasted", root,
    function()
         if isElement(vehicles99ui) then
              destroyElement(vehicles99ui)
              vehicles99ui = nil
         end
    end)

 

Link to comment

Here's an idea (someone helped me understand this as I had similar issues) try setting the players element data to the vehicle, then when they die, get the data, here's untested code, if it doesn't work do a debugscript 3 and tell me the errors.

function spawnVeh (thePlayer) --This function adds a command that spawns a car and sets players data, we will remove the car later
   	local x, y, z = getElementPosition (thePlayer) --Get players position
   	local rotX, rotY, rotZ = getElementRotation (thePlayer) --Get there rotation
   	veh = createVehicle (468, x, y, z+5, rotX, rotY, rotZ) --Create the vehicle at the players position +5 height
   	warpPedIntoVehicle (thePlayer, veh) --Warp the player into the vehicle
   	setElementData(thePlayer, "freecar", veh) --Set the players data to the car
end

addCommandHandler("sanchez", spawnVeh) --When command is passed we create a sanchez above and set players data


function removeVehicle ()
	local theVeh = getElementData( source, "freecar" ) --First we get the players element data
	
	if ( theVeh ~= false ) then --If the data exists, it means the vehicle exists (unless you have done above command and the car gets destroyed)
		destroyElement(theVeh) --Since we got the element with getElementData above we can now destroy it
		setElementData(source, "freecar", false) --We now set the players data to false.
	end
end

addEventHandler("onPedWasted", getRootElement(), removeVehicle) --When player dies we trigger our function to check there data

Hopefully this works!

Edited by kieran
Forgot spawnVehicle existed xD
  • Thanks 1
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...