Scripting Tutorial 8 - Ion Cannon and Nuke (from C&C '95)

All Lua scripting topics related to Multi Theft Auto.

Moderators: Moderators, MTA team

Scripting Tutorial 8 - Ion Cannon and Nuke (from C&C '95)

Postby Ransom on Wed Mar 28, 2007 10:00 pm

NOTICE: THIS TUTORIAL MAY BE OUTDATED! PLEASE READ: http://forum.mtasa.com/viewtopic.php?f=91&t=22270

Please post your comments about tutorial 8 scripts below. Thanks. 8)

The two seperate scripts for the ion cannon and nuke are posted below respectively. All of these two script's creation/commenting/video recording was done by me. So if you have any questions I'll be more than happy to answer them for you. ENJOY!
Last edited by Ransom on Wed Mar 28, 2007 10:46 pm, edited 2 times in total.
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby Ransom on Wed Mar 28, 2007 10:21 pm

NOTICE: THIS SCRIPT IS OUTDATED FROM THE CURRENT SCRIPTING SYSTEM.

http://community.mtasa.com/index.php?p= ... ails&id=71

Tutorial 8a: Ion Cannon
:!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!:

Start defining varibles, including a players array
  1. root = getRootElement ()
  2. players = {}
  3.  
  4. outputChatBox ( "Ion cannon by Ransom" )
  5. ion_rotx = 0
  6. ion_loops = 0
  7. ion_explosionTimer = 0
  8. ion_cannonActivated = false
  9. ion_cancelActivation = false
  10. ion_beamSize = 5
  11. ion_beamFlareSize = 5
  12. players = getElementsByType ( "player" )


Give all players on the server access to the weapons
  1. addEventHandler ( "onResourceStart", root, "ResourceStartIonCannon" )
  2. function ResourceStartIonCannon ( name, root )
  3. if name ~= getThisResource() then return end
  4.     for k,v in players do
  5.     -- for all players in the "players" array
  6.     bindKey ( v, "f", "down", "placeIonCannonBeacon" )
  7.     -- bind the key f for triggering the ion cannon
  8.     end
  9. end
  10.  
  11. addEventHandler ( "onPlayerJoin", root, "ionPlayerJoin" )
  12. function ionPlayerJoin ()
  13.     bindKey ( source, "f", "down", "placeIonCannonBeacon" )
  14.     --if a player joins after the resource loaded, bind their f key to trigger the ion cannon also
  15. end


When the ion cannon key (f) is pressed, show the mouse cursor that will allow the triggering of the onPlayerClick function
  1. function placeIonCannonBeacon ( player, key, state )
  2.     if ( ion_cannonActivated == false ) and ( ion_cancelActivation == false ) and ( nuke_cancelActivation == false )
  3.     and ( nuke_cannonActivated == false ) then
  4.     --These conditions prevent triggering the same weapon twice or triggering the other weapon at the same time.
  5.     --Both weapons cannot be triggered because explosions are stretched to the limit, explosions would be random
  6.     defineLaunchType = key
  7.     --This is used later on the onPlayerClick function to tell it what weapon to launch
  8.     showCursor ( player, true )
  9.     ion_cancelActivation = true
  10.     else
  11.         if ion_cancelActivation == true then
  12.         showCursor ( player, false )
  13.         end
  14.         --Prevents cursor from getting messed up if cursor is show for f or g and the opposite key is hit
  15.     ion_cancelActivation = false
  16.     --ion_cancelactivation is true when the cursor is showing. This is necessary along with asking if the actual
  17.     --weapon is active to prevent problems with the cursor and weapon activation between both weapons and themselves
  18.             if ion_cannonActivated == true then
  19.             outputChatBox ( "Ion cannon has already been activated", activator )
  20.             else
  21.             outputChatBox ( "Cannot activate ion cannon and nuke at the same time", activator )
  22.             end
  23.             --This statement says that if the ion cannon is already in use, display a meassage about it being in
  24.             --use on f press. Else, if the above conditions were not satisifed and the nuke is not active, it meant
  25.             --the ion cannon was active. Therefore, display the other message that both weapons cannot be used at
  26.             --the same time.
  27.     end
  28. end


When the player clicks the mouse cursor, decide if the ion cannon is supposed to be launched and if so, set up the launch
  1. addEventHandler ( "onPlayerClick", root, "playerClick" )
  2. function playerClick ( button, state, clickedElement, x, y, z )
  3.     if defineLaunchType == "f" then
  4.     --If the player clicked, we check if the key is equal to f or g. This will dictate which onPlayerClick function
  5.     --commences between the ion cannon and nuke scripts
  6.     ion_cancelActivation = false
  7.     --Since the weapon is now in use, you have no chance to abort by pressing the key again, therefore this is false
  8.     defineLaunchType = nil
  9.     --This must be reset to nil so it will not fire the ion cannon next time on click if g was pressed instead of f
  10.     --(which triggers nuke)
  11.     ion_beaconx = x
  12.     ion_beacony = y
  13.     ion_beaconz = z
  14.     --Set the ion cannon beacon (detonation spot) coordinates to the spot the mouse cursor clicked on the game map
  15.     local playerz, playerz, playerz = getElementPosition ( source )
  16.     --For the above line, getElementPosition outputs 3 varibles, but I only want z so I overwrote 1 varible called
  17.     --playerz as the function went through and assigned the XYZ values to varible x, varible y, and varible z
  18.     --respectively.
  19.             if ( button == "left" ) and ( state == "down" ) and ( ion_cannonActivated == false ) then
  20.             --When the left mouse button is pressed down (not when released), if ion cannon is not active then
  21.             ion_cannonActivated = true
  22.             --Set this varible to true, which will be used to avoid double launches & double weapon usage
  23.             showCursor ( source, false )
  24.             --Weapon beacon was chosen and the launch is initiating to that point. Hide cursor.
  25.             ionBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 )
  26.             ionBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 )
  27.             ionBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 )
  28.             ionSecondaryBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255,
  29.             255, 255 )
  30.             ionSecondaryBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255,
  31.             255, 255 )
  32.             ionSecondaryBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255,
  33.             255, 255 )
  34.             ionBeamFlare = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "corona", 5, 255, 255, 255, 255 )
  35.             --create six markers at the beacon point. The marker checkpoint will extend into the sky, but will end
  36.             --at the given z. 6 markers are used to ensure the beam looks full as I rapidly delete and recreate the
  37.             --markers in the next functions.
  38.             setTimer ( "ionExplosion", 50, 1 )  
  39.             setTimer ( "ionShot", 100, 20 )
  40.             setTimer ( "ionShot2", 150, 20 )
  41.             --Trigger the functions that will create the ion cannon shot and explosion imitation. 50ms 1 time, 100ms
  42.             --20 times, and 150ms 20 times respectively.
  43.             else
  44.             ion_activator = getPlayerFromNick ( source )
  45.             showCursor ( source, false )
  46.             --Makes sure the cursor will not show again for detonation unless the ion cannon is not active.
  47.             --Activator is used to display output messages in the other functions that activations/launches
  48.             --arent possible.
  49.             end
  50.     end
  51. end


