Jump to content

destroyElement


TorNix~|nR

Recommended Posts

Posted (edited)

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
Posted (edited)
    addEventHandler("onPlayerWasted", root,
    function()
         if isElement(vehicles99ui)and isPedDead(source) then
              destroyElement(vehicles99ui)
              vehicles99ui = nil
         end
    end)

 

Edited by Dimos7
  • Confused 1
Posted (edited)

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
Posted (edited)

You can't use only serverside for that problem if you want to delete only the clien's car on the client death... Try the  code, what I'm wrote...

Edited by Awang
Posted

Yes, I will, I'm sorry :)

I told that because I'm using this script so many times for other teams, if your script works, I should take a long time to add them all

I will try it, ty

Posted

Your way, but you need to use client side, or maybe an assoc server table with the car elements ( where the table keys can be the player name) , but I don't really suggest that... Just a little communication between the client and server...

  • Thanks 1
Posted

I want only for the player it destroy the vehicle

the problem is when I get the vehicle and when any player died, it destroy, I want it to be destroyed only if the player (source) died

if you want, I can post the full code

Posted (edited)
addEventHandler("onPlayerWasted", root,
  function()
        car = getPedOccupiedVehicle(source)
      if isPedInVehicle(source) and isPedDead(source) then 
         destroyElement(car)
      end
    end)

 

Edited by Dimos7
Posted

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)

 

Posted (edited)

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
Posted (edited)

@kieran, finally it worked, in the place of command, I made the event handler of marker, and I added the marker, and I added the team access, and it working, ty :D

Edited by TorNix~|nR
  • Like 1

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