Jump to content

[HELP] Creating a circular path with lua


Driggero

Recommended Posts

Hi everybody. I'm looking to create a circular path of explosions around the edge of my map. So the explosions will occur on the outer most part of the map and continue round eventually forming a circle. Simply changing the values each time is extremely tedious and not very efficient, so I was wondering if there was a way to map out a path using some of the math functions (perhaps math.sin, cos, etc.).

Unfortunately I can't get my head round these functions at all, could anyone offer some help as to whether this is actually possible? And if so how might it be done? Any help would be appreciated as I'm completely stumped :?

Link to comment

Do you want to form a circle of explosions at the same time or you want to create bunch of explosions one after another on a circular path?

-- x,y,z =  center of the circle 
-- radius = radius of the circle 
-- explosionCount = how many explosions you want to create in circle 
function createCircularExplosion( x, y, z, radius, explosionCount ) -- creates all explosions at the same time 
    if explosionCount == 0 then return end -- for safety: never divide by 0 
    for ang = 0, 360, (360/explosionCount) do -- increase ang by (360 degrees / explosions count) 
        local xx = math.cos( math.rad( ang ) ) * radius + x; 
        local yy = math.sin( math.rad( ang ) ) * radius + y; 
        createExplosion( xx, yy, z, 0 ); 
    end 
end 
  
  
-- x,y,z =  center of the circle 
-- radius = radius of the circle 
-- delay = how many milliseconds between each explosion 
-- explosionCount = how many explosions you want to create in circle 
function createDelayedCircularExplosion( x, y, z, radius, delay, explosionCount ) 
    if explosionCount == 0 then return end -- for safety: never divide by 0 
    local exploded = 0; 
    local incAngle = 360 / explosionCount; -- incremental angle (eg. 360 / 40 = explosion by every 9 degree) 
    local delayedExplosion = function ( x,y,z, radius ) 
        local xx = math.cos( math.rad( incAngle * exploded ) ) * radius + x; 
        local yy = math.sin( math.rad( incAngle * exploded ) ) * radius + y; 
        createExplosion( xx, yy, z, 0 ); 
        exploded = exploded + 1; 
    end 
    if explosionCount > 0 then 
        setTimer( delayedExplosion , delay, explosionCount,   x, y, z, radius ); 
    end 
end 

There is a GTA limit of explosion visible at the same time (I think it's roughly 20 explosions), so the first function will only create about 20 explosion maximum, other remaining explosions will not be created (so for 40 explosions: only half the circle will explode). You can try the second function:

-- warp yourself close to: 0, 0, 3 and call this function: 
createDelayedCircularExplosion( 0, 0, 3, 15, 200, 50 ); 

Link to comment

Yeah the delayed circular explosion was exactly what I was looking for, I'd have never worked that out on my own thanks very much indeed.

I've come across this explosion limit, weren't sure if it was just my local server or if there was an actual limit, cheers for clearing that up too. I guess I'll just set the explosions a little further apart, shouldn't be a problem.

Thanks again! :-D

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