Create the illusion of a beam coming from space and gradually increasing in size (beam strike power)
  1. function ionShot ()
  2.     ion_beamSize = ion_beamSize + 1
  3.     setMarkerSize ( ionBeam, ion_beamSize )
  4.     setMarkerSize ( ionBeam2, ion_beamSize )
  5.     setMarkerSize ( ionBeam3, ion_beamSize )
  6.     if ( ion_beamSize == 6 ) then  
  7.     setTimer ( "ionShotFlare", 3, 150 )
  8.     end
  9.     --The first 3 markers making the ion beam are gradually increased at +10 in 1 second. When the function has
  10.     --looped 6 times (6/10 of a second), the flare (again, its a corona marker but I call it a flare) grow
  11.     --function is triggered.
  12. end
  13.  
  14. function ionShot2 ()
  15.     setMarkerSize ( ionSecondaryBeam, ion_beamSize )
  16.     setMarkerSize ( ionSecondaryBeam2, ion_beamSize )
  17.     setMarkerSize ( ionSecondaryBeam3, ion_beamSize )
  18.     --These beams increase at a different rate, since beamSize is changing more rapidly in the ionShot function.
  19.     --They stay a little smaller than the main 3 markers and assist the "grow" look while keeping the beam visible
  20.     --while the markers change size.
  21. end
  22.  
  23. function ionShotFlare ()
  24.     ion_beamFlareSize = ion_beamFlareSize + 1
  25.     setMarkerSize ( ionBeamFlare, ion_beamFlareSize )
  26.     --Every 3ms for 150 loops, the flare size increases. This makes a large glow that appears to be caused by the
  27.     --beam's light
  28. end
  29.  
  30. function ionExplosion ()
  31.     if ion_explosionTimer == 0 then
  32.     --We set this value when the script started. I do so I can keep looping through this function without
  33.     --resetting it.
  34.     setTimer ( "ionExplosion", 170, 18 )
  35.     --Trigger this function to initiate 18 times in 170ms intervals.
  36.     ion_explosionTimer = 1
  37.     --Set the explosion timer flag to 1 so it is not done again with the looping (could have been true/false)
  38.     else
  39.     r = ion_beamSize --min/max blast radius: 1.5-28
  40.     --r will serve as our explosion radius. For the ion cannon, the explosions coming from the ion cannon
  41.     --will gradually increase distance from the center point in a circular motion, since I defined r as
  42.     --ion_beamSize, which is gradully increasing in size in the ionShot function at the same time.
  43.     angleup = randInt(0, 35999)/100
  44.     --Choose a random angle. A value between 0 and 35999 is divided by 100 because we want
  45.     --to have 2 random decimal places for as well, rather than just a whole integer.
  46.     explosionxcoord = r*math.cos(angleup) + ion_beaconx
  47.     explosionycoord = r*math.sin(angleup) + ion_beacony
  48.     --The x and y coordinates of the explosion will occur at a max radius of r away from the nuke beacon,
  49.     --in a circular shape. This is a fundamental, simple circle geometry formula.
  50.     createExplosion ( explosionxcoord, explosionycoord, ion_beaconz, 7 )
  51.     --An explosion of type 7 is created, which is the tied as the largest with some others it is
  52.     --an aircraft explosion.
  53.     ion_loops = ion_loops + 1
  54.             if ion_loops == 16 then
  55.             --on the 16th loop of this function
  56.             ion_beamFlareSize = 200
  57.             --This triggers the flare to grow +50 immediately right as the beam is ending to create a little
  58.             --larger flash, just for effect as the beam is done
  59.             setTimer ( "ionFlareFade", 5, 200 )
  60.             --The flarefade function is set to occur 200 times at 5ms to set the flare size to 0 quickly, as
  61.             --the beam has disappeared
  62.             elseif ion_loops == 18 then
  63.             --on the 18th loop of this function
  64.             ion_explosionTimer = 0
  65.             --Set the explosion timer to 0 for the next ion cannon launch, since this is the last loop
  66.             ion_loops = 0
  67.             --Set to 0 to trigger these events directly above on next ion cannon launch as well
  68.             ion_beamSize = 5
  69.             --Set to 0 to trigger the functions properly on the next ion cannon launch
  70.             destroyElement ( ionBeam )
  71.             destroyElement ( ionSecondaryBeam )
  72.             destroyElement ( ionBeam2 )
  73.             destroyElement ( ionSecondaryBeam2 )
  74.             destroyElement ( ionBeam3 )
  75.             destroyElement ( ionSecondaryBeam3 )
  76.             --Destroy all the created checkpoint marker elements that made the beam
  77.             end
  78.     end
  79. end
  80.  
  81. function ionFlareFade ()  
  82.         setMarkerSize ( ionBeamFlare, ion_beamFlareSize )
  83.         ion_beamFlareSize = ion_beamFlareSize - 1
  84.             if ion_beamFlareSize == 0 then
  85.             destroyElement ( ionBeamFlare )
  86.             ion_cannonActivated = false
  87.             ion_beamFlareSize = 5
  88.             end
  89. --Each time the function loops, the flare gets -1 smaller. When it has a size of 0 and becomes invisible, it needs
  90. --to be deleted for the next ion cannon launch. No elements should stay created as they will pile up and eventually
  91. --crash you or the server. Finally, ion_cannonActivated is false, meaning the ion cannon is inactive and another
  92. --weapon use can be performed.
  93. end
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby Ransom on Wed Mar 28, 2007 10:22 pm

