@name Chaqua Railgun Base
@inputs F
@persist S:string M:entity B
@model models/hunter/blocks/cube025x150x025.mdl
if(first())
{
    runOnTick(1)
    S = "models/hunter/plates/plate150.mdl"
    entity():setMaterial("phoenix_storms/wood")
}

if(M:isValid())
{
    M:applyForce(M:right()*1000000*M:mass())
    M:applyAngForce(-M:angVel()*0.7*M:mass())
    
    local RD = rangerOffset(200,M:pos(),M:vel())
    
    V = M:velL():x()
    if(abs($V)>30)
    {
        propSpawn("models/props_phx/ww2bomb.mdl",M:pos(),1):propBreak()
        M:propDelete()
        
        soundPlay("reload",0.28,"buttons/blip2.wav")
    }
}else
{
    
    if(F&!B)
    {
        B = 1
        timer("ub",5000)
        
        M = propSpawn(S,entity():toWorld(entity():boxCenter()+vec(0,-50,0)),entity():angles(),0)
        M:propGravity(0)
        M:setMass(50000)
        M:setMaterial("phoenix_storms/wood")
        M:setTrails(100,0,3,"trails/laser",vec(255,200,100),255)
        
        applyForce(-entity():right()*3600*entity():mass())
        
        soundPlay("shoot",0.7,"weapons/barret_arm_shot.wav")
    }
}

if(B)
{
    if(clk("ub"))
    {
        stoptimer("ub")
        B = 0
    }
}

if(duped()|dupefinished())
{
    reset()
}
