Transom Posted February 17, 2008 Share Posted February 17, 2008 Is it just me or is there something wrong with the ion cannon script. Do I have to add something to this: <meta> <info author="author" description="The ion cannon" /> <script src="ioncannon.lua" /> </meta> --===================================================================================================================== --Start defining varibles, including a players array. I defined players array in both scripts incase they are seperated --===================================================================================================================== root = getRootElement () players = {} outputChatBox ( "Ion cannon by Ransom" ) ion_rotx = 0 ion_loops = 0 ion_explosionTimer = 0 ion_cannonActivated = false ion_cancelActivation = false ion_beamSize = 5 ion_beamFlareSize = 5 ion_lauchbutton = "i" players = getElementsByType ( "player" ) --============================================================================================================== --Give all players on the server access to the weapons --============================================================================================================== function ResourceStartIonCannon ( name, root ) if name ~= getThisResource() then return end for k,v in ipairs ( players ) do -- for all players in the "players" array bindKey ( v, ion_lauchbutton, "down", placeIonCannonBeacon ) -- bind the key f for triggering the ion cannon end end addEventHandler ( "onResourceStart", root, ResourceStartIonCannon ) function ionPlayerJoin () bindKey ( source, ion_lauchbutton, "down", placeIonCannonBeacon ) --if a player joins after the resource loaded, bind their f key to trigger the ion cannon also end addEventHandler ( "onPlayerJoin", root, ionPlayerJoin ) --========================================================================================================================== --When the ion cannon key is pressed, show the mouse cursor that will allow the triggering of the onPlayerClick function --========================================================================================================================== function placeIonCannonBeacon ( player, key, state ) if ( ion_cannonActivated == false ) and ( ion_cancelActivation == false ) then -- and ( nuke_cancelActivation == false ) and ( nuke_cannonActivated == false ) then --These conditions prevent triggering the same weapon twice or triggering the other weapon at the same time. --Both weapons cannot be triggered because explosions are stretched to the limit, explosions would be random defineLaunchType = key --This is used later on the onPlayerClick function to tell it what weapon to launch showCursor ( player, true ) ion_cancelActivation = true else if ion_cancelActivation == true then showCursor ( player, false ) end --Prevents cursor from getting messed up if cursor is show for f or g and the opposite key is hit ion_cancelActivation = false --ion_cancelactivation is true when the cursor is showing. This is necessary along with asking if the actual --weapon is active to prevent problems with the cursor and weapon activation between both weapons and themselves. if ion_cannonActivated == true then outputChatBox ( "Ion cannon has already been activated", activator ) end --This statement says that if the ion cannon is already in use, display a meassage about it being in use on f press. --Else, if the above conditions were not satisifed and the nuke is not active, it meant the ion cannon was --active. Therefore, display the other message that both weapons cannot be used at the same time. end 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 --========================================================================================================================= function playerClick ( button, state, clickedElement, x, y, z ) if defineLaunchType == ion_lauchbutton then --If the player clicked, we check if the key is equal to f or g. This will dictate which onPlayerClick function --commences between the ion cannon and nuke scripts ion_cancelActivation = false --Since the weapon is now in use, you have no chance to abort by pressing the key again, therefore this is false defineLaunchType = nil --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 (which triggers nuke) ion_beaconx = x ion_beacony = y ion_beaconz = z --Set the ion cannon beacon (detonation spot) coordinates to the spot the mouse cursor clicked on the game map local playerz, playerz, playerz = getElementPosition ( source ) --For the above line, getElementPosition outputs 3 varibles, but I only want z so I overwrote 1 varible called --playerz as the function went through and assigned the XYZ values to varible x, varible y, and varible z respectively. if ( button == "left" ) and ( state == "down" ) and ( ion_cannonActivated == false ) then --When the left mouse button is pressed down (not when released), if ion cannon is not active then ion_cannonActivated = true --Set this varible to true, which will be used to avoid double launches & double weapon usage showCursor ( source, false ) --Weapon beacon was chosen and the launch is initiating to that point. Hide cursor. ionBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeamFlare = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "corona", 5, 255, 255, 255, 255 ) --create six markers at the beacon point. The marker checkpoint will extend into the sky, but will end at --the given z. 6 markers are used to ensure the beam looks full as I rapidly delete and recreate the markers --in the next functions. setTimer ( ionExplosion, 50, 1 ) setTimer ( ionShot, 100, 20 ) setTimer ( ionShot2, 150, 20 ) --Trigger the functions that will create the ion cannon shot and explosion imitation. 50ms 1 time, 100ms --20 times, and 150ms 20 times respectively. else ion_activator = getPlayerFromNick ( source ) showCursor ( source, false ) --Makes sure the cursor will not show again for detonation unless the ion cannon is not active. Activator --is used to display output messages in the other functions that activations/launches arent possible. end end end addEventHandler ( "onPlayerClick", root, playerClick ) --============================================================================================================================= --Create the illusion of a beam coming from space and gradually increasing in size (beam strike power) --============================================================================================================================= function ionShot () ion_beamSize = ion_beamSize + 1 setMarkerSize ( ionBeam, ion_beamSize ) setMarkerSize ( ionBeam2, ion_beamSize ) setMarkerSize ( ionBeam3, ion_beamSize ) if ( ion_beamSize == 6 ) then setTimer ( ionShotFlare, 3, 150 ) end --The first 3 markers making the ion beam are gradually increased at +10 in 1 second. When the function has looped --6 times (6/10 of a second), the flare (again, its a corona marker but I call it a flare) grow function is triggered. end function ionShot2 () setMarkerSize ( ionSecondaryBeam, ion_beamSize ) setMarkerSize ( ionSecondaryBeam2, ion_beamSize ) setMarkerSize ( ionSecondaryBeam3, ion_beamSize ) --These beams increase at a different rate, since beamSize is changing more rapidly in the ionShot function. They stay --a little smaller than the main 3 markers and assist the "grow" look while keeping the beam visible while the markers --change size. end function ionShotFlare () ion_beamFlareSize = ion_beamFlareSize + 1 setMarkerSize ( ionBeamFlare, ion_beamFlareSize ) --Every 3ms for 150 loops, the flare size increases. This makes a large glow that appears to be caused by the beam's light end function ionExplosion () if ion_explosionTimer == 0 then --We set this value when the script started. I do so I can keep looping through this function without --resetting it. setTimer ( ionExplosion, 170, 18 ) --Trigger this function to initiate 18 times in 170ms intervals. ion_explosionTimer = 1 --Set the explosion timer flag to 1 so it is not done again with the looping (could have been true/false) else r = ion_beamSize --min/max blast radius: 1.5-28 --r will serve as our explosion radius. For the ion cannon, the explosions coming from the ion cannon --will gradually increase distance from the center point in a circular motion, since I defined r as --ion_beamSize, which is gradully increasing in size in the ionShot function at the same time. angleup = randInt(0, 35999)/100 --Choose a random angle. A value between 0 and 35999 is divided by 100 because we want --to have 2 random decimal places for as well, rather than just a whole integer. explosionxcoord = r*math.cos(angleup) + ion_beaconx explosionycoord = r*math.sin(angleup) + ion_beacony --The x and y coordinates of the explosion will occur at a max radius of r away from the nuke beacon, --in a circular shape. This is a fundamental, simple circle geometry formula. createExplosion ( explosionxcoord, explosionycoord, ion_beaconz, 7 ) --An explosion of type 7 is created, which is the tied as the largest with some others it is --an aircraft explosion. ion_loops = ion_loops + 1 if ion_loops == 16 then --on the 16th loop of this function --ion_beamFlareSize = 200 --This triggers the flare to grow +50 immediately right as the beam is ending to create a little --larger flash, just for effect as the beam is done --setTimer ( ionFlareFade, 5, 200 ) --The flarefade function is set to occur 200 times at 5ms to set the flare size to 0 quickly, as --the beam has disappeared --skip the above, it doesn't work. Just get rid of the flare destroyElement ( ionBeamFlare ) ion_cannonActivated = false ion_beamFlareSize = 0 elseif ion_loops == 18 then --on the 18th loop of this function ion_explosionTimer = 0 --Set the explosion timer to 0 for the next ion cannon launch, since this is the last loop ion_loops = 0 --Set to 0 to trigger these events directly above on next ion cannon launch as well ion_beamSize = 5 --Set to 0 to trigger the functions properly on the next ion cannon launch destroyElement ( ionBeam ) destroyElement ( ionSecondaryBeam ) destroyElement ( ionBeam2 ) destroyElement ( ionSecondaryBeam2 ) destroyElement ( ionBeam3 ) destroyElement ( ionSecondaryBeam3 ) --Destroy all the created checkpoint marker elements that made the beam end end end function ionFlareFade () setMarkerSize ( ionBeamFlare, ion_beamFlareSize ) ion_beamFlareSize = ion_beamFlareSize - 1 if ion_beamFlareSize == 0 then destroyElement ( ionBeamFlare ) ion_cannonActivated = false ion_beamFlareSize = 5 end --Each time the function loops, the flare gets -1 smaller. When it has a size of 0 and becomes invisible, it needs --to be deleted for the next ion cannon launch. No elements should stay created as they will pile up and eventually --crash you or the server. Finally, ion_cannonActivated is false, meaning the ion cannon is inactive and another --weapon use can be performed. end Can I leave it as it is or do I have to add something to it, because on the Mtaserver.exe thingy, it says ion cannon resource failed to load. Link to comment
Mr.Hankey Posted February 18, 2008 Share Posted February 18, 2008 why are the first 5 lines the xml code of the meta.xml?! And btw the old ion cannon script is outdated because the syntax for eventhandlers changed in the time between the scripting tutorials and the dp1 release. And another thing is that the minimum interval for timers was set to 50 ms or something like this but Ransom uses a timer that calls every 3ms for 150 loops the function ionShotFlare =) Edit: hm... looks like this script has already been edited because the eventhandler sytax is correct^^ Link to comment
Transom Posted February 18, 2008 Author Share Posted February 18, 2008 why are the first 5 lines the xml code of the meta.xml?! And btw the old ion cannon script is outdated because the syntax for eventhandlers changed in the time between the scripting tutorials and the dp1 release. And another thing is that the minimum interval for timers was set to 50 ms or something like this but Ransom uses a timer that calls every 3ms for 150 loops the function ionShotFlare =) Edit: hm... looks like this script has already been edited because the eventhandler sytax is correct^^ I think I put that in trying to make it work. It still didn't work though. Hmmm. I'll try looking around for the new script. Link to comment
heavy air Posted February 18, 2008 Share Posted February 18, 2008 ive got this one running but it does give some errors it says it was written by RANSOM does give errors in the server window here u go --===================================================================================================================== --Start defining varibles, including a players array. I defined players array in both scripts incase they are seperated --===================================================================================================================== root = getRootElement () players = {} outputChatBox ( "Ion cannon by Ransom" ) ion_rotx = 0 ion_loops = 0 ion_explosionTimer = 0 ion_cannonActivated = false ion_cancelActivation = false ion_beamSize = 5 ion_beamFlareSize = 5 ion_lauchbutton = "i" players = getElementsByType ( "player" ) --============================================================================================================== --Give all players on the server access to the weapons --============================================================================================================== function ResourceStartIonCannon ( name, root ) if name ~= getThisResource() then return end for k,v in ipairs ( players ) do -- for all players in the "players" array bindKey ( v, ion_lauchbutton, "down", placeIonCannonBeacon ) -- bind the key f for triggering the ion cannon end end addEventHandler ( "onResourceStart", root, ResourceStartIonCannon ) function ionPlayerJoin () bindKey ( source, ion_lauchbutton, "down", placeIonCannonBeacon ) --if a player joins after the resource loaded, bind their f key to trigger the ion cannon also end addEventHandler ( "onPlayerJoin", root, ionPlayerJoin ) --========================================================================================================================== --When the ion cannon key is pressed, show the mouse cursor that will allow the triggering of the onPlayerClick function --========================================================================================================================== function placeIonCannonBeacon ( player, key, state ) if ( ion_cannonActivated == false ) and ( ion_cancelActivation == false ) then -- and ( nuke_cancelActivation == false ) and ( nuke_cannonActivated == false ) then --These conditions prevent triggering the same weapon twice or triggering the other weapon at the same time. --Both weapons cannot be triggered because explosions are stretched to the limit, explosions would be random defineLaunchType = key --This is used later on the onPlayerClick function to tell it what weapon to launch showCursor ( player, true ) ion_cancelActivation = true else if ion_cancelActivation == true then showCursor ( player, false ) end --Prevents cursor from getting messed up if cursor is show for f or g and the opposite key is hit ion_cancelActivation = false --ion_cancelactivation is true when the cursor is showing. This is necessary along with asking if the actual --weapon is active to prevent problems with the cursor and weapon activation between both weapons and themselves. if ion_cannonActivated == true then outputChatBox ( "Ion cannon has already been activated", activator ) end --This statement says that if the ion cannon is already in use, display a meassage about it being in use on f press. --Else, if the above conditions were not satisifed and the nuke is not active, it meant the ion cannon was --active. Therefore, display the other message that both weapons cannot be used at the same time. end 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 --========================================================================================================================= function playerClick ( button, state, clickedElement, x, y, z ) if defineLaunchType == ion_lauchbutton then --If the player clicked, we check if the key is equal to f or g. This will dictate which onPlayerClick function --commences between the ion cannon and nuke scripts ion_cancelActivation = false --Since the weapon is now in use, you have no chance to abort by pressing the key again, therefore this is false defineLaunchType = nil --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 (which triggers nuke) ion_beaconx = x ion_beacony = y ion_beaconz = z --Set the ion cannon beacon (detonation spot) coordinates to the spot the mouse cursor clicked on the game map local playerz, playerz, playerz = getElementPosition ( source ) --For the above line, getElementPosition outputs 3 varibles, but I only want z so I overwrote 1 varible called --playerz as the function went through and assigned the XYZ values to varible x, varible y, and varible z respectively. if ( button == "left" ) and ( state == "down" ) and ( ion_cannonActivated == false ) then --When the left mouse button is pressed down (not when released), if ion cannon is not active then ion_cannonActivated = true --Set this varible to true, which will be used to avoid double launches & double weapon usage showCursor ( source, false ) --Weapon beacon was chosen and the launch is initiating to that point. Hide cursor. ionBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam2 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionSecondaryBeam3 = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "checkpoint", 5, 255, 255, 255, 255 ) ionBeamFlare = createMarker ( ion_beaconx, ion_beacony, ion_beaconz, "corona", 5, 255, 255, 255, 255 ) --create six markers at the beacon point. The marker checkpoint will extend into the sky, but will end at --the given z. 6 markers are used to ensure the beam looks full as I rapidly delete and recreate the markers --in the next functions. setTimer ( ionExplosion, 50, 1 ) setTimer ( ionShot, 100, 20 ) setTimer ( ionShot2, 150, 20 ) --Trigger the functions that will create the ion cannon shot and explosion imitation. 50ms 1 time, 100ms --20 times, and 150ms 20 times respectively. else ion_activator = getPlayerFromNick ( source ) showCursor ( source, false ) --Makes sure the cursor will not show again for detonation unless the ion cannon is not active. Activator --is used to display output messages in the other functions that activations/launches arent possible. end end end addEventHandler ( "onPlayerClick", root, playerClick ) --============================================================================================================================= --Create the illusion of a beam coming from space and gradually increasing in size (beam strike power) --============================================================================================================================= function ionShot () ion_beamSize = ion_beamSize + 1 setMarkerSize ( ionBeam, ion_beamSize ) setMarkerSize ( ionBeam2, ion_beamSize ) setMarkerSize ( ionBeam3, ion_beamSize ) if ( ion_beamSize == 6 ) then setTimer ( ionShotFlare, 3, 150 ) end --The first 3 markers making the ion beam are gradually increased at +10 in 1 second. When the function has looped --6 times (6/10 of a second), the flare (again, its a corona marker but I call it a flare) grow function is triggered. end function ionShot2 () setMarkerSize ( ionSecondaryBeam, ion_beamSize ) setMarkerSize ( ionSecondaryBeam2, ion_beamSize ) setMarkerSize ( ionSecondaryBeam3, ion_beamSize ) --These beams increase at a different rate, since beamSize is changing more rapidly in the ionShot function. They stay --a little smaller than the main 3 markers and assist the "grow" look while keeping the beam visible while the markers --change size. end function ionShotFlare () ion_beamFlareSize = ion_beamFlareSize + 1 setMarkerSize ( ionBeamFlare, ion_beamFlareSize ) --Every 3ms for 150 loops, the flare size increases. This makes a large glow that appears to be caused by the beam's light end function ionExplosion () if ion_explosionTimer == 0 then --We set this value when the script started. I do so I can keep looping through this function without --resetting it. setTimer ( ionExplosion, 170, 18 ) --Trigger this function to initiate 18 times in 170ms intervals. ion_explosionTimer = 1 --Set the explosion timer flag to 1 so it is not done again with the looping (could have been true/false) else r = ion_beamSize --min/max blast radius: 1.5-28 --r will serve as our explosion radius. For the ion cannon, the explosions coming from the ion cannon --will gradually increase distance from the center point in a circular motion, since I defined r as --ion_beamSize, which is gradully increasing in size in the ionShot function at the same time. angleup = randInt(0, 35999)/100 --Choose a random angle. A value between 0 and 35999 is divided by 100 because we want --to have 2 random decimal places for as well, rather than just a whole integer. explosionxcoord = r*math.cos(angleup) + ion_beaconx explosionycoord = r*math.sin(angleup) + ion_beacony --The x and y coordinates of the explosion will occur at a max radius of r away from the nuke beacon, --in a circular shape. This is a fundamental, simple circle geometry formula. createExplosion ( explosionxcoord, explosionycoord, ion_beaconz, 7 ) --An explosion of type 7 is created, which is the tied as the largest with some others it is --an aircraft explosion. ion_loops = ion_loops + 1 if ion_loops == 16 then --on the 16th loop of this function --ion_beamFlareSize = 200 --This triggers the flare to grow +50 immediately right as the beam is ending to create a little --larger flash, just for effect as the beam is done --setTimer ( ionFlareFade, 5, 200 ) --The flarefade function is set to occur 200 times at 5ms to set the flare size to 0 quickly, as --the beam has disappeared --skip the above, it doesn't work. Just get rid of the flare destroyElement ( ionBeamFlare ) ion_cannonActivated = false ion_beamFlareSize = 0 elseif ion_loops == 18 then --on the 18th loop of this function ion_explosionTimer = 0 --Set the explosion timer to 0 for the next ion cannon launch, since this is the last loop ion_loops = 0 --Set to 0 to trigger these events directly above on next ion cannon launch as well ion_beamSize = 5 --Set to 0 to trigger the functions properly on the next ion cannon launch destroyElement ( ionBeam ) destroyElement ( ionSecondaryBeam ) destroyElement ( ionBeam2 ) destroyElement ( ionSecondaryBeam2 ) destroyElement ( ionBeam3 ) destroyElement ( ionSecondaryBeam3 ) --Destroy all the created checkpoint marker elements that made the beam end end end function ionFlareFade () setMarkerSize ( ionBeamFlare, ion_beamFlareSize ) ion_beamFlareSize = ion_beamFlareSize - 1 if ion_beamFlareSize == 0 then destroyElement ( ionBeamFlare ) ion_cannonActivated = false ion_beamFlareSize = 5 end --Each time the function loops, the flare gets -1 smaller. When it has a size of 0 and becomes invisible, it needs --to be deleted for the next ion cannon launch. No elements should stay created as they will pile up and eventually --crash you or the server. Finally, ion_cannonActivated is false, meaning the ion cannon is inactive and another --weapon use can be performed. end like i said watching the server window while other people are using it does report lots of errors but it works i have set it up as a separate script and just put a in the meta.xml Link to comment
Ransom Posted February 18, 2008 Share Posted February 18, 2008 I've written several times including across the top of the script now that it is outdated. The main issue is the corona grows on a timer that has been invalid for awhile since clientside events such as onClientRender gave enough reason to outlaw sloppy setTimer scripting. It was slop scripted from when I was more n00b at Lua. I haven't been arsed to fix it yet but I will sometime soon I think due to popular demand... busy with college and drained when I get home atm. The quick fix would be to make sure all timers are >= 50 but it wont look quite right. I need to rewrite it. btw damn you for absorbing my name transom Link to comment
heavy air Posted February 19, 2008 Share Posted February 19, 2008 hope i didnt offend or sound like i was complaining ioncannon script is amazing and seems to work quite well even though server reports errors it doesnt seem to be a problem THANX FOR THE HARD WORK RANSOM Link to comment
Transom Posted February 19, 2008 Author Share Posted February 19, 2008 I've written several times including across the top of the script now that it is outdated. The main issue is the corona grows on a timer that has been invalid for awhile since clientside events such as onClientRender gave enough reason to outlaw sloppy setTimer scripting. It was slop scripted from when I was more n00b at Lua. I haven't been arsed to fix it yet but I will sometime soon I think due to popular demand... busy with college and drained when I get home atm. The quick fix would be to make sure all timers are >= 50 but it wont look quite right. I need to rewrite it.btw damn you for absorbing my name transom Moi? Stealing names? Surely not ... Transom is actually what we call in the UK, as a fanlight. Above a door or something. Someone told me about the name and I thought it sounded good. Purely coincidental, Ransom I promise. You could sue me for plagiarism but no doubt you wouldn't get anywhere. Oh and don't worry, occasionally people thought I was you. I didn't steal your identity though. Promise. Link to comment
Ransom Posted February 21, 2008 Share Posted February 21, 2008 @ both replies No problem its just that the same request/mistake keeps happening and its irritating Link to comment
Ransom Posted February 24, 2008 Share Posted February 24, 2008 https://community.multitheftauto.com/index.php?p= ... ails&id=71 I finally fixed the superweapons. Enjoy. Link to comment
Transom Posted February 24, 2008 Author Share Posted February 24, 2008 I would come up with some witty, dry, sarcastic reply but I'll save it for a more deserving occasion. Yay!! **Dances a little jig** 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