Advertisement
Guest User

Prefab E2

a guest
Jun 26th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.66 KB | None | 0 0
  1. @name PreFab 1 v1
  2. @persist C PreFabs:table Selected:table Tempname:string Cat Temp:table
  3.  
  4. if (first() | duped() | dupefinished())
  5. {
  6.     runOnTick(1)
  7.     runOnChat(1)
  8.     runOnFile(1)
  9.     C = 1
  10.     Cat = 1
  11. }
  12.  
  13. if (owner():weapon():type() == "weapon_crowbar")
  14. {
  15.     local Props = Selected[1,array]
  16.     local Colors = Selected[2,array]
  17.     local Mats = Selected[3,array]
  18.     local Alphas = Selected[4,array]
  19.     local Poses = Selected[5,array]
  20.     local Angs = Selected[6,array]
  21.     local Models = Selected[7,array]
  22.     local Prop = owner():aimEntity()
  23.    
  24.     if (owner():keyAttack2())
  25.     {
  26.         if (Prop:isValid())
  27.         {
  28.             stoptimer("select")
  29.             timer("select",10)
  30.         }
  31.     }
  32.     if (clk("select"))
  33.     {
  34.         local Color = Prop:getColor()
  35.         local Mat = Prop:getMaterial()
  36.         local Alpha = Prop:getAlpha()
  37.         local Pos = entity():toLocal(Prop:pos())
  38.         local Ang = entity():toLocal(Prop:angles())
  39.         local Model = Prop:model()
  40.        
  41.         Prop:setColor(vec(0,0,255))
  42.         Prop:setAlpha(100)
  43.        
  44.         Props[Props:count()+1,entity] = Prop
  45.         Colors[Colors:count()+1,vector] = Color
  46.         Mats[Mats:count()+1,string] = Mat
  47.         Alphas[Alphas:count()+1,number] = Alpha
  48.         Poses[Poses:count()+1,vector] = Pos
  49.         Angs[Angs:count()+1,angle] = Ang
  50.         Models[Models:count()+1,string] = Model
  51.     }
  52.     if (owner():keyUse())
  53.     {
  54.         if (Prop:isValid())
  55.         {
  56.             stoptimer("deselect")
  57.             timer("deselect",10)
  58.         }
  59.     }
  60.     if (clk("deselect"))
  61.     {
  62.         for (I=1,Props:count())
  63.         {
  64.             if (Props[I,entity] == Prop)
  65.             {
  66.                 Prop:setColor(Colors[I,vector])
  67.                 Prop:setAlpha(Alphas[I,number])
  68.                
  69.                 Props:remove(I)    
  70.                 Colors:remove(I)
  71.                 Mats:remove(I)  
  72.                 Alphas:remove(I)  
  73.                 Poses:remove(I)  
  74.                 Angs:remove(I)
  75.                 Models:remove(I)
  76.             }
  77.         }
  78.     }
  79.    
  80.     Selected[1,array] = Props
  81.     Selected[2,array] = Colors
  82.     Selected[3,array] = Mats
  83.     Selected[4,array] = Alphas
  84.     Selected[5,array] = Poses
  85.     Selected[6,array] = Angs
  86.     Selected[7,array] = Models
  87.    
  88. }
  89.  
  90. if (chatClk(owner()))
  91. {
  92.     local SS = owner():lastSaid():explode(" ")
  93.    
  94.     if (SS[1,string]:lower() == ".psave" & SS[2,string] != "" & SS[2,string] != " ")
  95.     {
  96.         if (fileCanWrite())
  97.         {
  98.             local Prefab = vonEncode(Selected)
  99.             fileWrite(">e2shared/presets_" + SS[2,string]:lower() + ".txt" , Prefab)  
  100.            
  101.             local Props = Selected[1,array]
  102.             local Colors = Selected[2,array]
  103.             local Alphas = Selected[4,array]
  104.            
  105.             for (I=1,Props:count())
  106.             {
  107.                 Props[I,entity]:setColor(Colors[I,vector])
  108.                 Props[I,entity]:setAlpha(Alphas[I,number])
  109.             }
  110.             Selected:remove(1)
  111.             Selected:remove(2)
  112.             Selected:remove(3)
  113.             Selected:remove(4)
  114.             Selected:remove(5)
  115.             Selected:remove(6)
  116.             Selected:remove(7)
  117.             hideChat(1)
  118.             print("File Saved")
  119.         }
  120.         else
  121.         {
  122.             hideChat(1)
  123.             print("File Saving on cooldown")
  124.         }
  125.     }
  126.    
  127.     if (SS[1,string]:lower() == ".pdsave" & SS[2,string] != "" & SS[2,string] != " ")
  128.     {
  129.         if (fileCanWrite())
  130.         {
  131.             local Prefab = vonEncode(Selected)
  132.             fileWrite(">e2shared/presets_" + SS[2,string]:lower() + ".txt" , Prefab)  
  133.            
  134.             local Props = Selected[1,array]
  135.            
  136.             for (I=1,Props:count())
  137.             {
  138.                 Props[I,entity]:propDelete()
  139.             }
  140.             Selected:remove(1)
  141.             Selected:remove(2)
  142.             Selected:remove(3)
  143.             Selected:remove(4)
  144.             Selected:remove(5)
  145.             Selected:remove(6)
  146.             Selected:remove(7)
  147.             hideChat(1)
  148.             print("File Saved and props removed")
  149.         }
  150.         else
  151.         {
  152.             hideChat(1)
  153.             print("File Saving on cooldown")
  154.         }
  155.     }
  156.    
  157.     if (SS[1,string]:lower() == ".premsel")
  158.     {
  159.         local Props = Selected[1,array]
  160.        
  161.         for (I=1,Props:count())
  162.         {
  163.             Props[I,entity]:propDelete()
  164.         }
  165.         Selected:remove(1)
  166.         Selected:remove(2)
  167.         Selected:remove(3)
  168.         Selected:remove(4)
  169.         Selected:remove(5)
  170.         Selected:remove(6)
  171.         Selected:remove(7)
  172.         hideChat(1)
  173.         print("Selection has been removed")
  174.     }
  175.    
  176.     if (SS[1,string]:lower() == ".punsel")
  177.     {
  178.         local Props = Selected[1,array]
  179.         local Colors = Selected[2,array]
  180.         local Alphas = Selected[4,array]
  181.        
  182.         for (I=1,Props:count())
  183.         {
  184.             Props[I,entity]:setColor(Colors[I,vector])
  185.             Props[I,entity]:setAlpha(Alphas[I,number])
  186.         }
  187.         Selected:remove(1)
  188.         Selected:remove(2)
  189.         Selected:remove(3)
  190.         Selected:remove(4)
  191.         Selected:remove(5)
  192.         Selected:remove(6)
  193.         Selected:remove(7)
  194.         hideChat(1)
  195.         print("Selection deselected")
  196.     }
  197.    
  198.     if (SS[1,string]:lower() == ".pload")
  199.     {
  200.         if (fileCanLoad() & !fileLoading())
  201.         {
  202.             fileLoad(">e2shared/presets_" + SS[2,string]:lower()+".txt")
  203.             print("Loading Preset...")
  204.             Tempname = SS[2,string]:lower()
  205.         }
  206.         else
  207.         {
  208.             print("File cannot be loaded")    
  209.         }
  210.         hideChat(1)
  211.     }
  212.    
  213.     if (SS[1,string]:lower() == ".phelp")
  214.     {
  215.         print("Commands and descriptions are as following:")
  216.         print(".phelp  -  Displays this help message")
  217.         print(".psave  -  Saves the current selection to the given name")
  218.         print(".pdsave  -  Saves selection to the given name and removes afterwards")
  219.         print(".punsel  -  Unselects all selected props without saving")
  220.         print(".premsel  -  Removes currently selected props without saving")
  221.         hideChat(1)
  222.     }
  223. }
  224.  
  225. if (fileClk() & fileLoaded())
  226. {
  227.     local CC = PreFabs:count()
  228.     local Temptable = table()
  229.     Temptable[1,string] = Tempname
  230.     local Pref = vonDecodeTable(fileRead())
  231.     local Tem = Temptable:merge(Pref)
  232.     PreFabs[CC+1,table] = Tem
  233.     timer("init",100)
  234.     print("Loaded preset " + Tempname)
  235. }
  236.  
  237. if (clk("init"))
  238. {
  239.     if (propCanCreate())
  240.     {
  241.         if (Temp:count() > 0)
  242.         {
  243.             local Props = Temp[1,array]
  244.             local Colors = Temp[2,array]
  245.             local Mats = Temp[3,array]
  246.             local Alphas = Temp[4,array]
  247.             local Poses = Temp[5,array]
  248.             local Angs = Temp[6,array]
  249.             local Models = Temp[7,array]
  250.            
  251.             if (C<Models:count()+1)
  252.             {
  253.                 if (!Props[C,entity]:isValid())
  254.                 {
  255.                     Props[C,entity] = propSpawn(Models[C,string],1)
  256.                     Props[C,entity]:setColor(Colors[C,vector])
  257.                     Props[C,entity]:setAlpha(Alphas[C,number])
  258.                     Props[C,entity]:setMaterial(Mats[C,string])
  259.                     Props[C,entity]:setPos(entity():toWorld(Poses[C,vector]))
  260.                     Props[C,entity]:setAng(entity():toWorld(Angs[C,angle]))
  261.                 }
  262.                 else
  263.                 {
  264.                     C++  
  265.                 }
  266.             }
  267.             else
  268.             {
  269.                 C = 2
  270.                 Cat++
  271.                 if (Cat > PreFabs:count())
  272.                 {
  273.                     Cat = 1
  274.                 }
  275.                 Temp[1,array] = PreFabs[Cat,table][2,array]
  276.                 Temp[2,array] = PreFabs[Cat,table][3,array]
  277.                 Temp[3,array] = PreFabs[Cat,table][4,array]
  278.                 Temp[4,array] = PreFabs[Cat,table][5,array]
  279.                 Temp[5,array] = PreFabs[Cat,table][6,array]
  280.                 Temp[6,array] = PreFabs[Cat,table][7,array]
  281.                 Temp[7,array] = PreFabs[Cat,table][8,array]
  282.             }
  283.         }
  284.         else
  285.         {
  286.             Temp[1,array] = PreFabs[Cat,table][2,array]
  287.             Temp[2,array] = PreFabs[Cat,table][3,array]
  288.             Temp[3,array] = PreFabs[Cat,table][4,array]
  289.             Temp[4,array] = PreFabs[Cat,table][5,array]
  290.             Temp[5,array] = PreFabs[Cat,table][6,array]
  291.             Temp[6,array] = PreFabs[Cat,table][7,array]
  292.             Temp[7,array] = PreFabs[Cat,table][8,array]
  293.         }
  294.     }
  295.     timer("init",100)
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement