@name Cerealize
@persist MetaData:table [Entity Owner]:entity Name:string

if(first()) {
    Name="saucer2_bridge_v1"
    Global=1
    
    Entity=entity()
    Owner=owner()
    Objects=table()
    
    findByClass("prop_physics")
    findSortByDistance(Entity:toWorld(vec(0,0,-100)))
    
    local Index=0
    
    foreach(I,V:entity=findToArray()) {
        if(V:owner()!=Owner) {continue}
        Index++
        Objects[Index,table]=table(
            "pos"=Global ? V:pos() : Entity:toLocal(V:pos()),
            "ang"=Global ? V:angles() : Entity:toLocal(V:angles()),
            "mat"=V:getMaterial(),
            "col"=V:getColor(),
            "mdl"=V:model(),
            "alpha"=V:getAlpha()
        )
    }
    
    printColor(vec(0,255,255),"[Cereal] ",vec(255),"Saved ",vec(0,255,0),Index:toString(),vec(255)," props.")
    MetaData=table(
        "Global"=Global,
        "Objects"=Objects
    )
    local String=vonEncode(MetaData)
    fileWrite("cereal_"+Name+".txt",String)
    selfDestruct()
}
