Jump to content

Little help with script


isa_Khamdan

Recommended Posts

You were already doing it with destroyElement, all you had to do is change destroyElement to Destroy.

Hmm it only destroy the car if you hit the colshape and the speed is 0 :S

local Line1 = createColCircle ( 1800.2021484375, 1714.71691, 1000) 
  
  
  
 function Destroy( element ) 
  
    local Speed = getElementSpeed( element )  
   if getElementType ( element ) == "vehicle" then 
   if Speed == 0 then    
       destroyElement( element ) 
  
  end 
 end 
end 
addEvent ( "Destroy", true ) 
addEventHandler ( "onColShapeHit", resourceRoot, Destroy ) 
  
  
  
function SafeZoneA( element ) 
  
    if source == Line1 then 
  
        if getElementType ( element ) == "vehicle" then 
  
            if ( isElementWithinColShape( element, source ) ) then  
  
     outputChatBox ( tostring ( getElementSpeed ( element ) ) )          
                 
                    setTimer ( Destroy , 1000, 1, element ) 
  
                end 
  
            end 
  
        end 
  
    end 
  
  
addEventHandler ( "onColShapeHit", resourceRoot, SafeZoneA ) 
  
  
  
function getElementSpeed(element,unit) 
  
    if (unit == nil) then unit = 0 end 
  
    if (isElement(element)) then 
  
        local x,y,z = getElementVelocity(element) 
  
        if (unit=="mph" or unit==1 or unit =='1') then 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
  
        else 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
  
        end 
  
    else 
  
        outputDebugString("Not an element. Can't get speed") 
  
        return false 
  
    end 
  
end 

Link to comment

Give a try for this

local Line1 = createColRectangle ( -1318.4671630859, -189.9077911377, 1000, 1000 ) 
  
function SafeZoneA( element ) 
    if source == Line1 then 
        if getElementType ( element ) == "vehicle" then 
            if ( isElementWithinColShape( element, source ) ) then 
                repeat until getElementSpeed( element ) == 0 
                if getElementSpeed( element ) == 0 then 
                    setTimer ( destroyElement , 1000, 1, element ) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onColShapeHit", resourceRoot, SafeZoneA ) 
  
function getElementSpeed( element, unit ) 
    if ( nit == nil ) then  
        unit = 0  
    end 
    if ( isElement( element ) ) then 
        local x,y,z = getElementVelocity( element ) 
        if ( unit == "mph" or unit == 1 or unit == '1' ) then 
            return ( x^2 + y^2 + z^2 ) ^ 0.5 * 100 
        else 
            return ( x^2 + y^2 + z^2 ) ^ 0.5 * 1.8 * 100 
        end 
    else 
        outputDebugString( "Not an element. Can't get speed" ) 
        return false 
    end 
end 

Link to comment
Yes, change that "1" to "0" and it'll keep repeating every 10 seconds. But, you'll have to kill the timer after they leave the area.

Is that right?

local Line1 = createColCircle ( 1800.2021484375, 1714.71691, 1000) 
  
  
  
 function Destroy( element ) 
  
    local Speed = getElementSpeed( element )  
   if getElementType ( element ) == "vehicle" then 
   if Speed == 0 then    
       destroyElement( element ) 
  
  end 
 end 
end 
addEvent ( "Destroy", true ) 
  
  
  
  
function DSC( element ) 
  
    if source == Line1 then 
  
        if getElementType ( element ) == "vehicle" then 
  
            if ( isElementWithinColShape( element, source ) ) then  
     
                 
            local Timer = setTimer ( Destroy , 10000, 0, element ) 
  
                end 
  
            end 
  
        end 
  
    end 
  
addEventHandler ( "onColShapeHit", resourceRoot, DSC ) 
  
  
function DSCDT ( thePlayer ) 
    if source == Line1 then 
   if isTimer ( Timer ) then killTimer ( Timer ) end 
   end 
 end 
