Jump to content

Little help with script


isa_Khamdan

Recommended Posts

Hello ,

I want to make a script that destroy cars if they stop in a collshape ( safe area ) for 5 seconds so if someone stopped his car and didn't move in 5 seconds the car will be destroyed.

So I am going to use If isElementWithinCollsShape to check if the vehicle inside the safe area or not and then I will use getElementSpeed to see if the element is moving or not and if it's speed is 0 then it will destroy it

So it's all good now but there is one thing that I didn't figure out how to do it :S

How can I make it count the time so if player stopped his vehicle for 5 seconds then it will destroy it?

Link to comment
setTimer 
destroyElement 

Why it doesn't work?

local Line1 = createColRectangle ( -1287.9871826172, -217.75384521484, 500, 500) 
  
function SafeZoneA(thePlayer) 
    if getElementType ( thePlayer ) == "vehicle" then 
        if (isElementWithinColShape(thePlayer, Line1)) then 
    if getElementVelocity ( thePlayer == 0) then 
    setTimer ( destroyElement , 10000, 1, thePlayer )  
  
        end 
    end 
 end 
end  
addEventHandler ( "onColShapeHit", getRootElement(), SafeZoneA ) 

Link to comment

It doesn't work :S

local Line1 = createColRectangle ( -1318.4671630859, -189.9077911377, 1000, 1000) 
  
  
  
function SafeZoneA(thePlayer) 
    if getElementType ( thePlayer ) == "vehicle" then 
        if (isElementWithinColShape(thePlayer, Line1)) then  
    if ( getElementVelocity ( thePlayer ) == 0 ) then 
    setTimer ( destroyElement , 1000, 1, thePlayer )  
  
        end 
    end 
 end 
end  
addEventHandler ( "onColShapeHit", getRootElement(), 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
And where are you using the getElementSpeed function? you're still using getElementVelocity...

Still the same :S

local Line1 = createColRectangle ( -1318.4671630859, -189.9077911377, 1000, 1000) 
  
  
  
function SafeZoneA(Vehicle) 
    if getElementType ( Vehicle ) == "vehicle" then 
        if (isElementWithinColShape(Vehicle, Line1)) then    
    local Speed = getElementSpeed(Vehicle,"kmh") 
    if Speed == 0 then 
    setTimer ( destroyElement , 1000, 1, Vehicle )  
  
        end 
    end 
 end 
end  
addEventHandler ( "onColShapeHit", getRootElement(), 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
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    
                if getElementSpeed( element ) == 0 then 
                    setTimer ( destroyElement , 1000, 1, element ) 
                end 
            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
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    
                if getElementSpeed( element ) == 0 then 
                    setTimer ( destroyElement , 1000, 1, element ) 
                end 
            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 

It doesn't destroy the vehicle :S

and there are no errors in debug

Edit: it only destroy the car if there was no one driving it :S

Link to comment
You can set the timer to execute a function which will check the vehicle speed, if it's 0, then destroy the vehicle.

How can I make a timer like this?

I made the Function

function Destroy( element ) 
  
    local Speed = getElementSpeed( element )  
   if getElementType ( element ) == "vehicle" then 
   if Speed == 0 then    
       destroyElement( element ) 
  
  end 
 end 
end 

Link to comment
Yes, then you set the 10 seconds timer to execute "Destroy" function, and you have to pass "element" as an argument.

This should work?

local Line1 = createColRectangle ( -1318.4671630859, -189.9077911377, 1000, 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    
                 
                    setTimer ( triggerEvent , 5000, 1, Destroy ) 
  
                end 
  
            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

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