@name Holosaver2
@persist File:string L:string Use AIM:entity  HoloEntSet Save
@persist [LocalPos Model Color Angle Material Props]:array Index Can
@persist [PosS ModelS ColorS AngleS MaterialS PreCode AfterCode PropsS]:string Output:string I Arrr:array TEMP:entity ID EntArr:array HoloEnt:entity
 
#do not edit, its working. you only can destroy it with your big ugly hands
runOnChat(1)
interval(10)
File="ChassieID-"+randint(1,9999)+".txt"
L=owner():lastSaid()
Use=owner():keyUse()
 
AIM=owner():aimEntity()
if(first()){
   
    function number checkContain(AIM:entity){
        local TVAL = 0
        for(Ixxx=1,EntArr:count()){
            ETemp=EntArr[Ixxx,entity]
            if(AIM == ETemp){ TVAL=1 }
        }
        return 0 + TVAL
    }
   
    print("Aim at middle (that point where the expression2 later should be")
    print("and type !set")
PreCode="
@name "+File:replace(".txt","")+" HoloSaver \n
@persist [LocalPos Model Color Angle Material]:array Holos I\n
interval(10)\n
Shade=0\n
function void doneOnce()\n
{\n
  \n
}\n
function void done()\n
{\n
  \n
}\n
 
 
if(first()|dupefinished()){\n
##Data\n
"  
AfterCode="
#Data\n
}\n
    if(I<Holos&holoCanCreate())\n
    {\n
        I++\n
        holoCreate(I)\n
        holoModel(I,Model[I,string])\n
        holoPos(I,entity():toWorld(LocalPos[I,vector]))\n
        holoAng(I,entity():toWorld(Angle[I,angle]))\n
        holoScale(I,vec(1,1,1))\n
        holoColor(I,Color[I,vector4])\n
        holoMaterial(I,Material[I,string])\n
        holoRenderFX(I,Shade)\n
        holoParent(I,entity())\n
    }elseif(changed(I)&I==Holos){\n
        doneOnce()\n
    }else{\n
        done()\n
    }\n#HoloSaver / HSbase Script by gamerpaddy
"
}
if(chatClk(owner())&L:find("!set"))
{
    hideChat(1)
    print("You have set the Center! Now type !start to start selection")
    holoCreate(1,owner():aimPos())
    holoScale(1,vec(0.4,0.4,0.4))
    holoColor(1,vec(255,0,0))
    HoloEntSet=1
}else{
    hideChat(0)
}
if(chatClk(owner())&L:find("!start"))
{
    hideChat(1)
    print("Press Use to mark a prop.")
    print("selected props are green")
    print("After this, type !save")
   
    Can=1
}else{
    hideChat(0)
}
if(chatClk(owner())&L:find("!stop"))
{
    hideChat(1)#isnt working
    print("stopped")
    Can=0
   
}else{
    hideChat(0)#isnt working
}
if(findCanQuery()){
    findByClass("prop_physics")
    findAllowPlayerProps(owner():name())
    Arrr=findToArray()
}
if(Can){
    Index++
    if(changed(owner():keyUse())&owner():keyUse()){
        if(AIM:type()=="prop_physics"){
            if( !checkContain(AIM)){
                    if(AIM:model() != ""){
                        TEMP=AIM
                        ID++
                        EntArr[ID,entity]=AIM
                        LocalPos:setVector(ID,holoEntity(1):toLocal(TEMP:pos()))
                        Model:setString(ID,AIM:model())
                        Color:setVector4(ID,AIM:getColor4())
                        Angle:setAngle(ID,holoEntity(1):toLocal(TEMP:angles()))
                        Material:setString(ID,TEMP:getMaterial())
                        Props:setEntity(ID,TEMP)
                        AIM:setColor(vec4(0,255,0,155))
                        PropsS+=";"+TEMP:id()+";"
                        print("ID:"+ID+" added!")
                    }
            }else{
                print("Dont select props twice")
            }
   
        }else{
            print("not a prop_physics!")
        }
    }
    if(Index > Model:count()){
                   
    }
}
if(chatClk(owner())&L:find("!save"))
{
    Can = 0
    hideChat(1)
    print(Props:count())
    Save=1
    Index=0
    Index=Model:count()
}else{
    hideChat(0)
}
if(Save){
    if(I<Index){
        I++
        #print("Convert..."+I)
        PosS+="LocalPos["+I+",vector]=vec("+round(LocalPos[I,vector]:x(),4)+","+round(LocalPos[I,vector]:y(),4)+","+round(LocalPos[I,vector]:z(),4)+")\n"
        ModelS+="Model["+I+",string]=\""+Model[I,string]+"\"\n"
        ColorS+="Color["+I+",vector4]=vec4("+Color[I,vector4]:x()+","+Color[I,vector4]:y()+","+Color[I,vector4]:z()+","+Color[I,vector4]:w()+")\n"
        AngleS+="Angle["+I+",angle]=ang("+round(Angle[I,angle]:pitch(),4)+","+round(Angle[I,angle]:yaw(),4)+","+round(Angle[I,angle]:roll(),4)+")\n"
        MaterialS+="Material["+I+",string]=\""+Material[I,string]+"\"\n"    
        EntArr[I,entity]:setColor(Color[I,vector4])
    }
    if(I == Index){
        print("Save...")
        Output=PreCode+PosS+ModelS+ColorS+AngleS+MaterialS+"Holos="+Index+"\n"+AfterCode
        fileAppend(File,Output)
        print("Saved as "+File)
        print("go to garrysmod/data/e2files and copy "+File+" to garrysmod/data/Expression2")
        print("type !reset, to reset all data")
        Can=0
        Save=0
    }
}
if(chatClk(owner())&L:find("!reset"))
{
    hideChat(1)
    for(IN=0,Props:count()){
        Props[IN,entity]:setColor(Color[IN,vector4])  
    }
    Index=0
    Pos=array()
    Model=array()
    Angle=array()
    Material=array()
    Color=array()
    LocalPos=array()
   
    print("Resetted!")
    Can=0
}else{
    hideChat(0)
}