Tutorial 8b: Nuke
:!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!:

Start defining varibles, including a players array
  1. root = getRootElement ()
  2. players = {}
  3.  
  4. outputChatBox ( "Nulear Bomb by Ransom" )
  5. --nuke_rotX = 0
  6. nuke_loops = 0
  7. nuke_explosionTimer = 0
  8. nuke_cloudRotationAngle = 0
  9. nuke_explosionLimiter = false
  10. nuke_cannonActivated = false
  11. nuke_cancelActivation = false
  12. players = getElementsByType ( "player" )


Give all players on the server access to the weapons
  1. addEventHandler ( "onResourceStart", root, "ResourceStartNuke" )
  2. function ResourceStartNuke ( name, root )
  3. if name ~= getThisResource() then return end
  4.     for k,v in players do
  5.     -- for all players in the "players" array
  6.     bindKey ( v, "g", "down", "placeNukeBeacon" )
  7.     -- bind the key g for triggering the nuke
  8.     end
  9. end
  10.  
  11. addEventHandler ( "onPlayerJoin", root, "nukePlayerJoin" )
  12. function nukePlayerJoin ()
  13.     bindKey ( source, "g", "down", "placeNukeBeacon" )
  14.     --if a player joins after the resource loaded, bind their g key to trigger the nuke also
  15. end