addEventHandler ( "onColShapeLeave", resourceRoot, DSCDT ) 
  
  
  
function getElementSpeed(element,unit) 
  
    if (unit == nil) then unit = 0 end 
  
    if (isElement(element)) then 
  
        local x,y,z = getElementVelocity(element) 
  
        if (unit=="mph" or unit==1 or unit =='1') then 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
  
        else 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
  
        end 
  
    else 
  
        outputDebugString("Not an element. Can't get speed") 
  
        return false 
  
    end 
  
end 

Link to comment
local Line1 = createColCircle ( 1800.2021484375, 1714.71691, 1000) 
local timers = { }  
  
  
 function Destroy( element ) 
  
    local Speed = getElementSpeed( element ) 
   if getElementType ( element ) == "vehicle" then 
   if Speed == 0 then    
       destroyElement( element ) 
  
  end 
 end 
end 
  
function DSC( element ) 
  
    if source == Line1 then 
  
        if getElementType ( element ) == "vehicle" then 
  
            if ( isElementWithinColShape( element, source ) ) then 
    
                
            timers [ element ] = setTimer ( Destroy , 10000, 0, element ) 
  
                end 
  
            end 
  
        end 
  
    end 
  
addEventHandler ( "onColShapeHit", resourceRoot, DSC ) 
  
  
function DSCDT ( thePlayer ) 
    if source == Line1 then 
   if isTimer ( timers [ thePlayer ] ) then killTimer ( timers [ thePlayer ] ) end 
   end 
 end 
addEventHandler ( "onColShapeLeave", resourceRoot, DSCDT ) 
  
  
  
function getElementSpeed(element,unit) 
  
    if (unit == nil) then unit = 0 end 
  
    if (isElement(element)) then 
  
        local x,y,z = getElementVelocity(element) 
  
        if (unit=="mph" or unit==1 or unit =='1') then 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
  
        else 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
  
        end 
  
    else 
  
        outputDebugString("Not an element. Can't get speed") 
  
        return false 
  
    end 
  
end 

Link to comment
local Line1 = createColCircle ( 1800.2021484375, 1714.71691, 1000) 
local timers = { }  
  
  
 function Destroy( element ) 
  
    local Speed = getElementSpeed( element ) 
   if getElementType ( element ) == "vehicle" then 
   if Speed == 0 then    
       destroyElement( element ) 
  
  end 
 end 
end 
  
function DSC( element ) 
  
    if source == Line1 then 
  
        if getElementType ( element ) == "vehicle" then 
  
            if ( isElementWithinColShape( element, source ) ) then 
    
                
            timers [ element ] = setTimer ( Destroy , 10000, 0, element ) 
  
                end 
  
            end 
  
        end 
  
    end 
  
addEventHandler ( "onColShapeHit", resourceRoot, DSC ) 
  
  
function DSCDT ( thePlayer ) 
    if source == Line1 then 
   if isTimer ( timers [ thePlayer ] ) then killTimer ( timers [ thePlayer ] ) end 
   end 
 end 
addEventHandler ( "onColShapeLeave", resourceRoot, DSCDT ) 
  
  
  
function getElementSpeed(element,unit) 
  
    if (unit == nil) then unit = 0 end 
  
    if (isElement(element)) then 
  
        local x,y,z = getElementVelocity(element) 
  
        if (unit=="mph" or unit==1 or unit =='1') then 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 100 
  
        else 
  
            return (x^2 + y^2 + z^2) ^ 0.5 * 1.8 * 100 
  
        end 
  
    else 
  
        outputDebugString("Not an element. Can't get speed") 
  
        return false 
  
    end 
  
end 

There is one Small problem :S

It only destroy the vehicles if a player is driving it else get element type show error after destroying the vehicle

[00:13:14] WARNING: test1\SafeZone.lua:16: Bad argument @ 'getElementType' [Expected element at argument 1]

Edit: It works but if someone create a vehicle from the freeroam it will never get destroyed if the player didn't enter it.

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