Jump to content

Problems with Sams


WolfPire

Recommended Posts

So ok i made an amazing A69 sams script.

But i got a lil' problem... Seems like the sams will keep spawning no matter if the user got off the vehicle or the vehicle dissapeared.

I tried to kill the timers in many ways and i couldn't seem to find a solution.

Could you guys please help me?

Client

MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 )
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 )
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 )
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 )
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 )
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 )
------------------------------------------------------------------------------
function Missile1()
        if target then
            createProjectile ( localPlayer, 20 , 235.60000610352, 1939.5999755859, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer1)
        end
    end
end
 
function samson1()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite1 then
                samsTimer1 = setTimer(Missile1, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson1)
 
 
function samsoff1()
    if samsTimer1 then
        if source == MissileSite1 then
            killTimer(samsTimer1)
        end
    end
end
 
addEventHandler("onClientElementStreamOut", root, samsoff1)
 
----------------- Sams 2 -----------------
 
function Missile2()
    if target then
        createProjectile ( localPlayer, 20 , 268, 1899, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer2)
        end
    end
end
 
function samson2()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite2 then
                samsTimer2 = setTimer(Missile2, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson2)
 
 
function samsoff2()
    if samsTimer2 then
        if source == MissileSite2 then
            killTimer(samsTimer2)
        end
    end
end
 
addEventHandler("onClientElementStreamOut", root, samsoff2)
 
----------------- Sams 3 -----------------
 
function Missile3()
    if target then
        createProjectile ( localPlayer, 20 , 263, 1812, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer3)
        end
    end
end
 
function samson3()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite3 then
                samsTimer3 = setTimer(Missile3, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson3)
 
 
function samsoff3()
    if samsTimer3 then
        if source == MissileSite3 then
            killTimer(samsTimer3)
        end
    end
end
 
addEventHandler("onClientElementStreamOut", root, samsoff3)
 
----------------- Sams 4 -----------------
 
function Missile4()
    if target then
        createProjectile ( localPlayer, 20 , 167, 1854, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer4)
        end
    end
end
 
function samson4()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite4 then
                samsTimer4 = setTimer(Missile4, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson4)
 
 
function samsoff4()
    if samsTimer4 then
        if source == MissileSite4 then
            killTimer(samsTimer4)
        end
    end
end
 
addEventHandler("onClientElementStreamOut", root, samsoff4)
 
----------------- Sams 5 -----------------
 
function Missile5()
    if target then
        createProjectile ( localPlayer, 20 , 115, 1818, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer5)
        end
    end
end
 
function samson5()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite5 then
                samsTimer5 = setTimer(Missile5, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson5)
 
 
function samsoff5()
    if samsTimer5 then
        if source == MissileSite5 then
            killTimer(samsTimer5)
        end
    end
end
 
 
addEventHandler("onClientElementStreamOut", root, samsoff5)
 
----------------- Sams 6 -----------------
 
function Missile6()
    if target then
        createProjectile ( localPlayer, 20 , 105, 1905, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer6)
        end
    end
end
 
function samson6()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite6 then
                samsTimer6 = setTimer(Missile6, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson6)
 
 
function samsoff6()
    if samsTimer6 then
        if source == MissileSite6 then
            killTimer(samsTimer6)
        end
    end
end
 
 
addEventHandler("onClientElementStreamOut", root, samsoff6)
 
----------------- Sams 7 -----------------
 
function Missile7()
    if target then
        createProjectile ( localPlayer, 20 , 163, 1937, 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )
        else if target == nil then
            killTimer(samsTimer7)
        end
    end
end
 