When the nuke key (g) is pressed, show the mouse cursor that will allow the triggering of the onPlayerClick function
  1. function placeNukeBeacon ( player, key, state )
  2.     if ( nuke_cannonActivated == false ) and ( nuke_cancelActivation == false ) and
  3.     ( ion_cancelActivation == false ) and ( ion_cannonActivated == false ) then
  4.     --These conditions prevent triggering the same weapon twice or triggering the other weapon at the same time.
  5.     --Both weapons cannot be triggered because explosions are stretched to the limit, explosions would be random.
  6.     defineLaunchType = key
  7.     --This is used later on the onPlayerClick function to tell it what weapon to launch
  8.     showCursor ( player, true )
  9.     nuke_cancelActivation = true
  10.     else
  11.         if nuke_cancelActivation == true then
  12.         showCursor ( player, false )
  13.         end
  14.         --Prevents cursor from getting messed up if cursor is show for f or g and the opposite key is hit
  15.     nuke_cancelActivation = false
  16.     --nuke_cancelactivation is true when the cursor is showing. This is necessary along with asking if the actual
  17.     --weapon is active to prevent problems with the cursor and weapon activation between both weapons and themselves
  18.             if nuke_cannonActivated == true then
  19.             outputChatBox ( "Nuke has already been activated", activator )
  20.             else
  21.             outputChatBox ( "Cannot activate ion cannon and nuke at the same time", activator )
  22.             end
  23.             --This statement says that if the nuke is already in use, display a meassage about it being in use on g
  24.         --press else, if the above conditions were not satisifed and the nuke is not active, it meant the
  25.         --ioncannon was active. Therefore, display the other message that both weapons cannot be used at the
  26.         --same time.
  27.     end
  28. end


