FIRESTARTER Posted February 5, 2008 Share Posted February 5, 2008 hi, i need a little help because i cant script lua >.< how do i make this for only admins, moderators e.t.c --===================================================================================================================== --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 Link to comment
Ransom Posted February 5, 2008 Share Posted February 5, 2008 The script is outdated at the time being. Link to comment
ALBERT_NERI Posted February 5, 2008 Share Posted February 5, 2008 im is not admin but i see it About topic.I do not know Link to comment
Transom Posted February 5, 2008 Share Posted February 5, 2008 I have been wondering if this is possible. At the moment though ... I don't think the ion cannon works. I scripted it fine and it couldn't find the resource .... (Try looking .... damn server! ). Link to comment
FIRESTARTER Posted February 5, 2008 Author Share Posted February 5, 2008 this i posted works fine for me... i have dp 2 offcourse 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