@name Prop 2 Holo Alt
@persist [O]:entity Slc:array [CntrPos]:vector [Wep MdlStr ClrStr PosStr AngStr MatStr FinTxt FilNam]:string Svng N
interval(10)
if(first())
{
    runOnChat(1)
    
    Wep = "weapon_physcannon"
    
    O = owner()
    
    function vector2 entity:validate(R:array)
    {
        Val = 0
        Index = 0
        foreach(I, TE:entity = R)
        {
            if(TE == This)
            {
                Val = 1
                Index = I
            }
        }
        return vec2(Val,Index)
    }
}

if(Svng)
{
    if(changed(Svng))
    {
        
        Ps = vec()
        foreach(I, TE:entity = Slc)
        {
            Ps += TE:pos()
        }
        CntrPos = Ps/Slc:count()
        holoCreate(O:id(),CntrPos,vec())
    }
    
    if(N < Slc:count())
    {
        while(perf() & N < Slc:count())
        {
            N++
            
            local TE = Slc[N,entity]
            local NCma = N < Slc:count() ? "," : ""
            
            MdlStr += "\"" + TE:model() + "\"" + NCma
            ClrStr += "vec4(" + toString(TE:getColor4()) + ")" + NCma
            PosStr += "vec(" + toString(round(holoEntity(O:id()):toLocal(TE:pos()),4)) + ")" + NCma
            AngStr += "ang(" + toString(round(holoEntity(O:id()):toLocal(TE:angles()),4)) + ")" + NCma
            MatStr += "\"" + TE:getMaterial() + "\"" + NCma
        }
    }else
    {
        FinTxt = "@name "+FilNam:replace(".txt","") +"
@persist [P2H_Mdl P2H_Clr P2H_Pos P2H_Ang P2H_Mat]:array P2H_Int P2H_Ready
if(first())
{
    runOnTick(1)
    P2H_Mdl = array(" + MdlStr + ")
    P2H_Clr = array(" + ClrStr:replace("[",""):replace("]","") + ")
    P2H_Pos = array(" + PosStr:replace("[",""):replace("]","") + ")
    P2H_Ang = array(" + AngStr:replace("[",""):replace("]","") + ")
    P2H_Mat = array(" + MatStr + ")
}

if(!P2H_Ready)
{
    while(P2H_Int < P2H_Mdl:count())
    {
        P2H_Int++
        local Offset = 0
        local TI = P2H_Int + Offset
        local E = entity()
        holoCreate(TI,E:toWorld(P2H_Pos[P2H_Int,vector]),vec(1),E:toWorld(P2H_Ang[P2H_Int,angle]))
        holoModel(TI,P2H_Mdl[P2H_Int,string])
        holoColor(TI,P2H_Clr[P2H_Int,vector4])
        holoMaterial(TI,P2H_Mat[P2H_Int,string])
        holoParent(TI,E)
    }
    P2H_Ready = P2H_Int == P2H_Mdl:count()
}"
        fileWrite(">e2shared/" + FilNam,FinTxt)
        hint("SAVED " + FilNam:upper() + " IN E2SHARED FOLDER",10)
        selfDestruct()
    }
}else
{
    if(O:weapon():type() == Wep)
    {
        Act = O:keyUse()
        if(changed(Act) & Act)
        {
            local AE = O:aimEntity()
            if(AE:isValid())
            {
                local Val = AE:validate(Slc)
                if(Val:x())
                {
                    holoDelete(Slc[Val:y(),entity]:id())
                    Slc:remove(Val:y())
                }else
                {
                    Slc:pushEntity(AE)
                    holoCreate(AE:id(),AE:pos(),vec(-1.05),AE:angles())
                    holoModel(AE:id(),AE:model())
                    holoColor(AE:id(),vec4(0,255,0,255))
                    holoMaterial(AE:id(),AE:getMaterial())
                    holoDisableShading(AE:id(),1)
                }
                hint("COUNT: " + Slc:count(),3)
            }
        }
    }
    
    if(chatClk(O))
    {
        local X = lastSaid():lower():explode(" ")
        switch(X[1,string])
        {
            case "-s",
                hideChat(1)
                if(Slc:count())
                {
                    local FN = X:concat("_",2)
                    FilNam = (FN + (FN:find(".txt") ? "" : ".txt")):lower()
                    Svng = 1
                }else
                {
                    hint("NO PROPS SELECTED! PLEASE SELECT SOME PROPS AND THEN SAVE!",7.5)
                }
            break
        }
    }
}