When the player clicks the mouse cursor, decide if the nuke is supposed to be launched and if so, set up the launch
  1. addEventHandler ( "onPlayerClick", root, "playerClickNuke" )
  2. function playerClickNuke ( button, state, clickedElement, x, y, z )
  3.     if defineLaunchType == "g" then
  4.     --If the player clicked, we check if the key is equal to f or g. This will dictate which onPlayerClick function
  5.     --commences between the ion cannon and nuke scripts
  6.     nuke_cancelActivation = false
  7.     --Since the weapon is now in use, you have no chance to abort by pressing the key again, therefore this is false
  8.     defineLaunchType = nil
  9.     --This must be reset to nil so it will not fire the nuke next time on click if f was pressed instead of g
  10.     --(which triggers ion)
  11.     nuke_beaconx = x
  12.     nuke_beacony = y
  13.     nuke_beaconz = z
  14.     --Set the nuke beacon (detonation spot) coordinates to the spot the mouse cursor clicked on the game map
  15.     local playerz, playerz, playerz = getElementPosition ( source )
  16.     --I put a z height limit on the nuke, because the visual image of the bomb dropping can be broken if it is set
  17.     --to start an explosion/visually show object deletion in a mid-air point. To prevent this, I have assigned a max
  18.     --nuke height that is a little bit more than the z height of the player who activated it. There is a function to
  19.     --grab the actual z height at an X,Y position that I will implement later. For the above line,
  20.     --getElementPosition outputs 3 varibles, but I only want z so I overwrote 1 varible called playerz as the
  21.     --function went through and assigned the XYZ values to varible x, varible y, and varible z respectively.
  22.     nuke_maxBeamHeight = playerz + 2
  23.             if nuke_beaconz > nuke_maxBeamHeight then
  24.             nuke_beaconz = playerz + 3
  25.             end
  26.             --resets the nuke beacon z height if it is more than +3 above player z height
  27.                 if ( button == "left" ) and ( state == "down" ) and ( nuke_cannonActivated == false ) then
  28.                 --When the left mouse button is pressed down (not when released), if nuke is not active then
  29.                 nuke_cannonActivated = true
  30.                 --Set this varible to true, which will be used to avoid double launches & double weapon usage
  31.                 showCursor ( source, false )
  32.                 --Weapon beacon was chosen and the launch is initiating to that point. Hide cursor.
  33.                 setTimer ( "nukeExplosion", 2700, 1 )
  34.                 setTimer ( "nukeShot", 500, 1 )
  35.                 --Trigger these two functions that will drop and explode the nuke. Nuke drop triggers in 500ms,
  36.                 --1 time only. The explosion is triggered at 2700ms which is when the nuke should be hitting
  37.                 --the ground on the game map, it is also triggered 1 time.
  38.                 else
  39.                 activator = getPlayerFromNick ( source )
  40.                 showCursor ( source, false )
  41.                 --Makes sure the cursor will not show again for detonation unless the nuke is not active. Activator
  42.                 --is used to display output messages in the other functions that activations/launches arent possible
  43.                 end
  44.     end
  45. end


Move 3 objects according to the beacon/detonation point to give the appearance of a falling nuclear bomb to the desired point
  1. function nukeShot ()
  2.     nuke1 = createObject ( 16340, nuke_beaconx, nuke_beacony, nuke_beaconz + 200 )
  3.     nuke2 = createObject ( 3865, nuke_beaconx + 0.072265, nuke_beacony + 0.013731, nuke_beaconz + 196.153122 )
  4.     nuke3 = createObject ( 1243, nuke_beaconx + 0.060547, nuke_beacony - 0.017578, nuke_beaconz + 189.075554 )
  5.     --The 3 objects that make the nucelar bomb are called nuke1, nuke2, and nuke3. Math is done to piece the
  6.     --bomb together correctly at any given XYZ detonation coordinates.
  7.     setObjectRotation ( nuke1, math.deg(0.245437), math.deg(0), math.deg(3.150001) )
  8.     setObjectRotation ( nuke2, math.deg(1.938950), math.deg(0), math.deg(-1.575) )
  9.     setObjectRotation ( nuke3, math.deg(-1.767145), math.deg(0), math.deg(0) )
  10.     --The objects must also be rotated after they are placed in the correct XYZ positions to get the bomb shape
  11.     --I created in the map editor at any given XYZ beacon/detonation point.
  12.     shotpath = nuke_beaconz - 200
  13.     moveObject ( nuke1, 5000, nuke_beaconx, nuke_beacony, shotpath, 259.9 ) --, 259
  14.     moveObject ( nuke2, 5000, nuke_beaconx + 0.072265, nuke_beacony + 0.013731, shotpath - 3.846878, 259.9 )
  15.     moveObject ( nuke3, 5000, nuke_beaconx + 0.060547, nuke_beacony - 0.017578, shotpath - 10.924446, 259.9 )
  16.     --To make all 3 pieces of the bomb stay together in the exact same shape, they must descend directly down.
  17.     --nuke2 and nuke3 drop paths are altered slightly to be directly below their created positions in the air.
  18. end


