Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name HoloDetailer V5.5
- @outputs Props:array Ops
- @persist [Base TProp]:entity
- @persist Int Go Key Alpha FinalInvalid Sounds TryDelete Version SwitchInterval Cycle SearchRadius
- @persist [Weapon FileName CustomName Append Tab]:string
- @persist [TVec Offset PreBase]:vector
- @persist TAng:angle
- @trigger none
- if(duped() | dupefinished()){reset()}
- ############################################
- #SETTINGS YOU CAN CHANGE####################
- ############################################
- Key=owner():keyAttack2() #Key used to select/deselect props
- Offset=vec(0,0,200) #Offset of preview holos
- Weapon="weapon_crowbar" #Weapon/tool that must be used
- Alpha=120 #Transparency of selected objects
- Sounds=1 #Play sound effects: 1=on, 0=off
- SwitchInterval=40 #How often to start a new switch statement
- #Interval
- ###########################################
- ###########INSTRUCTIONS####################
- ###########################################
- #Default tool to use this chip is the HL2 Crowbar, if unavailable, change it in the settings above.
- #Use the chat command !base to define a base prop which all others will be relative to.
- #If no base is set using the command, the first prop you select will become the base.
- #If you want to change your base, you must reset the process.
- #Default: Right click with the crowbar to add/remove props or entitities from the selection list.
- #Can also add all props/entities constrained to another to the list using the !constraints command.
- #Use the chat command !go to validate props and write a .txt file, the path to the file will be given after the process is complete.
- #Custom filename can be set with the !name command. Process can be reset with the !reset command.
- #Delete all highlighted props with the !delete command.
- #You can check the amount of props currently selected with the !check command
- #Conversion is not instant, approximate rate is 4 props per second.
- #Correctly formatted E2 holo code in the form of a switch statement will be written to the .txt file, please note that Windows Notepad does not show the linebreaks, I recommend Notepad++.
- #In a new E2, create a "N" number variable, a "Cycle" variable and a "Base" entity variable. These are only default values and can be changed.
- #The "Base" variable must be set for the holos to appear correctly.
- #Holos use a incrementing value so as to not overwrite each other if new holos need to be added to an existing chip.
- ###COMMANDS
- # !base = Select a Base
- # !go = Start Conversion Process
- # !name = Define a filename
- # !check = Check amount
- # !reset = Reset Process/E2
- ###########
- ############################################ FILES OF THE SAME NAME WILL BE OVERWRITTEN ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- #STUFF YOU SHOULD NOT TOUCH#################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- ############################################
- Version=5.5
- setName("[Holo Detailer v"+Version+"]\n"+"Selected: "+Props:count()+(CustomName != "null" ? ("\n"+"Filename: "+CustomName) : ""))
- if(first())
- {
- entity():soundPlay("reset",0,"buttons/blip2.wav")
- runOnChat(1)
- runOnLast(1)
- hint("Holo Detailer: Version "+Version+"\nCreated by Ixil",3)
- hint("Open E2 for Instructions",3)
- printColor(vec(255,50,50),"[Your server holo limit may vary...]")
- printColor(vec(255,50,50),"[FILES OF THE SAME NAME WILL BE OVERWRITTEN]")
- holoDeleteAll()
- Int=1
- CustomName="null"
- Tab=toChar(9)
- SearchRadius=150 #Radius of Area to Search for Entities
- function number verifyEntity(E:entity)
- {
- local Errors=0
- local I=1
- for(I=1,Props:count())
- {
- if(E==Props[I,entity])
- {
- Errors++
- }
- }
- if(E==Base)
- {
- Errors++
- }
- if(Errors>0)
- {
- return 0
- }
- else
- {
- return 1
- }
- }
- function number validateArray(Arr:array)
- {
- local Invalid=0
- local I=1
- for(I=1,Arr:count())
- {
- if(!Arr[I,entity]:isValid())
- {
- Invalid++
- hint("Invalid Found",1)
- }
- }
- if(Invalid>0)
- {
- return Invalid
- }
- else
- {
- return 0
- }
- }
- function void removeEntity(E:entity)
- {
- local I=1
- for(I=1,Props:count())
- {
- if(E==Props[I,entity])
- {
- Props:remove(I)
- }
- }
- }
- function void resetProps()
- {
- local I=1
- for(I=1,Props:count())
- {
- Props[I,entity]:setAlpha(255)
- }
- Props=array()
- hint("Prop Array Cleared",2)
- Base:setColor(PreBase)
- Base=noentity()
- }
- function deleteProps()
- {
- local I=1
- local Prop=noentity()
- for(I=1,Props:count())
- {
- Prop=Props[I,entity]
- Prop:propDelete()
- }
- Props=array()
- }
- function number processProp(Num)
- {
- local TProp=Props[Num,entity]
- if(frac(Num/SwitchInterval)==0)
- {
- #hint("This interval is even: "+Num/2,2)
- Cycle++
- Append+=Tab+Tab+"Cycle++\n"+Tab+"break\n\n"+Tab+"case "+Cycle+",\n"
- }
- Append+=Tab+Tab+"###Beginning Loop: "+Num+"\n"
- Append+=Tab+Tab+"#############################\n"
- local TVec=Base:toLocal(TProp:pos())#TProp:pos()-Base:pos()
- holoPos(Num,Base:toWorld(TVec)+Offset)
- Append+=Tab+Tab+"holoPos(N,Base:toWorld(vec("+round(TVec:x(),3)+","+round(TVec:y(),3)+","+round(TVec:z(),3)+")) )\n"
- holoAng(Num,Base:toWorld( Base:toLocal(TProp:angles()) ))
- local TAng=Base:toLocal(TProp:angles())
- Append+=Tab+Tab+"holoAng(N,Base:toWorld( ang("+round(TAng:pitch())+","+round(TAng:yaw())+","+round(TAng:roll())+") ))\n"
- holoModel(Num,TProp:model())
- Append+=Tab+Tab+"holoModel(N,"+toChar(34)+TProp:model()+toChar(34)+")\n"
- holoMaterial(Num,TProp:getMaterial())
- Append+=Tab+Tab+"holoMaterial(N,"+toChar(34)+TProp:getMaterial()+toChar(34)+")\n"
- holoColor(Num,TProp:getColor())
- local TVec=TProp:getColor()
- Append+=Tab+Tab+"holoColor(N,"+"vec("+round(TVec:x(),2)+","+round(TVec:y(),2)+","+round(TVec:z(),2)+"))\n"
- holoParent(Num,1)
- Append+=Tab+Tab+"holoParent(N,Base)\n"
- Append+=Tab+Tab+"#############################\n"
- Append+=Tab+Tab+"N++\n"
- if(Num==Props:count())
- {
- Append+=Tab+Tab+"Cycle=0\n"+Tab+"break\n"
- }
- if(!holoEntity(Num):isValid())
- {
- FinalInvalid++
- }
- if(fileCanWrite())
- {
- return 1
- }
- else
- {
- return 0
- }
- }
- }
- if(Go)
- {
- interval(50)
- }
- else
- {
- interval(50)
- }
- if(chatClk(owner()))
- {
- local LS=owner():lastSaid()
- local Explode=LS:explode(" ")
- if(Explode:count()>1)
- {
- if(Explode[1,string]=="!name")
- {
- CustomName=Explode[2,string]
- printColor(vec(255,255,255),"Filename set to: "+CustomName)
- hideChat(1)
- }
- if(Explode[1,string]=="!radius")
- {
- SearchRadius=clamp(Explode[2,string]:toNumber(),32,512)
- printColor(vec(255,255,255),"Area Select radius set to: "+SearchRadius)
- hideChat(1)
- }
- }
- switch(LS)
- {
- case"!base",
- if(!Base)
- {
- Base=owner():aimEntity()
- PreBase=Base:getColor()
- Base:setColor(vec(255,0,0))
- hint("Base: "+Base:model(),2)
- }
- else
- {
- hint("Base already set, reset to change.",2)
- }
- hideChat(1)
- break
- case"!go",
- local I=0
- printColor(vec(255,255,255),"Starting process...")
- if(Base:isValid()){I++}else{hint("Base not found",3)}
- if(Props:count()>0){I++}else{hint("No Props selected",3)}
- if(I==2)
- {
- holoDeleteAll()
- #Props=Base:getConstraints()
- timer("validate",500)
- if(CustomName!="null")
- {
- FileName=CustomName+".txt"
- }
- else
- {
- FileName="Holo Detailer-"+randint(1,999)+".txt"
- }
- Cycle=1
- Append="#############################\n####Holo Detailer by Ixil####\n#############################\n"
- Append+="@name "+FileName+"\n@persist Cycle N Max Phase Go Base:entity\n@trigger none\n
- if(first())\n
- {\n"
- +Tab+"Max="+Props:count()+"\n"
- +Tab+"if(entity():hasConstraints("+toChar(34)+"Weld"+toChar(34)+")){Base=entity():isWeldedTo()}else{Base=entity():isConstrainedTo(1):isConstrainedTo(1)}\n"
- +Tab+"N=1\n"
- +Tab+"Cycle=1"
- +Tab+"Phase=1\n"
- +Tab+"timer("+toChar(34)+"Go"+toChar(34)+",2500)\n
- }\n if(clk("+toChar(34)+"Go"+toChar(34)+")){Go=1,hint("+toChar(34)+"Building..."+toChar(34)+",2)}\n"+
- "if(Phase==1 & Go)\n
- {\n"
- +Tab+"interval(75)\n"
- +Tab+"if(N<=Max)\n"
- +Tab+"{\n"
- +Tab+Tab+"local E=holoCreate(N)\n"
- +Tab+Tab+"holoParent(N,Base)\n"
- +Tab+Tab+"N++\n"
- +Tab+"}\n"
- +Tab+"else\n"
- +Tab+"{\n"
- +Tab+Tab+"N=1\n"
- +Tab+Tab+"Phase=2\n"
- +Tab+"}\n
- }\n"
- Append+="if(Cycle!=0 & Go & Phase==2)\n
- {\n"
- +Tab+"interval(80)\n"
- +Tab+"switch(Cycle)\n"
- +Tab+"{\n"
- Append+=Tab+Tab+"case 1,\n"+Tab+Tab+"N=1\n"
- }
- hideChat(1)
- break
- case"!reset",
- hint("Resetting...",2)
- holoDeleteAll()
- Int=1
- if(Base:isValid())
- {
- Base:setColor(PreBase)
- Base=noentity()
- }
- resetProps()
- entity():soundPlay("reset",0.276,"buttons/blip2.wav")
- hideChat(1)
- break
- case"!check",
- print(_HUD_PRINTCENTER,"Current Prop Count: "+Props:count())
- hideChat(1)
- break
- case"!area",
- findByClass("prop_physics")
- findIncludeClass("prop_physics")
- findInSphere(owner():aimPos(),SearchRadius)
- local Found = findToArray()
- local I=1
- local Added=0
- local TEnt=noentity()
- if(Base:isValid())
- {
- while(perf() & I<=Found:count())
- {
- #if(perf())
- #{
- TEnt=Found[I,entity]
- if(TEnt!=Base)
- {
- TEnt:setAlpha(Alpha)
- Props:pushEntity(TEnt)
- Added++
- }
- I++
- #}
- }
- if(Sounds)
- {
- print(_HUD_PRINTCENTER,"Added "+Added+" Props of "+Found:count()+"\nTotal Count: "+Props:count())
- owner():aimEntity():soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
- }
- }
- hideChat(1)
- break
- case"!constraints",
- local Constraints=owner():aimEntity():getConstraints()
- local I=1
- local Added=0
- local TEnt=noentity()
- if(Base:isValid())
- {
- for(I=1,Constraints:count())
- {
- if(perf())
- {
- TEnt=Constraints[I,entity]
- if(verifyEntity(TEnt)==1)
- {
- TEnt:setAlpha(Alpha)
- Props:pushEntity(TEnt)
- Added++
- }
- I++
- }
- }
- if(Sounds)
- {
- print(_HUD_PRINTCENTER,"Added "+Added+" Props of "+Constraints:count()+"\nTotal Count: "+Props:count())
- owner():aimEntity():soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
- }
- }
- else
- {
- hint("Please define a Base",3)
- }
- hideChat(1)
- break
- case"!delete",
- if(Base:isValid() & Props:count()>0)
- {
- printColor(vec(255,0,0),"This function will delete all highlighted props, cannot be undone.")
- printColor(vec(255,0,0),"Type !confirm to delete.")
- TryDelete=1
- timer("resetDelete",10000)
- }
- hideChat(1)
- break
- case"!confirm",
- if(TryDelete)
- {
- printColor(vec(255,0,0),"Removing highlighted props.")
- deleteProps()
- }
- else
- {
- printColor(vec(255,0,0),"Request timed out.")
- }
- hideChat(1)
- break
- default,
- hideChat(0)
- break
- }
- }
- if(clk("resetDelete"))
- {
- TryDelete=0
- }
- if(clk("validate"))
- {
- printColor(vec(255,255,255),"Please wait, validating prop array...")
- local Invalid=validateArray(Props)
- if(Invalid==0)
- {
- timer("start",500)
- }
- else
- {
- printColor(vec(255,0,0),Invalid+" Invalid Props Found. Type !reset to start over")
- }
- }
- if(clk("start"))
- {
- printColor(vec(0,255,0),"Props Validated, process started")
- Go=1
- }
- if(changed(Key) & Key & owner():weapon():type()==Weapon )
- {
- local TEnt=owner():aimEntity()
- if(TEnt:isValid() & Base:isValid() & TEnt!=Base & TEnt!=entity())
- {
- if(!TEnt:isPlayer() & TEnt:owner()==entity():owner())
- {
- if(verifyEntity(TEnt)==1)
- {
- TEnt:setAlpha(Alpha)
- Props:pushEntity(TEnt)
- print(_HUD_PRINTCENTER,"Added...\nTotal Count: "+Props:count())
- if(Sounds)
- {
- TEnt:soundPlay(1,1.0,"buttons/button_synth_positive_01.wav")
- }
- }
- else
- {
- TEnt:setAlpha(255)
- removeEntity(TEnt)
- print(_HUD_PRINTCENTER,"Removed...\nTotal Count: "+Props:count())
- if(Sounds)
- {
- TEnt:soundPlay(2,1.0,"buttons/button_synth_negative_02.wav")
- }
- }
- }
- else
- {
- hint("Invalid Selection",1)
- }
- }
- else
- {
- if(!Base:isValid())
- {
- Base=owner():aimEntity()
- PreBase=Base:getColor()
- Base:setColor(vec(255,0,0))
- hint("Base: "+Base:model(),2)
- }
- else
- {
- hint("Error",1)
- }
- }
- }
- if(Go & Base:isValid())
- {
- if(Int<=Props:count())
- {
- if(processProp(Int)==1)
- {
- Int++
- }
- }
- else
- {
- Append+="}\n}\n###PROCESS COMPLETE###"
- fileWrite(">e2shared/"+FileName,Append)
- printColor(vec(0,255,0),"Process Complete: "+(Props:count()-FinalInvalid)+" of "+Props:count()+" holos created")
- printColor(vec(255,93,0),"File Saved As: [STEAM DIRECTORY]/SteamApps/common/GarrysMod/garrysmod/data/Expression2/e2shss/"+FileName)
- printColor(vec(0,255,0),"Type !delete to remove selected props")
- printColor(vec(255,255,0),"Type !reset to begin again")
- Go=0
- Int=1
- }
- }
- if(last())
- {
- resetProps()
- if(Base)
- {
- Base:setColor(PreBase)
- }
- holoDeleteAll()
- }
- Ops=ops()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement