Jump to content

I need a spike deleter


Peti930

Recommended Posts

Posted

Helo!

I have a script with i spawn spikes but i only can delete with restart the script! 

Anyone can make me a function with delete all of the spikes have spawned by anyone? with this command: delspikes

 

 

addCommandHandler("rendorspike", 
    function(player) 
        if (player) then 
        local x, y, z = getElementPosition(player) 
        local spike = createObject(2892,x+2,y+2,z-0.6) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blow = createColSphere(x2, y2, z2, 3) 
        addEventHandler("onColShapeHit",blow,function (player) 
        if player and getElementType(player) == "player" then 
        if isPedInVehicle(player) then 
                local pveh = getPedOccupiedVehicle(player)       
                setVehicleWheelStates(pveh,1,1,1,1) 
                end 
            end 
        end) 
    end 
end) 

 

Posted (edited)
addCommandHandler("delpikes", function()
    for _, object in ipairs(getElementsByType("object") do
	    if getElementModel(object) == 2892 then
		   destroyElement(object)
		end
	end
end, false, false)

try this

Edited by Dimos7
Posted (edited)

Seeing in debugscript 3:

 

ERROR: Loading script failed: spikedel/server.lua:2:')' expected near 'do"

Im passed it, only you forgot an ")", thanks!

Uhm i have a problem, if i use /delspikes its deleting the object but if you go to this area where your car rubber was off its get off again

Can you make a scrpit with i use command /delspikes and its restarts the "spike" resource? Because this is a small script and cant be "NETWROK TROUBLE"

Edited by Peti930
Posted

why restart it

addCommandHandler("delpikes", function()
    for _, object in ipairs(getElementsByType("object")) do
	    if getElementModel(object) == 2892 then
		   destroyElement(object)
		end
	end
end, false, false)

 

Posted

Deleting the object won't do it as there is a colshape that does the actual work.

I would do something like this:

addCommandHandler("rendorspike", 
    function(player) 
        if (player) then 
        local x, y, z = getElementPosition(player) 
        local spike = createObject(2892,x+2,y+2,z-0.6) 
        local x2, y2, z2 = getElementPosition(spike) 
        local blow = createColSphere(x2, y2, z2, 3)
      	setElementData(blow, "blowObject", spike, false)
    end 
end)

addEventHandler("onColShapeHit", root, function (player) --Do it for all colshapes
    if not getElementData(source, "blowObject") then return end --Not a 'blow' colshape; don't care..
    if player and getElementType(player) == "player" then 
      if isPedInVehicle(player) then 
        local pveh = getPedOccupiedVehicle(player)
        setVehicleWheelStates(pveh,1,1,1,1)
      end 
    end 
  end)

addCommandHandler("delspikes", function (player)
    for i, element in pairs(getElementsByType("colshape")) do
      	if getElementData(element, "blowObject") then --is a 'blow' colshape
       	 	destroyElement(getElementData(element, "blowObject")) --Object has to be destroyed first
        	destroyElement(element) --Destroy the colshape itself
     	end
    end
end)
    

Didn't try it but you should get the idea.

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