Create the imitation of a nuclear explosion
  1. function nukeExplosion ()
  2.     if nuke_explosionTimer == 0 then
  3.     --We set this value when the script started. I do so I can keep looping through this function without
  4.     --resetting it.
  5.     setTimer ( "nukeExplosion", 170, 35 )
  6.     --Trigger this function to initiate 35 times in 170ms intervals.
  7.     nuke_explosionTimer = 1
  8.     --Set the explosion timer flag to 1 so it is not done again with the looping (could have been true/false)
  9.     else
  10.     nuke_loops = nuke_loops + 1
  11.     --tells us how many times this function as been run through, which will be 35 in total.
  12.     r = randInt(1.5, 4.5)
  13.     --r will serve as our explosion radius. It can be a random value between 1.5 and 4.5 from the center of
  14.     --the circle. The math for this is below.
  15.     angleup = randInt(0, 35999)/100
  16.     --Choose a random angle. A value between 0 and 35999 is divided by 100 because we want
  17.     --to have 2 random decimal places for as well, rather than just a whole integer.
  18.     Explosionxcoord = r*math.cos(angleup) + nuke_beaconx
  19.     Explosionycoord = r*math.sin(angleup) + nuke_beacony
  20.     --The x and y coordinates of the explosion will occur at a max radius of 4.5 away from the nuke beacon,
  21.     --in a circular shape. This is a fundamental, simple circle geometry formula.
  22.         if nuke_loops == 1 then
  23.         nuke_nukeCloud = nuke_beaconz
  24.         createExplosion ( Explosionxcoord, Explosionycoord, nuke_nukeCloud, 7 )
  25.         elseif nuke_loops == 2 then
  26.         nuke_nukeCloud = nuke_beaconz + 4
  27.         createExplosion ( Explosionxcoord, Explosionycoord, nuke_nukeCloud, 7 )
  28.         --Up until 20 loops, a pillar of explosions is created with the above. 7 is the explosion type,
  29.         --which is tied with a couple others as the largest. 7 is a aircraft explosion.
  30.         elseif nuke_loops > 20 then
  31.         nuke_cloudRotationAngle = nuke_cloudRotationAngle + 22.5
  32.             if nuke_explosionLimiter == false then
  33.             nuke_cloudRadius = 7
  34.             Explosionxcoord = nuke_cloudRadius*math.cos(nuke_cloudRotationAngle) + nuke_beaconx
  35.             Explosionycoord = nuke_cloudRadius*math.sin(nuke_cloudRotationAngle) + nuke_beacony
  36.             createExplosion ( Explosionxcoord, Explosionycoord, nuke_nukeCloud, 7 )
  37.             nuke_explosionLimiter = true
  38.             elseif nuke_explosionLimiter == true then
  39.             nuke_explosionLimiter = false
  40.             end
  41.         nuke_cloudRadius2 = 16
  42.         Explosionxcoord2 = nuke_cloudRadius2*math.cos(nuke_cloudRotationAngle) + nuke_beaconx
  43.         Explosionycoord2 = nuke_cloudRadius2*math.sin(nuke_cloudRotationAngle) + nuke_beacony
  44.         createExplosion ( Explosionxcoord2, Explosionycoord2, nuke_nukeCloud, 7 )
  45.         else
  46.         nuke_nukeCloud = nuke_nukeCloud + 4
  47.         createExplosion ( Explosionxcoord, Explosionycoord, nuke_nukeCloud, 7 )
  48.         end
  49.         --Since explosions are pushed to the limit, I have to make sure I can use the maximum amount without
  50.         --having explosions not appear. This required me to have the above explosions run every other time
  51.         --to create a mushroom cloud inner part (a circular area defined above), while at the same time creating
  52.         --an outter circle that also gave the look of a "full" mushroom cloud that won't have obvious visual holes.
  53.             if nuke_loops == 1 then
  54.             --On the first loop, the bright flare (as I call it, actually a corona marker), is created and
  55.             --increases in size.
  56.             nukeExplosionFlare = createMarker ( nuke_beaconx, nuke_beacony, nuke_beaconz, "corona", 0, 255, 255,
  57.             255, 255 )
  58.             --The flare has an inital size of 0, and the R, G, B colors are 255, making it white.
  59.             nuke_flareSize = 0
  60.             setTimer ( "nukeFlareGrow", 1, 200 )
  61.             --On the first loop, set the nuke_flareSize varible to 0, which will dictate the flare (corona) size
  62.             --in the nukeFlareGrow function below as it is looped. The timer initiates the function 200 times,
  63.             --every 1ms (so it takes 1/5 of a second to loop 200 times, thus making the bright flare).
  64.             elseif nuke_loops == 35 then
  65.             nuke_explosionTimer = 0
  66.             setTimer ( "nukeFlareFade", 1, 200 )
  67.             nuke_loops = 0
  68.             end
  69.                 --When this function has looped 35 times, the nuke has finished exploding and the flare must begin
  70.                 --fading to look like it disappears naturally. Nuke loops is reset for the next nuke launch.
  71.     end
  72. end
  73.  
  74. function nukeFlareGrow ()
  75.         setMarkerSize ( nukeExplosionFlare, nuke_flareSize )
  76.         nuke_flareSize = nuke_flareSize + 1
  77.             if nuke_flareSize == 200 then
  78.             destroyElement ( nuke1 )
  79.             destroyElement ( nuke2 )
  80.             destroyElement ( nuke3 )
  81.             end
  82.             --The flare becomes +1 larger on each loop, and the nuke is destroyed when the flare reaches maximum
  83.             --size. It is triggered here as this is the point where it is safest to assume the objects are out
  84.             --of site.
  85. end
  86.  
  87. function nukeFlareFade ()
  88.     nuke_flareSize = nuke_flareSize - 1
  89.     setMarkerSize ( nukeExplosionFlare, nuke_flareSize )
  90.     if nuke_flareSize == 0 then
  91.     destroyElement ( nukeExplosionFlare )
  92.     nuke_cannonActivated = false
  93.     end
  94.     --Each time the function loops, the flare gets -1 smaller. When it has a size of 0 and becomes invisible,
  95.     --it needs to be deleted for the next nuke launch. No elements should stay created as they will pile up and
  96.     --eventually crash you or the server. Finally, nuke_cannonActivated is false, meaning the nuke is inactive
  97.     --and another weapon use can be performed.
  98. end
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby Azu on Thu Mar 29, 2007 1:09 am

