Castillo Posted September 15, 2013 Share Posted September 15, 2013 You were already doing it with destroyElement, all you had to do is change destroyElement to Destroy. Link to comment
isa_Khamdan Posted September 15, 2013 Author Share Posted September 15, 2013 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 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
Castillo Posted September 15, 2013 Share Posted September 15, 2013 Isn't that what you wanted? Link to comment
Blaawee Posted September 15, 2013 Share Posted September 15, 2013 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
Castillo Posted September 16, 2013 Share Posted September 16, 2013 I highly doubt that's efficient at all. Link to comment
isa_Khamdan Posted September 17, 2013 Author Share Posted September 17, 2013 (edited) I highly doubt that's efficient at all. I want it that when the Player is in the safe area and when he stop anytime while he is inside the area the car will be destroyed , the script now only destroy the car if it hit the collshape and the speed is 0 Edited September 17, 2013 by Guest Link to comment
Blaawee Posted September 17, 2013 Share Posted September 17, 2013 Are you kidding with me ! that's what you want to = ) Link to comment
isa_Khamdan Posted September 17, 2013 Author Share Posted September 17, 2013 Are you kidding with me ! that's what you want to = ) I am not that good in English , so if you are here to say jokes then please leave my thread and stop Spamming it with your replays. Link to comment
Castillo Posted September 17, 2013 Share Posted September 17, 2013 Well, just increase the timer time then? because you set it to 1 second. setTimer ( Destroy , 1000, 1, element ) Change that 1000 to 10000 for 10 seconds. Link to comment
isa_Khamdan Posted September 17, 2013 Author Share Posted September 17, 2013 Well, just increase the timer time then? because you set it to 1 second. setTimer ( Destroy , 1000, 1, element ) Change that 1000 to 10000 for 10 seconds. They may be in the area for a very long time so can I make the timer repeat every 10 seconds or something? Link to comment
Castillo Posted September 17, 2013 Share Posted September 17, 2013 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. Link to comment
isa_Khamdan Posted September 20, 2013 Author Share Posted September 20, 2013 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
Castillo Posted September 20, 2013 Share Posted September 20, 2013 If you set the timer to local, then you won't be able to kill it, because it won't exist outside of that function. Also, you'll need to use a table to store timers. Link to comment
isa_Khamdan Posted September 20, 2013 Author Share Posted September 20, 2013 If you set the timer to local, then you won't be able to kill it, because it won't exist outside of that function.Also, you'll need to use a table to store timers. is there another way to do it? Link to comment
Castillo Posted September 20, 2013 Share Posted September 20, 2013 What's the problem of using tables? is not hard. Link to comment
isa_Khamdan Posted September 20, 2013 Author Share Posted September 20, 2013 What's the problem of using tables? is not hard. Can you tell me how to make one? Else there is a problem with the Destroy Function it show that error " Expected Element at Argument 1 " Is that because there is no event handler? Link to comment
Castillo Posted September 20, 2013 Share Posted September 20, 2013 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
isa_Khamdan Posted September 20, 2013 Author Share Posted September 20, 2013 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 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now