@name Generic_Test_E2_#1
@persist Props:table B:entity Time Index
@model models/hunter/blocks/cube075x075x075.mdl

if(first()) {
    runOnLast(1)
    runOnTick(1)
    
    function number hid(N) {
        Index += N
        return Index
    }
    function vector scale(X,Y,Z) {
        return vec(X,Y,Z)
    }
    function vector scale(X) {
        return scale(X,X,X)
    }
    function number u(Mod) {
        return 47.45*Mod
    }
    function vector u(X,Y,Z) {
        return 47.45*vec(X,Y,Z)
    }
    
    function entity spawnChurch(Pos:vector, Ang:angle) {
        local Prop = noentity()
        #Bill Makes Shit Much Complicated.
        #Kron Made it Simple.
        #:3
        
        Prop = propSpawn("models/hunter/blocks/cube8x8x2.mdl",Pos,Ang,1)
        Prop:setMaterial("models/props_wasteland/concretefloor010a")
        Props:pushEntity(Prop)
        B = Prop
        
        local Props2Spawn = table(
            "1"=table("model"="models/hunter/blocks/cube4x4x2.mdl","pos"=B:toWorld(u(-6,0,0.5)),"ang"=B:toWorld(ang(0,0,0)),"material"="models/props_wasteland/concretefloor010a","color"=vec4(255, 255, 255, 255)),
            "2"=table("model"="models/hunter/blocks/cube8x8x2.mdl","pos"=B:toWorld(u(8,0,0)),"ang"=B:toWorld(ang(0,0,0)),"material"="models/props_wasteland/concretefloor010a","color"=vec4(255, 255, 255, 255)),
            "3"=table("model"="models/hunter/blocks/cube2x4x05.mdl","pos"=B:toWorld(u(9,0,1.75)),"ang"=B:toWorld(ang(0,0,0)),"material"="models/props/de_inferno/woodfloor008a","color"=vec4(255, 255, 255, 255)),
            "4"=table("model"="models/hunter/blocks/cube1x2x025.mdl","pos"=B:toWorld(u(8.25,0,2.5)),"ang"=B:toWorld(ang(90,0,0)),"material"="models/props_wasteland/wood_fence01a","color"=vec4(255, 255, 255, 255)),
            "5"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(5,2,1.5)),"ang"=B:toWorld(ang(0,-10,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "6"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(3,2,1.5)),"ang"=B:toWorld(ang(0,-6,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "7"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(1,2,1.5)),"ang"=B:toWorld(ang(0,-10,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "8"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(-1,2,1.5)),"ang"=B:toWorld(ang(0,8,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "9"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(-1,-2,1.5)),"ang"=B:toWorld(ang(0,2,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "10"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(1,-2,1.5)),"ang"=B:toWorld(ang(0,-7,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "11"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(3,-2,1.5)),"ang"=B:toWorld(ang(0,-6,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "12"=table("model"="models/props_trainstation/traincar_seats001.mdl","pos"=B:toWorld(u(5,-2,1.5)),"ang"=B:toWorld(ang(0,9,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "13"=table("model"="models/hunter/blocks/cube6x8x05.mdl","pos"=B:toWorld(u(8,-3.75,4.5)),"ang"=B:toWorld(ang(90,-90,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "14"=table("model"="models/hunter/blocks/cube6x8x05.mdl","pos"=B:toWorld(u(0,-3.75,4.5)),"ang"=B:toWorld(ang(90,-90,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "15"=table("model"="models/hunter/blocks/cube6x8x05.mdl","pos"=B:toWorld(u(0,3.75,4.5)),"ang"=B:toWorld(ang(90,90,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "16"=table("model"="models/hunter/blocks/cube6x8x05.mdl","pos"=B:toWorld(u(8,3.75,4.5)),"ang"=B:toWorld(ang(90,90,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "17"=table("model"="models/hunter/blocks/cube4x8x05.mdl","pos"=B:toWorld(u(11.75,0,5.5)),"ang"=B:toWorld(ang(90,0,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "18"=table("model"="models/hunter/blocks/cube2x4x05.mdl","pos"=B:toWorld(u(11.75,2,2.5)),"ang"=B:toWorld(ang(90,0,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "19"=table("model"="models/props_debris/walldestroyed05a.mdl","pos"=B:toWorld(u(11.72,-1.57,2.58)),"ang"=B:toWorld(ang(0,0,180)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "20"=table("model"="models/props_debris/walldestroyed02a.mdl","pos"=B:toWorld(u(-3.82,2.37,5.44)),"ang"=B:toWorld(ang(0,90,180)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "21"=table("model"="models/hunter/blocks/cube1x4x05.mdl","pos"=B:toWorld(u(-3.75,1.5,3.5)),"ang"=B:toWorld(ang(0,90,-90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "22"=table("model"="models/hunter/blocks/cube1x4x05.mdl","pos"=B:toWorld(u(-3.75,-1.5,3.5)),"ang"=B:toWorld(ang(0,90,-90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "23"=table("model"="models/hunter/blocks/cube2x6x05.mdl","pos"=B:toWorld(u(-3.75,-3,4.5)),"ang"=B:toWorld(ang(0,-90,90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "24"=table("model"="models/hunter/blocks/cube2x6x05.mdl","pos"=B:toWorld(u(-3.75,1,6.5)),"ang"=B:toWorld(ang(90,180,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "25"=table("model"="models/hunter/blocks/cube4x6x05.mdl","pos"=B:toWorld(u(-6,1.75,4.5)),"ang"=B:toWorld(ang(0,180,90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "26"=table("model"="models/hunter/blocks/cube3x3x05.mdl","pos"=B:toWorld(u(-7.75,0,6)),"ang"=B:toWorld(ang(90,180,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "27"=table("model"="models/hunter/blocks/cube4x6x05.mdl","pos"=B:toWorld(u(-6,-1.75,4.5)),"ang"=B:toWorld(ang(0,0,90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "28"=table("model"="models/hunter/blocks/cube05x3x05.mdl","pos"=B:toWorld(u(-7.75,-1.25,3)),"ang"=B:toWorld(ang(0,90,-90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "29"=table("model"="models/hunter/blocks/cube05x3x05.mdl","pos"=B:toWorld(u(-7.75,1.25,3)),"ang"=B:toWorld(ang(0,90,-90)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "30"=table("model"="models/hunter/blocks/cube4x4x2.mdl","pos"=B:toWorld(u(-6,0,8.5)),"ang"=B:toWorld(ang(0,180,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "31"=table("model"="models/hunter/tubes/tube4x4x3.mdl","pos"=B:toWorld(u(-6,0,9)),"ang"=B:toWorld(ang(0,90,0)),"material"="models/props_debris/plasterwall034a","color"=vec4(255, 255, 255, 255)),
            "32"=table("model"="models/props_rooftop/dome_copper.mdl","pos"=B:toWorld(u(-6.03,0,10.37)),"ang"=B:toWorld(ang(0,0,0)),"material"="","color"=vec4(255, 255, 255, 255)),
            "33"=table("model"="models/hunter/triangles/6x6.mdl","pos"=B:toWorld(u(-3.97,0,7.5)),"ang"=B:toWorld(ang(-45,90,-90)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "34"=table("model"="models/hunter/blocks/cube025x8x025.mdl","pos"=B:toWorld(u(0.37,0,11.85)),"ang"=B:toWorld(ang(45,-90,0)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "35"=table("model"="models/hunter/blocks/cube025x8x025.mdl","pos"=B:toWorld(u(8.37,0,11.85)),"ang"=B:toWorld(ang(45,-90,0)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "36"=table("model"="models/hunter/triangles/6x6.mdl","pos"=B:toWorld(u(11.97,0,7.5)),"ang"=B:toWorld(ang(-45,-90,-90)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "37"=table("model"="models/hunter/blocks/cube8x8x05.mdl","pos"=B:toWorld(u(8,-2.76,9.09)),"ang"=B:toWorld(ang(0,180,-45)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "38"=table("model"="models/hunter/blocks/cube8x8x05.mdl","pos"=B:toWorld(u(0,-2.76,9.09)),"ang"=B:toWorld(ang(0,180,-45)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "39"=table("model"="models/hunter/blocks/cube8x8x05.mdl","pos"=B:toWorld(u(0,2.76,9.09)),"ang"=B:toWorld(ang(0,180,45)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255)),
            "40"=table("model"="models/hunter/blocks/cube8x8x05.mdl","pos"=B:toWorld(u(8,2.76,9.09)),"ang"=B:toWorld(ang(0,180,45)),"material"="models/props_debris/concretewall019a","color"=vec4(255, 255, 255, 255))
        )
        
        foreach(ID, T:table=Props2Spawn) {
            Prop = propSpawn(T["model", string], T["pos", vector], 1)
            Prop:setMaterial(T["material", string])
            Prop:setColor(T["color", vector4])
            Prop:setAng(T["ang", angle])
            Props:pushEntity(Prop)
        }
        
        return B
    }
    
    spawnChurch(entity():pos()+vec(512,0,-128),ang(0,0,0))
    
}

if(tickClk()) {
    if(owner():keyPressed("g") & owner():aimEntity():isValid() & Time < realtime()) {
        local Ent = owner():aimEntity()
        local Pos = round(B:toLocal(Ent:pos())/u(1),2)
        local Ang = round(B:toLocal(Ent:angles()),0)
        
        print("table(\"model\"=\""+Ent:model()+"\",\"pos\"=B:toWorld(u("+Pos:x()+","+Pos:y()+","+Pos:z()+")),\"ang\"=B:toWorld(ang("+Ang:pitch()+","+Ang:yaw()+","+Ang:roll()+")),\"material\"=\"" + Ent:getMaterial() + "\",\"color\"=vec4(" + Ent:getColor4():x() + ", " + Ent:getColor4():y() + ", " + Ent:getColor4():z() + ", " + Ent:getColor4():w() + "))")
        Time = realtime()+1
    }
    
    if(owner():keyPressed("h") & owner():aimEntity():isValid() & Time < realtime()) {
        print("main Prop set!")
        B = owner():aimEntity()
        Time = realtime()+1
    }
}

if(last()) {
    Props:propDelete()
}