Woot. First to reply. Finally! Anyways, would this be possible to do without click. Say, you goto Area 52 and click on a spot on map or something. if you get what I mean.
Image
Azu
Regular
 
Posts: 219
Joined: Sat Dec 09, 2006 5:35 am

Postby Hedning on Thu Mar 29, 2007 2:26 am

Haha very nice :)
User avatar
Hedning
Experienced
 
Posts: 501
Joined: Sun Apr 23, 2006 1:05 pm
Location: Sweden

Postby adamale on Thu Mar 29, 2007 2:26 am

Wow. Looks great!

Fantastic idea ; )
adamale
New User
 
Posts: 14
Joined: Sun Feb 04, 2007 8:19 am
Location: Poland

Postby Ransom on Thu Mar 29, 2007 3:38 am

Azu wrote:Woot. First to reply. Finally! Anyways, would this be possible to do without click. Say, you goto Area 52 and click on a spot on map or something. if you get what I mean.


Well theres many different ways you can trigger something to occur with Lua. For a future version, yes I was hoping to be able to click on a map, get player details, and confirm a launch to their location. Could maybe cycle through a players list, type players name... thousands of possibilites. Its sometimes hard to have a concrete answer though. It depends on your ability to manipulate the functions MTA has provided to get what you desire. Such things like Aeron makes (A.I. sam site rockets, hay climb tower) seem impossible at first, but it can be done.

