Laser Beams.

Discussion in 'CommandHelper Scripts' started by Jason Krause, Sep 28, 2015.

  1. Jason Krause

    Jason Krause Member

    Here is a script I wrote that adds laser beams functionality to your server.

    How to use: When you place a 'Laser Crystal' in a Dropper and apply redstone power, the Dropper will emit the laser beam. The Dropper can be in any orientation. The default laser color is red, and is harmful to any entity. You can change the laser's color by placing colored glass blocks or panes in the laser's path.

    Ideas: Create some puzzle games where you give the player certain blocks, and they must cross the beams safely to the next level. You can create a nice wall of beams by stacking 3 droppers high, making 3 laserbeams. More will be possible once I implement what I have listed in the future plans below.

    Future plans: Add banners to change the angle of the beams (banners used as mirrors). Add laser receptors that will detect when a laser beam hits the block. Make certain blocks break after a few seconds of being exposed to a red laser (ie: gold block breaks after 5 seconds, iron blocks break after 10 seconds, etc), different colored beams could have different effects on entities.

    Dependencies: CHSpigot (for the particle effects)

    Credits: InventiveTalent (on for the idea.
    PseudoKnight for helping with Yaw/Pitch to vectors.

    To add the Laser Crystal recipe, run the following alias once. To craft the Laser Crystal, simply add one diamond and one glass block in any position to a crafting table.
    /addlasercrystals = >>>
        add_recipe(array('type':'SHAPELESS','result':array('type':'264','meta':array('display':colorize('&4Laser Crystal'))),'ingredients':array('264','20')))
    Paste this in your .ms file and reload:
    #**************************************** LASER BEAMS ***************************************************
    #When you apply redstone power to a DROPPER that contains a 'Laser Crystal', it will shoot a laser beam.
    #The beam is red by default, but the color can be changed using any colored glass.  Red lasers are deadly
    #to any entity, any other color laser is safe.  Solid blocks and entities will block the laser.
        @type = @event['type'];             #Get dispenser type
       @item = @event['item'];             #Get item dispensed

        #Only continue if dispenser is a dropper and its dispensing a 'Laser Crystal'
       if(@type == 'DROPPER' && @item && @item['meta'] && @item['meta']['display'] == colorize('&4Laser Crystal')){
            @loc = @event['location'];      #location of the Dropper
           @block = get_block_at(@loc);    #get Dropper orientation
           cancel();                       #Cancel dropping item

            switch(@block){                 #Configure parameters depending on Dropper orientation
               case '158:10':              #North
                   @yaw = to_radians(-90);
                    @pitch = 0;
                    @OffsetX = 0.5;
                    @OffsetY = 0.3;
                    @OffsetZ = 0;
                case '158:11':              #South
                   @yaw = to_radians(90);
                    @pitch = 0;
                    @OffsetX = 0.5;
                    @OffsetY = 0.3;
                    @OffsetZ = 1;
                case '158:12':              #West
                   @yaw = to_radians(-180);
                    @pitch = 0;
                    @OffsetX = 0;
                    @OffsetY = 0.3;
                    @OffsetZ = 0.5;
                case '158:13':              #East
                   @yaw = to_radians(0);
                    @pitch = 0;
                    @OffsetX = 1;
                    @OffsetY = 0.3;
                    @OffsetZ = 0.5;
                case '158:9':               #Up
                   @yaw = 0;
                    @pitch = to_radians(90);
                    @OffsetX = 0.5;
                    @OffsetY = 1;
                    @OffsetZ = 0.5;

                case '158:8':               #Down
                   @yaw = 0;
                    @pitch = to_radians(-90);
                    @OffsetX = 0.5;
                    @OffsetY = 0;
                    @OffsetZ = 0.5;
            #Create vector from Yaw/Pitch
           @vector = array();
            @vector['x'] = cos(@yaw) * cos(@pitch);
            @vector['y'] = sin(@pitch);
            @vector['z'] = sin(@yaw) * cos(@pitch);
            #Define starting coordinate for laser beam
           @start = array(@loc[0] + @OffsetX,@loc[1] + @OffsetY,@loc[2] + @OffsetZ,@loc[3]);
            #Define laser's RGB color values
           @colorcodes = array(0:array(1,1,1),1:array(1,0.5,0.01),2:array(1,0.01,1),3:array(0.67,0.75,1),4:array(1,1,0.01),5:array(0.40,0.8,0.40),6:array(1,0.4,0.4),7:array(0.4,0.4,0.4),8:array(0.6,0.6,0.6),9:array(0.01,1,1),10:array(0.5,0.01,1),11:array(0.01,0.01,1),12:array(0.5,0.3,0),13:array(0.01,1,0.01),14:array(1,0.01,0.01),15:array(0.01,0.01,0.01));
            #Define laser's default color (Red)
           @color = @colorcodes[14];
            #Refresh laser beam every 1/4th of a second
                #Since red is the default color, the laser is not safe by default
               @lasersafe = false;
                    #if the DROPPER is not powered by redstone, cancel the interval (turn off laser)
                   if(get_block_power(@loc) == 0){clear_task()};
                    #define all positions of the beam's particles
                   @newx = @start[0] + (@vector['x'] * (@t / 4));
                    @newy = @start[1] + (@vector['y'] * (@t / 4));
                    @newz = @start[2] + (@vector['z'] * (@t / 4));
                    #get the block at the current particle's location
                   @block = get_block_at(array(@newx,@newy,@newz,@loc['world']));

                    #check if the block the particle is in is colored glass (glass block (95) or pane (160))
                   if(split(':',@block)[0] == '95' || split(':',@block)[0] == '160'){
                        #get the color value of the block/pane
                       @color = @colorcodes[split(':',@block)[1]];
                        #if the color is red, the laser is unsafe, any other color is safe
                       if(split(':',@block)[1] == '14'){
                            @lasersafe = false;
                        } else {
                            @lasersafe = true;

                    } else {
                        #if the beam is passing through a solid block that is not glass, and the laser is not safe, then create a burning effect on the block (LAVA_POP)
                       if(@block != '0:0' && @block != '20:0' && @block != '102:0'){
                            if([email protected]lasersafe){                    
                                play_effect(array(@start[0] + (@vector['x'] * ((@t - 1) / 4)),@start[1] + (@vector['y'] * ((@t - 1) / 4)),@start[2] + (@vector['z'] * ((@t - 1) / 4)),@loc['world']), 'LAVA_POP', array(offsetX:0,offsetY:0,offsetZ:0,particleCount:2,speed:0,radius:75));
                            #when the beam hits a solid block, stop the beam

                    #get all entities near the laser particles
                   @toburn = entities_in_radius(array(@newx,@newy - 0.3,@newz,@loc['world']),1);
                    foreach(@entity in @toburn){
                        #If the laser is not safe, check for entities to burn/hurt
                       if([email protected]lasersafe){
                            #get the type of entity detected
                           @entitytype = entity_type(@entity);
                            if(@entitytype == 'DROPPED_ITEM'){
                                #Dropped items will be removed
                            } else {
                                #Living entities will be damaged by 10 health
                                #set_entity_onfire(entity_id(@toburn[0]),1);     #remove comment to light entity on fire
                            #play fizz sound effect and lava_pop burning effect when unsafe beam is intercepted by entity
                            play_effect(array(@newx,@newy,@newz,@loc['world']), 'lava_pop', array(toffsetX:0,offsetY:0,offsetZ:0,particleCount:2,speed:0,radius:75));
                        #entities block safe/unsafe laser beams until removed or dead
                    #display coloured_dust particle as the laser beam
                   play_effect(array(@newx,@newy,@newz,@loc['world']), 'COLOURED_DUST', array(offsetX:@color[0],offsetY:@color[1],offsetZ:@color[2],particleCount:0,speed:1,radius:75));

    Last edited: Dec 19, 2015
    Synthproc likes this.
  2. MCmacjuul

    MCmacjuul Member

    Thank you a lot for this script! I used it to make an awesome Quake railgun :D
  3. Synthproc

    Synthproc Member