Advertisement
glitchdetector

[Garry's Mod E2] Rust Building Creator

Aug 8th, 2014
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.53 KB | None | 0 0
  1. @name RUST Building (GlitchDetector)
  2. @persist Building:number Type:string Gx Gy Gz X Y Z Scale Pr:entity ANGOFF:number ROTSCALE:number
  3. @persist Holding:number LS:string
  4. @persist BASEPROP:string POLEPROP:string MATERIAL:string WALLPROP:string STAIRPROP:string
  5. @persist DOORPROP:string WINDOWPROP:string RAMPPROP:string GLASSPROP:string ROTWALLPROP:string
  6. @persist PM:string PA:angle PP:vector PMAT:number FILLERPROP:string
  7. @model models/bull/gates/microcontroller2.mdl
  8.  
  9. ########################################
  10. #       RUST STRUCTURE BUILDER         #
  11. #          BY GLITCHDETECTOR           #
  12. # Based on the construction mechanism  #
  13. #   in the game "Rust" by Facepunch    #
  14. ########################################
  15. # Controls are as following by default #
  16. # LMB:  Place tile                     #
  17. # RMB:  Change tile                    #
  18. # R:    Rotate tile                    #
  19. # Z:    Undo tile                      #
  20. ########################################
  21.  
  22.  
  23. runOnTick(1)
  24. runOnChat(1)
  25.  
  26. # Check if the player is using the tool or not.
  27. Building = (owner():weapon():type() == "weapon_crowbar") # This can be changed to what WEP or SWEP you want.
  28.  
  29. # "Enable" or "Disable" the holographic preview if the player is building or not.
  30. holoAlpha(0,Building*100)
  31. holoMaterial(0,"models/wireframe")
  32.  
  33.  
  34.  
  35. # Custom function for spawning props, materializing and setting their properties.
  36. function void spawnCustom(CModel:string,CPos:vector,CAng:angle,CMat:number){
  37.     if( !propCanCreate() ){
  38.         timer("spawnprop",10)
  39.         PM = CModel
  40.         PP = CPos
  41.         PA = CAng
  42.         PMAT = CMat
  43.     }else{
  44.     Pr = propSpawn(CModel,1)
  45.     Pr:setPos(CPos)
  46.     Pr:setAng(CAng)
  47.     if(CMat){ Pr:setMaterial(MATERIAL) }
  48. }}
  49.  
  50. if( clk("spawnprop") ){
  51.         spawnCustom("" + PM,vec() + PP,ang() + PA,0 + PMAT)
  52.     }
  53.    
  54. # Define everything the first time, so it is not executed every server tick.
  55. if( first() ){
  56.     holoCreate(0)                   # Creates the holographic preview. So it can be worked with.
  57.     propSpawnEffect(1)              # Enables an effect when spawning props.
  58.     Type = "base"                   # Sets the default tile.
  59.     Building = 0                    # Variable for checking if you are building or not.
  60.     Gx = 16                         # Default grid x-size
  61.     Gy = 16                         # Default grid y-size
  62.     Gz = 16                         # Default grid z-size
  63.     Scale = 4                       # Scaling, this only affects the holographic preview and the grid. Not the props.
  64.     ANGOFF = 0                      # Default rotation angle.
  65.    
  66.     # Define all props here.
  67.     BASEPROP = "models/hunter/blocks/cube4x4x05.mdl"            # Used as the foundation and ceiling.
  68.     POLEPROP = "models/hunter/blocks/cube05x4x05.mdl"           # A pole or pillar.
  69.     WALLPROP = "models/hunter/blocks/cube4x4x025.mdl"           # Used as the wall.
  70.     ROTWALLPROP = "models/hunter/blocks/cube4x6x025.mdl"        # This is used as a wall, but only when the rotation is 45, 135 etc. ( So it fills the whole block )
  71.     STAIRPROP = "models/hunter/blocks/cube1x4x025.mdl"          # This is used in every part of the staircase. (Which contains 4 props)
  72.     DOORPROP = "models/hunter/blocks/cube1x4x025.mdl"           # Used to make doorways.
  73.     WINDOWPROP = "models/hunter/blocks/cube1x4x025.mdl"         # Used to make windows.
  74.     GLASSPROP = "models/props_phx/construct/glass/glass_plate2x2.mdl"   # Used to make glass in windows.
  75.     RAMPPROP = "models/hunter/blocks/cube1x6x025.mdl"           # Used to make ramps or roof filler pieces.
  76.     FILLERPROP = "models/hunter/blocks/cube1x4x025.mdl"   # Used to fil in halved walls
  77.     MATERIAL = "models/props/CS_militia/roofbeams01"            # Default material used for props.
  78.     ROTSCALE = 45                   # Angular rotation grid.
  79.     Holding = 0                     # Variable for checking if you are holding down a key.
  80. }
  81.  
  82. # Check if the player is building and not holding a key, so double placement is not an issue.
  83. if( Building && !Holding ){
  84.        
  85.         # Rotate if the player holds RELOAD (R)
  86.         if( owner():keyReload() ){
  87.             ANGOFF = ANGOFF + ROTSCALE
  88.             hint("Rotate "+(ANGOFF),4)
  89.         }
  90.         # Change material
  91.         if( owner():keyUse() ){
  92.             if( MATERIAL == "models/props/CS_militia/roofbeams01" ){ # If current tile is "base"
  93.                 MATERIAL = "models/props_combine/health_charger_glass"# Set tile to "pole" ... and etc.
  94.             }elseif(MATERIAL=="models/props_combine/health_charger_glass"){
  95.                 MATERIAL = "phoenix_storms/Metalfloor_2-3"
  96.         }else{
  97.                 MATERIAL = "models/props/CS_militia/roofbeams01"
  98.     }
  99.         hint("Material: "+MATERIAL,4)
  100.     }
  101.        
  102.         # Change tile if the player is holding ATTACK2 (RMB)
  103.         if( owner():keyAttack2() ){
  104.             if( Type == "base" ){   # If current tile is "base"
  105.                 Type = "pole"       # Set tile to "pole" ... and etc.
  106.             }elseif(Type=="pole"){
  107.                 Type = "wall"
  108.             }elseif(Type=="wall"){
  109.                 Type = "stair"
  110.             }elseif(Type=="stair"){
  111.                 Type = "door"
  112.             }elseif(Type=="door"){
  113.                 Type = "door2"
  114.             }elseif(Type=="door2"){
  115.                 Type = "window"
  116.             }elseif(Type=="window"){
  117.                 Type = "window2"
  118.             }elseif(Type=="window2"){
  119.                 Type = "ramp"
  120.             }elseif(Type=="ramp"){
  121.                 Type = "filler"
  122.         }elseif(Type=="filler"){
  123.                 Type = "base"
  124.         }
  125.             # Tell the player the new tile
  126.             hint("Tile \""+Type+"\"",4)
  127.        }          
  128.        
  129.        # Place a tile if the player is holding ATTACK1 (LMB)
  130.        if( owner():keyAttack1() ){
  131.         if( Type == "base" ){                   # If Tile is "base" then spawn the correct props.
  132.             spawnCustom(BASEPROP,vec(X,Y,Z),ang(),1)
  133.         }elseif(Type=="pole"){                  # If Tile is "pole" then spawn the correct props. ... etc
  134.             spawnCustom(POLEPROP,vec(X+6,Y,Z),ang(0,0,90),1)
  135.                 }elseif(Type=="wall"){
  136.         if( (ANGOFF / 90) == floor(ANGOFF/90) ) {
  137.         spawnCustom(WALLPROP,vec(X,Y,Z),ang(0,ANGOFF,90),1)
  138.     }else{
  139.         spawnCustom(ROTWALLPROP,vec(X,Y,Z),ang(90,ANGOFF,90),1)
  140. }
  141.     } elseif(Type=="stair"){
  142.             spawnCustom(STAIRPROP,vec(X+(Scale*12),Y+(Scale*12*0.25),Z+(Scale*12)),ang(0,0,30),1)
  143.             spawnCustom(STAIRPROP,vec(X,Y-(Scale*12*2),Z),ang(0,90,0),1)
  144.             spawnCustom(STAIRPROP,vec(X,Y+(Scale*12*2),Z+(Scale*12*2)),ang(0,90,0),1)
  145.             spawnCustom(STAIRPROP,vec(X-(Scale*12),Y+(Scale*12*0.25),Z-(Scale*12)),ang(0,180,30),1)
  146.     } elseif(Type=="door"){
  147.             spawnCustom(DOORPROP,vec(X,Y-(Scale*12*1.5),Z),ang(0,90,90),1)
  148.             spawnCustom(DOORPROP,vec(X,Y+(Scale*12*1.5),Z),ang(0,90,90),1)
  149.             spawnCustom(DOORPROP,vec(X,Y,Z+(Scale*12*1.5)),ang(90,90,90),1)
  150.     } elseif(Type=="door2"){
  151.             spawnCustom(DOORPROP,vec(X-(Scale*12*1.5),Y,Z),ang(0,180,90),1)
  152.             spawnCustom(DOORPROP,vec(X+(Scale*12*1.5),Y,Z),ang(0,180,90),1)
  153.             spawnCustom(DOORPROP,vec(X,Y,Z+(Scale*12*1.5)),ang(90,180,90),1)
  154.     } elseif(Type=="window"){
  155.             spawnCustom(GLASSPROP,vec(X,Y+(Scale*12*0.5),Z-(Scale*12*0.5)),ang(0,90,90),0)
  156.             spawnCustom(WINDOWPROP,vec(X,Y,Z-(Scale*12*1.5)),ang(90,90,90),1)
  157.             spawnCustom(WINDOWPROP,vec(X,Y-(Scale*12*1.5),Z),ang(0,90,90),1)
  158.             spawnCustom(WINDOWPROP,vec(X,Y+(Scale*12*1.5),Z),ang(0,90,90),1)
  159.             spawnCustom(WINDOWPROP,vec(X,Y,Z+(Scale*12*1.5)),ang(90,90,90),1)
  160.                
  161.     } elseif(Type=="window2"){
  162.             spawnCustom(GLASSPROP,vec(X-(Scale*12*0.5),Y,Z-(Scale*12*0.5)),ang(0,180,90),0)
  163.             spawnCustom(WINDOWPROP,vec(X,Y,Z-(Scale*12*1.5)),ang(90,180,90),1)
  164.             spawnCustom(WINDOWPROP,vec(X-(Scale*12*1.5),Y,Z),ang(0,180,90),1)
  165.             spawnCustom(WINDOWPROP,vec(X+(Scale*12*1.5),Y,Z),ang(0,180,90),1)
  166.             spawnCustom(WINDOWPROP,vec(X,Y,Z+(Scale*12*1.5)),ang(90,180,90),1)
  167.     } elseif(Type=="ramp"){
  168.         Pr = propSpawn(RAMPPROP,ang(0,ANGOFF,45),1)
  169.             Pr:setPos(vec(X,Y,Z)) Pr:setMaterial(MATERIAL)
  170.     } elseif(Type=="filler"){
  171.         spawnCustom(FILLERPROP,vec(X,Y,Z),ang(90,ANGOFF,0),1)
  172.     } elseif(Type==""){
  173.        
  174.     }
  175.    
  176.     hint("Placed \""+Type+"\"",4)
  177.     Pr:setMaterial(MATERIAL)            # Sets the spawned props material, this was used before multiple props per spawn was made.
  178. }
  179. }
  180.  
  181.  
  182. # Show the holographic preview for the tiles.
  183. if( Building ){
  184.    
  185.     # Reset all XYZ coordinates with their respective scaled values.
  186.     X = round( owner():aimPos():x() / Gx )*Gx
  187.     Y = round( owner():aimPos():y() / Gy )*Gy
  188.     Z = ceil( (owner():aimPos():z()-Gz/2) / Gz )*Gz
  189.     # Reset the angle so you don't need holoAng(0,ang()) in every block not using another value for angle.
  190.    holoAng(0,ang())
  191.    
  192.     if( Type == "base" ){                           # Again, if tile is "base" ...
  193.         holoModel(0,"block")                        # Sets the model of the holographic preview.
  194.        holoScale(0,vec(Scale*4,Scale*4,Scale*0.5)) # Sets the scale of the hologram.
  195.         Gx = Gy = Gz = Scale*12*4                   # Sets the grid size, so some tiles can be placed more freely than others.
  196.    }elseif( Type == "pole" ){
  197.        holoModel(0,"block")
  198.        holoScale(0,vec(Scale*0.5,Scale*0.5,Scale*4))
  199.        Gx = Gy = Scale*12*2
  200.        Gz = Scale*12*4
  201.        Z = Z + Scale*12*2
  202.    }elseif( Type == "wall" ){
  203.        holoModel(0,"block")
  204.        holoScale(0,vec(Scale*4,Scale*0.25,Scale*4))
  205.         holoAng(0,ang(0,ANGOFF,0))                  # Sets the angle of the preview, so you can rotate tiles before placing them.
  206.        Gx = Gy = Scale*12*2
  207.        Gz = Scale*12*4
  208.        Z = Z + Scale*12*2
  209.    }elseif( Type == "stair" ){
  210.        holoModel(0,"block")
  211.        holoScale(0,vec(Scale*3,Scale*3,Scale*0.5))
  212.        holoAng(0,ang(0,0,30))
  213.        Gx = Gy = Scale*12*4
  214.        Gz = Scale*12*4
  215.        Z = Z + Scale*12*2
  216.     }elseif( Type == "door" ){
  217.        holoModel(0,"block")
  218.        holoScale(0,vec(Scale*0.5,Scale*3,Scale*3))
  219.        Gx = Gy = Scale*12*2
  220.        Gz = Scale*12*4
  221.        Z = Z + Scale*12*2
  222.     }elseif( Type == "door2" ){
  223.        holoModel(0,"block")
  224.        holoScale(0,vec(Scale*0.5,Scale*3,Scale*3))
  225.        holoAng(0,ang(0,90,0))
  226.        Gx = Gy = Scale*12*2
  227.        Gz = Scale*12*4
  228.        Z = Z + Scale*12*2
  229.    }elseif( Type == "window" ){
  230.        holoModel(0,"block")
  231.        holoScale(0,vec(Scale*0.5,Scale*2,Scale*2))
  232.        Gx = Gy = Scale*12*2
  233.        Gz = Scale*12*4
  234.        Z = Z + Scale*12*2
  235.    }elseif( Type == "window2" ){
  236.        holoModel(0,"block")
  237.        holoScale(0,vec(Scale*0.5,Scale*2,Scale*2))
  238.        holoAng(0,ang(0,90,0))
  239.        Gx = Gy = Scale*12*2
  240.        Gz = Scale*12*4
  241.        Z = Z + Scale*12*2
  242.    }elseif( Type == "ramp" ){
  243.        holoModel(0,"block")
  244.        holoScale(0,vec(Scale*0.5,Scale*5,Scale*0.5))
  245.        holoAng(0,ang(0,ANGOFF,45))
  246.        Gx = Gy = Scale*12
  247.        Gz = Scale*12*4
  248.        Z = Z + Scale*12*2
  249.    }elseif( Type == "filler" ){
  250.        holoModel(0,"block")
  251.        holoScale(0,vec(Scale*0.5,Scale*4,Scale*1))
  252.        holoAng(0,ang(0,ANGOFF,0))
  253.        Gx = Gy = Scale*12
  254.        Gz = Scale*12*2
  255.        Z = Z + Scale*12*0.5
  256.    }
  257.    
  258.    # Set the holographic position after the respective values have been altered.
  259.    holoPos(0,vec(X,Y,Z))
  260.    
  261. }
  262.  
  263. # Sets the message shown in the chips information-popup.
  264. setName("RUST Building Tool by GlitchDetector
  265. Used by "+owner():name() + "
  266.  
  267. Current tool: "+Type+"")
  268.  
  269. # Checks if the player is holding down a key, used so you cannot execute two actions in a row without releasing a key.
  270. Holding = ( owner():keyReload() || owner():keyAttack1() || owner():keyAttack2() || owner():keyUse() )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement