The HoloShip

Right, I don’t know how much you guys are going to appreciate this, seeing as its mostly wire. But, some shameless copy+paste from wiremod.com for more criticism never hurt.

Although I “finished” this thing ages ago, I’ve been making loads of improvements and code optimizations whenever I happen to be bored. I’m finally at a point where I’m pretty happy with it, so I decided to release it.

Controls:
W - Move forward
S - Move backward
A - Strafe left/Roll left
D - Strafe right/roll right
Shift - Strafe down
Space - Strafe up

Turning is accomplished with the mouse.

Hotkeys:
Controlled Movement Toggle - Alt(0.5s)
Cloaking - Alt+R(0.25s)
Hyperjump - Shift+R(Varied, charges up based on hold length)
Third-person Camera - R(0.25s)



# _______________________________________________________________
#                   - Undomian's HoloShip v2 - 
#                       - By NG|Undomian -
#
#   This is my spacebuild fighter base. After being wired to an
# Adv. Pod Controller, this chip essentially becomes an excellent
# flying vehicle. For best results, type this into the console 
# before spawning this chip:
# wire_expression2_model models/hunter/plates/plate1x1.mdl
#
#   That changes the model of the chip to a 1x1 PHX plate, perfect
# for welding all of your other stuff to. It's really only capable
# of carrying a bit over 1 pound though, so it's recommended that
# you set the weight of ALL OTHER ATTACHED PROPS to < 0.001 units.
#
#   As of now, this chip is capable of performing the following:
#       - 3D movement
#       - Barrel Rolls (With a slight code modification)
#       - Hyper jumps, to a distance of 10000 units
#       - Cloaking
#       - Holographic false body
#       - Turret (Just weld them to the front of the plate, reticle is accurate, Mouse outputs exist)
#       - Holographic HUD
# ______________________________________________________________

@name Undomian's HoloShip v2
@inputs [PodController CamController]:wirelink
@outputs Mouse1 Mouse2 Jump JumpTar:vector
@persist Ent:entity Constrained:array OwnerID:string Mass ConstrainedMass Active Shift R 
@persist Power PowerConsumptionRate PowerRegenRate AntigravConstant
@persist JumpDistance Cloak Camera Slow
@trigger all

if(first() | duped()){
    runOnTick(1)
    hint("Undomian's HoloShip v2", 4)
    hint("Hold W or S and use the mouse to steer.", 4)
    hint("Use Shift and Space to adjust altitude.", 4)
    hint("Strafe with A and D.", 4)
    #Basic Initialization
    #Power System
    Power = 1000
    PowerConsumptionRate = 1 #Modify to adjust basic power consumption rates
    PowerRegenRate = 2 #Modify to adjust basic power regeneration rates
    #Basics
    Ent = entity()
    Constrained = Ent:getConstraints()
    OwnerID = owner():steamID()
    TheftControl = 1
    Jump = 0
    Ent:setMass(20000)
    
    #Visual body
    Up = Ent:up()*25
    holoCreate(1, Ent:pos()+Ent:forward()*50+Up,vec(3,5,15), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqcone")
    holoMaterial(1, "models/props_canal/metalwall005b")
    holoCreate(2, Ent:pos()+Ent:forward()*-52+Up,vec(3,5,2), Ent:angles()+ang(-90,0,0), vec(255,255,255), "hqcone")
    holoMaterial(2, "models/props_canal/metalwall005b")
    holoCreate(3, Ent:pos()+Ent:forward()*-55+Up,vec(2,2,2), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqcone")
    holoMaterial(3, "models/gibs/metalgibs/metal_gibs")
    holoCreate(4, Ent:pos()+Ent:forward()*5+Ent:up()*8+Up,vec(2,3,8), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqicosphere2")
    holoMaterial(4, "models/gibs/metalgibs/metal_gibs")
    holoCreate(5, Ent:pos()+Ent:right()*40+Up,vec(5,0.2,3), Ent:angles()+ang(0,-170,-90), vec(255,255,255), "hqcone")
    holoMaterial(5, "models/props_canal/metalwall005b")
    holoCreate(6, Ent:pos()+Ent:right()*-40+Up,vec(5,0.2,3), Ent:angles()+ang(0,170,90), vec(255,255,255), "hqcone")
    holoMaterial(6, "models/props_canal/metalwall005b")
    holoCreate(7, Ent:pos()+Ent:right()*24+Up,vec(0.3,0.3,5), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqcylinder2")
    holoMaterial(7, "models/gibs/metalgibs/metal_gibs")
    holoCreate(8, Ent:pos()+Ent:right()*-24+Up,vec(0.3,0.3,5), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqcylinder2")
    holoMaterial(8, "models/gibs/metalgibs/metal_gibs")
    holoCreate(9, Ent:pos()+Ent:right()*24+Ent:forward()*25+Up, vec(0.5,0.5,0.5), Ent:angles():setPitch(90), vec(255,255,255), "hqtorus2")
    holoMaterial(9, "models/gibs/metalgibs/metal_gibs")
    holoCreate(10, Ent:pos()+Ent:right()*-24+Ent:forward()*25+Up, vec(0.5,0.5,0.5), Ent:angles():setPitch(90), vec(255,255,255), "hqtorus2")
    holoMaterial(10, "models/gibs/metalgibs/metal_gibs")
    holoCreate(11, Ent:pos()+Ent:right()*40+Ent:forward()*2.5+Up,vec(1.5,0.25,3), Ent:angles()+ang(90,180,180), vec(255,255,255), "hqcone")
    holoMaterial(11, "models/props_canal/metalwall005b")
    holoCreate(12, Ent:pos()+Ent:right()*-40+Ent:forward()*2.5+Up,vec(1.5,0.25,3), Ent:angles()+ang(90,180,180), vec(255,255,255), "hqcone")
    holoMaterial(12, "models/props_canal/metalwall005b")
    #Shield(13) - Uncomment all index 13 holograms to display it.
    #holoCreate(13, Ent:pos()+Ent:forward()*30+Up,vec(10,10,21), Ent:angles()+ang(90,0,0), vec(255,255,255), "hqsphere2")
    #holoAlpha(13, 50)
    #holoMaterial(13, "models/debug/debugwhite")
    holoCreate(14, Ent:pos()+Ent:forward()*-67+Up,vec(1.9,1.9,0.05), Ent:angles()+ang(90,0,0), vec(50,50,150), "hqcylinder2")
    holoAlpha(14, 100)
    holoEntity(14):setTrails(30,1,3,"trails/plasma",vec(50,50,150),255)
    #HoloHUD
    #Power monitor
    holoCreate(15, Ent:pos() + Ent:forward() * 50 + vec(0,0,5)+Up/1.5, vec(0.25,0.25,2), Ent:angles():setRoll(90), vec(255,255,0), "hqcylinder2")
    holoAlpha(15, 100)
    holoCreate(16, Ent:pos() + Ent:forward() * 50 + vec(0,0,5)+Up/1.5, vec(0.30,0.30,2.1), Ent:angles():setRoll(90), vec(0,0,0), "hqcylinder2")
    holoAlpha(16, 100)
    #Stationary crosshair
    holoCreate(17, Ent:pos() + Ent:forward() * 45 + vec(0,0,35), vec(0.25,0.25,0.25), Ent:angles():setPitch(90), vec(255,0,0), "hqtorus2")
    holoAlpha(17, 200)
    holoCreate(18, Ent:pos() + Ent:forward() * 45 + vec(0,0,35), vec(0.05,0.05,0.05), Ent:angles(), vec(255,0,0), "hqsphere2")
    holoAlpha(18, 200)
    for(I=0, 18){
        holoParent(I, Ent)
    }
    #Mass Calculation
    for(I=0, Constrained:count()){
        ConstrainedMass += Constrained:entity(I):mass()
        Mass = entity():mass() + ConstrainedMass
    }
    #Sound Loop
    soundPlay(1,0,"ambient/machines/combine_shield_loop3.wav")
}

#Wirelink inputs
W = PodController["W", number]
A = PodController["A", number]
S = PodController["S", number]
D = PodController["D", number]
R = PodController["R", number]
Shift = PodController["Shift", number]
Space = PodController["Space", number]
Alt = PodController["Alt", number]
Active = PodController["Active", number]
Mouse1 = PodController["Mouse1", number]
Mouse2 = PodController["Mouse2", number]
Seat = PodController["Entity", entity]

#Basic Variables
AntigravConstant = -Ent:pos():z()
AngVel = entity():angVel()
Angles = entity():angles()
AngMul = clamp(AngVel, 10, 50)

if(Active){
    if(TheftControl & $Active & Seat:driver():steamID() != OwnerID & !isSinglePlayer()){
        Seat:hintDriver("You are not authorized to use this vehicle.", 3)
        Seat:ejectPod()
    }
    #Active Only Variables
    Speed = Ent:vel():length()
    Position = entity():pos() + -Ent:forward()*250 + Ent:up()*100
    Direction = Seat:driver():eye()
    
    #Controlled movement toggle
    if(Alt & !R){
        timer("SlowTimer", 500)
        if(clk("SlowTimer")){
            Seat:hintDriver("Controlled movement status: "+!Slow, 2)
            Slow = !Slow
        }
    }
    if(Slow){
        MoveNorm =  (entity():forward()*Mass*1000-Ent:vel()*Ent:vel():length()*5)*(W-S)
        MoveStrafe = (entity():right()*Mass*1000-Ent:vel()*Ent:vel():length()*5)*(D-A)
        MoveVert = (entity():up()*Mass*1000-Ent:vel()*Ent:vel():length()*5)*(Space-Shift)
        SlowAng = 3
    } else {
        MoveNorm =  (entity():forward()*Mass*1000-Ent:vel()*(Ent:vel():length()/2))*(W-S)
        MoveStrafe = (entity():right()*Mass*1000-Ent:vel()*(Ent:vel():length()/2))*(D-A)
        MoveVert = (entity():up()*Mass*1000-Ent:vel()*(Ent:vel():length()/2))*(Space-Shift)
        SlowAng = 1
    }
    
    #Angular Regulation
    applyAngForce((ang(-Ent:elevation(Seat:driver():eye()*1000+entity():pos()) *AngMul:pitch()/2, -Ent:bearing(Seat:driver():eye()*1000+entity():pos()) * AngMul:yaw(), -Angles:roll()) - AngVel * 6 * SlowAng)*shiftL(ang(Ent:inertia())))
    
    #Movement
    if(W|S){
        if(!Shift&!Space){
            applyForce(MoveNorm + ((W-S)-1)*Ent:vel()*5000)
        } elseif((Shift|Space) & (!R&!Alt)){
            applyForce(MoveNorm:setZ(MoveVert:z()))
        } else {
            applyForce((vec(0,0,9.019-$AntigravConstant)-2*Ent:vel())*Mass)
        }
    } elseif(A|D){
        if(!Shift&!Space){
            applyForce(MoveStrafe + ((W-S)-1)*Ent:vel()*2000)
        } elseif((Shift|Space) & (!R&!Alt)){
            applyForce(MoveStrafe:setZ(MoveVert:z()))
        } else {
            applyForce((vec(0,0,9.019-$AntigravConstant)-2*Ent:vel())*Mass)
        }
    } elseif((Shift|Space) & (!R&!Alt) & (!W&!A&!S&!D)){
        applyForce(MoveVert)
    } else {
        applyForce((vec(0,0,9.019-$AntigravConstant)-1*Ent:vel())*Mass)
    }
    
    #Sound - Changes pitch based on speed, but it mostly stays at max.
    #"ambient/machines/combine_shield_loop3.wav"
    soundPitch(1,clamp(Speed,100,250))
    soundVolume(1,1)
    
    #JumpDrive
    #Prototype ChargedJump
    if(Shift & R & !Alt & !Space){
        JumpDistance += 50
        if(JumpDistance > 10000){JumpDistance = 10000}
    } elseif($Shift & $R & !Shift & !R & !Alt & !Space & JumpTar:isInWorld()){
        Jump = 1
        Power -= (JumpDistance/40) * PowerConsumptionRate
        Seat:hintDriver("Initating hyperspace jump. Distance: "+JumpDistance, 2)
    } else {
        Jump = 0
        JumpDistance = 0
    }
    JumpTar = Ent:pos() + Ent:forward() * JumpDistance
    
    #Third-person camera
    if(R & !Shift & !Alt & !Space){
        timer("CamTimer", 250)
        if(clk("CamTimer")){
            Camera = !Camera
            Seat:hintDriver("Camera status: "+Camera, 2)
        }
    }          
    
    #Power Monitor
    if(Speed >= 500 & !Cloak){
        Power -= 0.2 * PowerConsumptionRate
    } elseif(Speed >= 500 & Cloak){
        Power -= 0.25 * PowerConsumptionRate
    } elseif(Speed < 500 & !Cloak){
        Power += 0.15 * PowerRegenRate
    } elseif(Speed < 500 & !Cloak){
        Power += 0.1 * PowerRegenRate
    }
    if(Power <= 0){
        Seat:hintDriver("Power levels critical!", 4)
        Seat:hintDriver("Ejecting driver to preserve the ship!", 4)
        Seat:ejectPod()
    }
    holoScale(entity():id()+10, vec(0.25,0.25,(Power * 2) / 1000))
    
    #Cloaking
    if(Active & $Active){
        Alpha = 0
        Seat:driver():setColor(vec(0,0,0))
        Seat:driver():setMaterial("Models/effects/vol_light001")
        entity():setAlpha(Alpha)
        for(I = 0, Constrained:count()){
            Constrained:entity(I):setAlpha(Alpha)
        }
    }
    if(Alt & R & !Shift & !Space){
        timer("CloakTimer", 250)
        if(clk("CloakTimer")){
            Cloak = !Cloak
            Seat:hintDriver("Cloak status: "+Cloak, 2)
            Power -= 50 * PowerConsumptionRate
        }
    }
} else {
    #Angular facing and dampening
    applyAngForce((-Angles:setYaw(-AngVel:yaw()) - 10 * AngVel) * AngMul)
    applyForce((vec(0,0,9.019-$AntigravConstant)-1*Ent:vel())*Mass)
    #Sound
    soundVolume(1,0.1)
    #Outside camera
    Camera = 0
    Cloak = 0
    Power += 0.75 * PowerRegenRate
}

#Cloaking
if(Cloak & $Cloak){
    for(I = 0, 18){
        holoAlpha(I, 0)
    }
    holoEntity(14):setTrails(30,1,3,"trails/plasma",vec(50,50,150),0)
    soundVolume(1,0.25)
} elseif(!Cloak & $Cloak){
    for(I = 0, 18){
        holoAlpha(I, 255)
    }
    holoAlpha(14, 100)
    holoAlpha(15, 200)
    holoAlpha(16, 200)
    holoAlpha(17, 100)
    holoAlpha(18, 100)
    holoEntity(14):setTrails(30,1,3,"trails/plasma",vec(50,50,150),255)
    soundVolume(1,1)
}

#Power Overflow Prevention
Power = clamp(Power, 0, 1000)

#Wirelink Outputs
CamController["Position", vector] = Position
CamController["Direction", vector] = Direction
CamController["Activated", number] = Camera



To modify the code so that the ship can do a quasi-barrel roll, replace the applyAngForce code in the Active section with this, and add the variable “Roll” (Without the quotes) to the persists:



if(A|D){
        Roll += (D-A) * 2
    } else {
        Roll = 0
    }
    if(!A&!D){
        applyAngForce((ang(-Ent:elevation(Seat:driver():eye()*1000+entity():pos()) *AngMul:pitch()/2, -Ent:bearing(Seat:driver():eye()*1000+entity():pos()) * AngMul:yaw(), -Angles:roll()) - AngVel * 6 * SlowAng)*shiftL(ang(Ent:inertia())))
    } else {
        applyAngForce((ang(-Ent:elevation(Seat:driver():eye()*1000+entity():pos()) *AngMul:pitch()/2, -Ent:bearing(Seat:driver():eye()*1000+entity():pos()) * AngMul:yaw(), -Angles:roll() + Roll) - AngVel * 6 * SlowAng)*shiftL(ang(Ent:inertia())))
    }  


If anyone has some optimization tips, please tell me. Other than that, tell me what you think!

Dupe File.

That’s pretty sick. Definitely downloading the dupe.

Very nice indeed.

I like it…jeep brah!

The ship looks a bit small and i don’t think you need weapons on it unless it can be hit by weapons itself.

Acceleration?

Had it on for a bit, took it off because it was mostly pointless.

Oh cool, I remember seeing the old version of this ingame. It’s quite nice.

good, nice code but get rid of that god-awful looking hologram and build it with some props

Please do ^that

He could make it look way better with props indeed, but then again it wouldn’t be so easy on the peformance, and not as smooth (Atleast without some more coding(MORE :d))

What? Couldn’t he just parent them to the expression?

Typical American accent in the video.

Looks basic but seems pretty good.

Wtf u mean by typical american accent

you know… the mix between a canadian hick and a mexican inbred.

I find that statement offensive. I am American and I don’t talk like Mexicans, Canadians, nor Undomain.

80% of americas are fat, they are annoying, they are racist, they’re VERY religious and thinks the whole world is just in their state.
And so much more.

100% of the idiots that think this are ignorant bastards. Quit pulling statistics out of your ass.

And I’m from southwestern Pennsylvania, we seem to have extremely definitive accents for some reason. :saddowns:

Yeah none of those things are correct your just being an ignorant retard. Not all of america is fat. Not all of america is religious. And yes, 1/4 of americans are retards but the other 3/4s aren’t stupid enough to think that their state is the whole world.

sv: Expression 2 (Undomian’s HoloShip v2): SPropProtection/sh_CPPI.lua:52: attempt to index field ‘?’ (a nil value)

?