Although the MTA team has provided the functions and events, they are amazed themselves sometimes by how we coordinate them with scripting and come up with impressive results such as the imitation of WMDs in this video. eai was particularly pleased with this one as well since he is also a big C&C fan. I hope to perhaps make a mode to use these weapons in a team game or something for the future. We'll see depending on my time. I'd probably produce it this summer if anything.
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby Simbad De Zeeman on Thu Mar 29, 2007 8:25 am

WOOOOOOOOOOOOOOOOOOOOOOOW SO COOOL!!!

i played C&C Red Alert very much! i like this!
VERY NICE TUTORIAL, i will use it

and when there is an asshole in the serevr, i will nuke him! muhauhuahuahuah... thanks Ransom.
User avatar
Simbad De Zeeman
Regular
 
Posts: 148
Joined: Sun Oct 29, 2006 7:39 am
Location: Hattem, Netherlands

Postby Magus1724 on Thu Mar 29, 2007 10:40 am

Zomg :shock:
I'm gonna be :~ myself when I see that thing in the sky lol. Awesome! Very interesting scripting tutorial :P
User avatar
Magus1724
Regular
 
Posts: 330
Joined: Wed Jan 17, 2007 12:22 pm
Location: Canada
Gang: KotH

Postby Ace_Gambit on Thu Mar 29, 2007 11:18 am

Nice feature, although the damage radius of the blast in de video doesn't look very realistic :wink: . But I am sure you can adjust this with some extra parameters.
User avatar
Ace_Gambit
Experienced
 
Posts: 533
Joined: Mon Dec 25, 2006 12:58 pm
Location: Amsterdam

Postby Ransom on Thu Mar 29, 2007 12:11 pm

Yes its not a finalized version it needs some work still
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby Raoul on Thu Mar 29, 2007 12:38 pm

Very cool! Best tutorial subject so far :D I have 1 question can you make a explosion like this shape?

Image
Image
Raoul
New User
 
Posts: 41
Joined: Mon Dec 25, 2006 11:44 am
Location: Netherlands

Postby Wheelburner on Thu Mar 29, 2007 2:17 pm

Wow, that was crazy thing :o :shock: Very-very cool, best scripting tutorial at the moment 8)
Image Image
Image
User avatar
Wheelburner
New User
 
Posts: 91
Joined: Mon Jan 29, 2007 8:16 am
Location: Estonia

Postby Ransom on Thu Mar 29, 2007 2:52 pm

Raoul wrote:Very cool! Best tutorial subject so far :D I have 1 question can you make a explosion like this shape?

Image


Yes, that was the shape I was going for. If you read the code you'll see I did it in this way because I'm strecthing explosions to the GTA limit pretty much. You could make it more expansive but the completion time would be slower since you can only do so many explosions at once. I'll try to make a splash pool of explosions on the ground radius before I start the cloud but it may look too slow or glitchy. If I do, it should resemble your picture pretty well. The width of the middle part could be imitated more if you expand the radius of explosions as the nuke goes upward. Even if I can't make a better explosion cloud, when the flash goes off for the nuke explosion, I'll be defining an instant kill radius anyhow. Its not completed yet, but the visuals are pretty accurate already.

Also note for this same reason that the two weapons can NOT be launched at the same time. Many explosions would occur sporadically between them and ruin the visuals. The exact explosion limit you ask? From my testing and timing of these weapons as I recall the max stretch was 60 explosions at once (from the explosion to the time the smoke animation clears which takes considerably longer).
Part of the legendary VCP team... the only gang to win an official MTA tournament, undefeated! /smug
Offical B.L.A.S.T.A.ddict
XFire Gaming Record
User avatar
Ransom
Super Moderator
 
Posts: 4759
Joined: Wed Sep 24, 2003 6:32 pm
Location: The non-smoking section
Gang: VCP

Postby [TDH]Boss on Thu Mar 29, 2007 4:36 pm

I have made "ion cannon" in sa-mp, but it's far not that realistic. Thanks for this tutorial.
Image
Image
User avatar
[TDH]Boss
Regular
 
Posts: 122
Joined: Sun Jan 21, 2007 3:51 am
Location: Russia, Moscow
Gang: Team Dies Hard

Next

Return to Scripting

Who is online

Users browsing this forum: 50p and 0 guests