function samson7()
    target = getPedOccupiedVehicle(getLocalPlayer())
    if isPedInVehicle(localPlayer) then
        if (getVehicleType" class="kw2">getVehicleType(target) == "Plane" or "Helicopter") then
            if source == MissileSite7 then
                samsTimer7 = setTimer(Missile7, 2000, 0)
            end
        end
    end
end
 
addEventHandler("onClientElementStreamIn", root, samson7)
 
 
function samsoff7()
    if samsTimer7 then
        if source == MissileSite7 then
            killTimer(samsTimer7)
        end
    end
end
 
Link to comment

MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos =  
{ 
    MissileSite1 = { 235.6, 1939.5 }; 
    MissileSite2 = { 268.0, 1899.0 }; 
    MissileSite3 = { 263.0, 1812.0 }; 
    MissileSite4 = { 167.0, 1854.0 }; 
    MissileSite5 = { 115.0, 1818.0 }; 
    MissileSite6 = { 105.0, 1905.0 }; 
    MissileSite7 = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    MissileSite1 = true; 
    MissileSite2 = true; 
    MissileSite3 = true; 
    MissileSite4 = true; 
    MissileSite5 = true; 
    MissileSite6 = true; 
    MissileSite7 = true; 
} 
  
local uTimers =  
{  
    localPlayer = { 
        MissileSite1 = false; 
        MissileSite2 = false; 
        MissileSite3 = false; 
        MissileSite4 = false; 
        MissileSite5 = false; 
        MissileSite6 = false; 
        MissileSite7 = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer(  
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )    
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end  
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end  
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)    

Updated.

Syntax bug in highlighting ...

Link to comment

MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos =  
{ 
    [ MissileSite1 ] = { 235.6, 1939.5 }; 
    [ MissileSite2 ] = { 268.0, 1899.0 }; 
    [ MissileSite3 ] = { 263.0, 1812.0 }; 
    [ MissileSite4 ] = { 167.0, 1854.0 }; 
    [ MissileSite5 ] = { 115.0, 1818.0 }; 
    [ MissileSite6 ] = { 105.0, 1905.0 }; 
    [ MissileSite7 ] = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    [ MissileSite1 ] = true; 
    [ MissileSite2 ] = true; 
    [ MissileSite3 ] = true; 
    [ MissileSite4 ] = true; 
    [ MissileSite5 ] = true; 
    [ MissileSite6 ] = true; 
    [ MissileSite7 ] = true; 
} 
  
local uTimers =  
{  
    [ localPlayer ] = { 
        [ MissileSite1 ] = false; 
        [ MissileSite2 ] = false; 
        [ MissileSite3 ] = false; 
        [ MissileSite4 ] = false; 
        [ MissileSite5 ] = false; 
        [ MissileSite6 ] = false; 
        [ MissileSite7 ] = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer(  
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )    
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end  
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end  
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)      
    
  

Updated.

Tested.

Little mistake with index :/

P.S Funny script :D

P.S Projectiles will fly to target even if the vehicle destroyed.( idk need you check if vehicle destroyed or no )

Link to comment
MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos =  
{ 
    [ MissileSite1 ] = { 235.6, 1939.5 }; 
    [ MissileSite2 ] = { 268.0, 1899.0 }; 
    [ MissileSite3 ] = { 263.0, 1812.0 }; 
    [ MissileSite4 ] = { 167.0, 1854.0 }; 
    [ MissileSite5 ] = { 115.0, 1818.0 }; 
    [ MissileSite6 ] = { 105.0, 1905.0 }; 
    [ MissileSite7 ] = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    [ MissileSite1 ] = true; 
    [ MissileSite2 ] = true; 
    [ MissileSite3 ] = true; 
    [ MissileSite4 ] = true; 
    [ MissileSite5 ] = true; 
    [ MissileSite6 ] = true; 
    [ MissileSite7 ] = true; 
} 
  
local uTimers =  
{  
    [ localPlayer ] = { 
        [ MissileSite1 ] = false; 
        [ MissileSite2 ] = false; 
        [ MissileSite3 ] = false; 
        [ MissileSite4 ] = false; 
        [ MissileSite5 ] = false; 
        [ MissileSite6 ] = false; 
        [ MissileSite7 ] = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer(  
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )    
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end  
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end  
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)      
    
  

Updated.

Tested.

Little mistake with index :/

P.S Funny script :D

P.S Projectiles will fly to target even if the vehicle destroyed.( idk need you check if vehicle destroyed or no )

Thanks n_n

works now =)

EDIT: a Wild problem has appeared!

Can you help me with the vehicle checking? i want them to stop if there's no planes or helis near by

Edited by Guest
Link to comment

MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos =  
{ 
    [ MissileSite1 ] = { 235.6, 1939.5 }; 
    [ MissileSite2 ] = { 268.0, 1899.0 }; 
    [ MissileSite3 ] = { 263.0, 1812.0 }; 
    [ MissileSite4 ] = { 167.0, 1854.0 }; 
    [ MissileSite5 ] = { 115.0, 1818.0 }; 
    [ MissileSite6 ] = { 105.0, 1905.0 }; 
    [ MissileSite7 ] = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    [ MissileSite1 ] = true; 
    [ MissileSite2 ] = true; 
    [ MissileSite3 ] = true; 
    [ MissileSite4 ] = true; 
    [ MissileSite5 ] = true; 
    [ MissileSite6 ] = true; 
    [ MissileSite7 ] = true; 
} 
  
local uTimers =  
{  
    [ localPlayer ] = { 
        [ MissileSite1 ] = false; 
        [ MissileSite2 ] = false; 
        [ MissileSite3 ] = false; 
        [ MissileSite4 ] = false; 
        [ MissileSite5 ] = false; 
        [ MissileSite6 ] = false; 
        [ MissileSite7 ] = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer(  
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )    
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end  
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end  
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)      
addEventHandler( 'onClientVehicleExplode',root, 
    function( ) 
        if getVehicleType( source ) == 'Plane' or 'Helicopter' then 
            for _,v in pairs( uTimers[ localPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)    
    
addEventHandler( 'onClientVehicleExit',root, 
    function( uPlayer ) 
        if getVehicleType( source ) == 'Plane' or 'Helicopter' then 
            for _,v in pairs( uTimers[ uPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)      
  

Updated again.( forgot syntax highlighting bug )

It kills timers only ( not destroy projectile )

Link to comment
  • 8 months later...
MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos =  
{ 
    [ MissileSite1 ] = { 235.6, 1939.5 }; 
    [ MissileSite2 ] = { 268.0, 1899.0 }; 
    [ MissileSite3 ] = { 263.0, 1812.0 }; 
    [ MissileSite4 ] = { 167.0, 1854.0 }; 
    [ MissileSite5 ] = { 115.0, 1818.0 }; 
    [ MissileSite6 ] = { 105.0, 1905.0 }; 
    [ MissileSite7 ] = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    [ MissileSite1 ] = true; 
    [ MissileSite2 ] = true; 
    [ MissileSite3 ] = true; 
    [ MissileSite4 ] = true; 
    [ MissileSite5 ] = true; 
    [ MissileSite6 ] = true; 
    [ MissileSite7 ] = true; 
} 
  
local uTimers =  
{  
    [ localPlayer ] = { 
        [ MissileSite1 ] = false; 
        [ MissileSite2 ] = false; 
        [ MissileSite3 ] = false; 
        [ MissileSite4 ] = false; 
        [ MissileSite5 ] = false; 
        [ MissileSite6 ] = false; 
        [ MissileSite7 ] = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer(  
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )    
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end  
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end  
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)      
addEventHandler( 'onClientVehicleExplode',root, 
    function( ) 
        if getVehicleType( source ) == 'Plane' or 'Helicopter' then 
            for _,v in pairs( uTimers[ localPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)    
    
addEventHandler( 'onClientVehicleExit',root, 
    function( uPlayer ) 
        if getVehicleType( source ) == 'Plane' or 'Helicopter' then 
            for _,v in pairs( uTimers[ uPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)      
  

Updated again.( forgot syntax highlighting bug )

It kills timers only ( not destroy projectile )

Sorry for the HUGE BUMP...

But you had an error... I just fixed it, after a long time.

MissileSite1 = createObject( 3884, 233.60000610352, 1934.5999755859, 32.500001525879 ) 
MissileSite2 = createObject( 3884, 267.20001220703, 1895.0999755859, 32.500001525879 ) 
MissileSite3 = createObject( 3884, 262, 1807.8000488281, 32.500001525879 ) 
MissileSite4 = createObject( 3884, 166.10000610352, 1849.9000244141, 32.500001525879 ) 
MissileSite5 = createObject( 3884, 113.40000152588, 1814, 32.500001525879 ) 
MissileSite6 = createObject( 3884, 103.80000305176, 1901, 32.500001525879 ) 
MissileSite7 = createObject( 3884, 162, 1932.9000244141, 32.500001525879 ) 
------------------------------------------------------------------------------ 
  
local tPos = 
{ 
    [ MissileSite1 ] = { 235.6, 1939.5 }; 
    [ MissileSite2 ] = { 268.0, 1899.0 }; 
    [ MissileSite3 ] = { 263.0, 1812.0 }; 
    [ MissileSite4 ] = { 167.0, 1854.0 }; 
    [ MissileSite5 ] = { 115.0, 1818.0 }; 
    [ MissileSite6 ] = { 105.0, 1905.0 }; 
    [ MissileSite7 ] = { 163.0, 1937.0 }; 
} 
  
local tStreamed = 
{ 
    [ MissileSite1 ] = true; 
    [ MissileSite2 ] = true; 
    [ MissileSite3 ] = true; 
    [ MissileSite4 ] = true; 
    [ MissileSite5 ] = true; 
    [ MissileSite6 ] = true; 
    [ MissileSite7 ] = true; 
} 
  
local uTimers = 
{ 
    [ localPlayer ] = { 
        [ MissileSite1 ] = false; 
        [ MissileSite2 ] = false; 
        [ MissileSite3 ] = false; 
        [ MissileSite4 ] = false; 
        [ MissileSite5 ] = false; 
        [ MissileSite6 ] = false; 
        [ MissileSite7 ] = false; 
    };   
} 
  
local function onStreamIn( ) 
    local target = getPedOccupiedVehicle( localPlayer ) 
    if isPedInVehicle( localPlayer ) then 
        if getVehicleType( target ) == 'Plane' or getVehicleType( source ) == 'Helicopter' then 
            if getElementType( source ) == 'object' and tStreamed[ source ] then 
                if isTimer( uTimers[ localPlayer ][ source ] ) then 
                    killTimer( uTimers[ localPlayer ][ source ] ) 
                    uTimers[ localPlayer ][ source ] = false 
                end 
                uTimers[ localPlayer ][ source ] = setTimer( 
                    function( target,element ) 
                        createProjectile ( localPlayer, 20 , tPos[ element ][1], tPos[ element ][2], 34.90000152587, 1.0, target, 0, 60, 0, 0, 0, 0 )   
                    end, 
                2000, 0,target,source  ) 
            end 
        end 
    end 
end 
addEventHandler( 'onClientElementStreamIn', root, onStreamIn ) 
  
local function onStreamOut( ) 
    if getElementType( source ) == 'object' and tStreamed[ source ] then 
        if uTimers[ localPlayer ][ source ] then 
            if isTimer( uTimers[ localPlayer ][ source ] ) then 
                killTimer( uTimers[ localPlayer ][ source ] ) 
                uTimers[ localPlayer ][ source ] = false 
            end 
        end 
    end 
end 
addEventHandler( 'onClientElementStreamOut', root, onStreamOut ) 
  
addEventHandler( 'onClientPlayerQuit',root, 
    function( ) 
        uTimers[ source ] = nil 
    end 
)     
addEventHandler( 'onClientVehicleExplode',root, 
    function( ) 
        if getVehicleType( source ) == 'Plane' or getVehicleType( source ) == 'Helicopter' then 
            for _,v in pairs( uTimers[ localPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)    
    
addEventHandler( 'onClientVehicleExit',root, 
    function( uPlayer ) 
        if getVehicleType( source ) == 'Plane' or getVehicleType( source ) == 'Helicopter' then 
            for _,v in pairs( uTimers[ uPlayer ] ) do 
                if isTimer( v ) then 
                    killTimer( v ) 
                    v = false 
                end 
            end 
        end  
    end 
)      
  

There was a very important conditional that wasn't made right... It looked like this:

if getVehicleType( source ) == 'Plane' or 'Helicopter' then 

Instead of this:

if getVehicleType( source ) == 'Plane' or getVehicleType( source ) == 'Helicopter' then 

Just pointing that out so it can be useful in future to people. Without it... The projectiles shot other type of vehicles too.

- WolfPire

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