Code:
@name Red's Track System - v2d: red has no life
@inputs [La Ra]:wirelink
@outputs [Aa0 Aa1 Aa2 Aa3 Aa4 Aa5 Aa6 Aa7 Aa8 Aa9 Aa10 Aa11 Aa12]:vector
@persist [SprocketL SprocketR RSprocketL RSprocketR R1 R2 R3 R4 R5 L1 L2 L3 L4 L5]:entity F Wheelnumber Trackrun M AMod:angle Skin:string Sprsize Roadwheelsize Thickness Width RSprsize [Pos Up Right Fore RRPos LRPos LPos RPos]:vector Uhm Wheelmod Sprocketmod RSprocketmod Stretchmod Off
@trigger
interval(175)
if(dupefinished()) {reset()}
if(first())
{
#This is a simple holo caterpillar track system
#While it may look a bit confusing at first, this is an easy tool to use.]
#much easier than the old one. This adds "tracks on" and "tracks off" chat commands to disable the tracks
#It was made by redreaper. That's me. I'll probably put together a vid on how to set it up but it's nto hard.
#GunslingerP Karbine and shadowscion did help, Gunslinger betatesting, karbine and slinger both suggesting features, shadow helping with code optimization and math shit
#current issues will be resolved iwth subsequent releases.
#to use this, parent it upright, facing forward, to your vehicle. Make sure the chip loads upright and not at an angle (that'll twist treads up)
#usually this is the center of the tank. if your roadwheels are forward more or aft more
#adjust the chip's position accordingly. you want the chip spaced evenly between the idler & drive sprocket
#Scaling of the wheels is now done different, you're only going to fine tune htem, it'll start them at boundingbox size
#Some basic variables - These variables are 99% of the time all you need to tweak.
Wheelnumber = 4 #How many roadwheels you have. NOTE: ONLY QUANTITIES OF 4 AND 5 ARE WORKING
Sprmod = 3 #Fine-tune the size of the front sprocket
RSprmod = 5 #Fine-tune the size of the rear sprocket
Width = 1.7 #Width of the track's contact patch
Thickness = 0.3 #The thickness of the actual track. Keep it between 0.1 and 0.3, usually 0.2 is enough.
Trackrun = 1 #Do tracks run along the top? saves 4 holos. turn off trackrun if you have side skirts
Skinnum = 3 #Number to designate which skin to use
Roadwheelmod = 3 #Fine-tune the size of roadwheels
Wheelmod = 0 #Modifier of width for the roadwheels
Sprocketmod = 0 #Modifier of width for the front drive sprockets
RSprocketmod = 0 #Modifier of width for the rear drive sprockets
Stretch = 7 #Modifier of length for the first and last roadwheels, to look smoother
Color = vec(200,200,200) #Color the treads
#These should not need altering.
M = 0.09 #should be able to ignore this, scaling for track connection
Uhm = Thickness*12 #trackrun above ground
TUV = vec(0,0,(Thickness*1.5)) #Thickness up multiplier.
AMod = ang(0,0,0) #Modifier for angles, do not use at this time
if(Skinnum == 1) {Skin = "phoenix_storms/middle"} #A good solid jointed texture for ww2 and modern tanks
if(Skinnum == 2) {Skin = "phoenix_storms/metalset_1-2"} #A metallic texture, for early ww2 and ww1 tanks
if(Skinnum == 3) {Skin = "phoenix_storms/FuturisticTrackRamp_1-2"} #Another metallic texture, for early ww2 and ww1 tanks
if(Skinnum == 4) {Skin = "models/XQM/Rails/gumball_1"} #Rubber banded track skin, use dark colors.
if(Skinnum == 5) {Skin = "phoenix_storms/car_tire"} #A car tire skin some people like. Ugly as sin.
if(Skinnum == 6) {Skin = "models/weapons/w_stunbaton/stunbaton"} #A weird scifi looking texture.
if(Skinnum == 7) {Skin = "hunter/myplastic"} #Default phx nomat skin, boxy but passable
if(Skinnum == 8) {Skin = "phoenix_storms/lag_sign"} #For entertainment only
#Deconstruct those wire links
#for now use the bottom one if you have four roadwheels. It's a quick fix. no more.
if(Wheelnumber ==5)
{
#LEFT
SprocketL = La:entity("Entity1")
L1 = La:entity("Entity2")
L2 = La:entity("Entity3")
L3 = La:entity("Entity4")
L4 = La:entity("Entity5")
L5 = La:entity("Entity6")
RSprocketL = La:entity("Entity7")
#RIGHT
SprocketR = Ra:entity("Entity1")
R1 = Ra:entity("Entity2")
R2 = Ra:entity("Entity3")
R3 = Ra:entity("Entity4")
R4 = Ra:entity("Entity5")
R5 = Ra:entity("Entity6")
RSprocketR = Ra:entity("Entity7")
}
if(Wheelnumber ==4)
{
#LEFT
SprocketL = La:entity("Entity1")
L1 = La:entity("Entity2")
L2 = La:entity("Entity3")
L3 = L2
L4 = La:entity("Entity4")
L5 = La:entity("Entity5")
RSprocketL = La:entity("Entity6")
#RIGHT
SprocketR = Ra:entity("Entity1")
R1 = Ra:entity("Entity2")
R2 = Ra:entity("Entity3")
R3 = R2
R4 = Ra:entity("Entity4")
R5 = Ra:entity("Entity5")
RSprocketR = Ra:entity("Entity6")
}
Roadwheelsize = (R3:boxSize():x() /2) + Roadwheelmod #Determines actual wheel size
Sprsize = (SprocketL:boxSize():x()/2) + Sprmod #Determines actual sprocket size
RSprsize = (RSprocketL:boxSize():x()/2) + RSprmod #Determines actual rear sprocekt size
Stretchmod = ((Roadwheelsize)/-1.75) + Stretch
}
#Everything below here you can pretty much ignore. It's just a wall of code.
if(Off == 0)
{
#some shit shadowscion suggested, i don't notice that much of a difference but it seems to be decent.
Pos = entity():massCenter()
Up = entity():up()
Right = entity():right()
Fore = entity():forward()
LPos = SprocketL:massCenter() + (Right*-Sprocketmod)
RPos = SprocketR:massCenter() + (Right*Sprocketmod)
LRPos = RSprocketL:massCenter() + (Right*-RSprocketmod)
RRPos = RSprocketR:massCenter() + (Right*RSprocketmod)
Down = -Up #why did I add this?
A0 = RPos + (Up * -(Sprsize))
A1 = R1:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*Wheelmod) + (Fore*-Stretchmod)
A2 = R2:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*Wheelmod)
A3 = R3:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*Wheelmod)
A4 = R4:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*Wheelmod)
A5 = R5:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*Wheelmod) + (Fore*Stretchmod)
A6 = RPos + (Fore * (Sprsize*0.7)) + (Up*-(Sprsize*0.5))
A7 = RPos + (Fore * (Sprsize*0.8)) + (Up*(Sprsize*0.4))
A8 = RRPos + (Up * -(RSprsize))
A9 = RRPos + (Fore * (RSprsize*-0.7)) + (Up*-(RSprsize*0.5))
A10 = RRPos + (Fore*(RSprsize*-0.75)) + (Up*RSprsize*0.5)
A11 = RPos + (Fore*(Sprsize*0.1)) + (Up*(Sprsize*0.8))
A12 = RRPos + (Fore * (RSprsize*-0.1)) + (Up*(Sprsize*1))
Am = ((A12+A11)/2 -TUV)
Aa0 = LPos + (Up * -(Sprsize))
Aa1 = L1:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*-Wheelmod) + (Fore*-Stretchmod)
Aa2 = L2:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*-Wheelmod)
Aa3 = L3:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*-Wheelmod)
Aa4 = L4:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*-Wheelmod)
Aa5 = L5:massCenter() - (Up*Roadwheelsize) + (Up * Uhm) + (Right*-Wheelmod) + (Fore*Stretchmod)
Aa6 = LPos + (Fore * (Sprsize*0.7)) + (Up*-(Sprsize*0.5))
Aa7 = LPos + (Fore * (Sprsize*0.8)) + (Up*(Sprsize*0.4))
Aa8 = LRPos + (Up * -(RSprsize))
Aa9 = LRPos + (Fore * (RSprsize*-0.7)) + (Up*-(RSprsize*0.5))
Aa10 = LRPos + (Fore*(RSprsize*-0.75)) + (Up*RSprsize*0.5)
Aa11 = LPos + (Fore*(Sprsize*0.1)) + (Up*(Sprsize*0.8))
Aa12 = LRPos + (Fore * (RSprsize*-0.1)) + (Up*(Sprsize*1))
Aam = ((Aa12+Aa11)/2 -TUV)
Axis1 = entity():toLocalAxis(A1-A2)
Atan1 = atan(-Axis1:z(), Axis1:x())
Axis2 = entity():toLocalAxis(A2-A3)
Atan2 = atan(-Axis2:z(), Axis2:x())
Axis3 = entity():toLocalAxis(A3-A4)
Atan3 = atan(-Axis3:z(), Axis3:x())
Axis4 = entity():toLocalAxis(A4-A5)
Atan4 = atan(-Axis4:z(), Axis4:x())
Axis5 = entity():toLocalAxis(A0-A1)
Atan5 = atan(-Axis5:z(), Axis5:x())
Axis8 = entity():toLocalAxis(A5-A8)
Atan8 = atan(-Axis8:z(), Axis8:x())
holoPos(1,(A1+A2+TUV)/2)
holoPos(2,(A2+A3+TUV)/2)
holoPos(3,(A3+A4+TUV)/2)
holoPos(4,(A4+A5+TUV)/2)
holoPos(5,(A0+A1+(TUV/2))/2)
holoPos(8,(A5+A8+(TUV/2))/2)
holoAng(1,entity():toWorld((ang(Atan1,0,0)+AMod)))
holoAng(2,entity():toWorld((ang(Atan2,0,0)+AMod)))
holoAng(3,entity():toWorld((ang(Atan3,0,0)+AMod)))
holoAng(4,entity():toWorld((ang(Atan4,0,0)+AMod)))
holoAng(5,entity():toWorld((ang(Atan5,0,0)+AMod)))
holoAng(8,entity():toWorld((ang(Atan8,0,0)+AMod)))
Axis11 = entity():toLocalAxis(Aa1-Aa2)
Atan11 = atan(-Axis11:z(), Axis11:x())
Axis12 = entity():toLocalAxis(Aa2-Aa3)
Atan12 = atan(-Axis12:z(), Axis12:x())
Axis13 = entity():toLocalAxis(Aa3-Aa4)
Atan13 = atan(-Axis13:z(), Axis13:x())
Axis14 = entity():toLocalAxis(Aa4-Aa5)
Atan14 = atan(-Axis14:z(), Axis14:x())
Axis15 = entity():toLocalAxis(Aa0-Aa1)
Atan15 = atan(-Axis15:z(), Axis15:x())
Axis18 = entity():toLocalAxis(Aa5-Aa8)
Atan18 = atan(-Axis18:z(), Axis18:x())
holoPos(11,(Aa1+Aa2+TUV)/2)
holoPos(12,(Aa2+Aa3+TUV)/2)
holoPos(13,(Aa3+Aa4+TUV)/2)
holoPos(14,(Aa4+Aa5+TUV)/2)
holoPos(15,(Aa0+Aa1+(TUV/2))/2)
holoPos(18,(Aa5+Aa8+(TUV/2))/2)
holoAng(11,entity():toWorld((ang(Atan11,0,0)+AMod)))
holoAng(12,entity():toWorld((ang(Atan12,0,0)+AMod)))
holoAng(13,entity():toWorld((ang(Atan13,0,0)+AMod)))
holoAng(14,entity():toWorld((ang(Atan14,0,0)+AMod)))
holoAng(15,entity():toWorld((ang(Atan15,0,0)+AMod)))
holoAng(18,entity():toWorld((ang(Atan18,0,0)+AMod)))
holoScale(1,vec(((A1-A2):length())*M,Width,Thickness))
holoScale(2,vec(((A2-A3):length())*M,Width,Thickness))
holoScale(3,vec(((A3-A4):length())*M,Width,Thickness))
holoScale(4,vec(((A4-A5):length())*M,Width,Thickness))
holoScale(5,vec(((A0-A1):length())*M,Width,Thickness))
holoScale(8,vec(((A5-A8):length())*M,Width,Thickness))
holoScale(11,vec(((Aa1-Aa2):length())*M,Width,Thickness))
holoScale(12,vec(((Aa2-Aa3):length())*M,Width,Thickness))
holoScale(13,vec(((Aa3-Aa4):length())*M,Width,Thickness))
holoScale(14,vec(((Aa4-Aa5):length())*M,Width,Thickness))
holoScale(15,vec(((Aa0-Aa1):length())*M,Width,Thickness))
holoScale(18,vec(((Aa5-Aa8):length())*M,Width,Thickness))
}
if(first())
{
holoCreate(1,(A1+A2)/2,vec(3.6,1.5,0.4),ang(A1-A2),Color)
if(Wheelnumber > 4) {holoCreate(2,(A2+A3)/2,vec(3.6,1.5,0.4),ang(A2-A3),Color)}
holoCreate(3,(A3+A4)/2,vec(3.6,1.5,0.4),ang(A3-A4),Color)
holoCreate(4,(A4+A5)/2,vec(3.6,1.5,0.4),ang(A4-A5),Color)
holoCreate(5,(A0+A1)/2,vec(3.6,1.5,0.4),ang(A0-A1),Color)
holoCreate(6,(A0+A6)/2,vec(((A0-A6):length())*M,Width,Thickness),((A0-A6):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(7,(A7+A6)/2,vec(((A7-A6):length())*M,Width,Thickness),((A6-A7):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(8,(A5+A8)/2,vec(3.6,1.5,0.4),ang(A5-A8),Color)
holoCreate(9,(A8+A9)/2,vec(((A8-A9):length())*M,Width,Thickness),((A8-A9):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(10,(A9+A10)/2,vec(((A9-A10):length())*M,Width,Thickness),((A9-A10):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(61,(A11+A7)/2,vec(((A11-A7):length())*M,Width,Thickness),((A11-A7):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(62,(A12+A10)/2,vec(((A12-A10):length())*M,Width,Thickness),((A12-A10):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(11,(Aa1+Aa2)/2,vec(3.6,1.5,0.4),ang(Aa1-Aa2),Color)
if(Wheelnumber > 4) {holoCreate(12,(Aa2+Aa3)/2,vec(3.6,1.5,0.4),ang(Aa2-Aa3),Color)}
holoCreate(13,(Aa3+Aa4)/2,vec(3.6,1.5,0.4),ang(Aa3-Aa4),Color)
holoCreate(14,(Aa4+Aa5)/2,vec(3.6,1.5,0.4),ang(Aa4-Aa5),Color)
holoCreate(15,(Aa0+Aa1)/2,vec(3.6,1.5,0.4),ang(Aa0-Aa1),Color)
holoCreate(16,(Aa0+Aa6)/2,vec(((Aa0-Aa6):length())*M,Width,Thickness),((Aa0-Aa6):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(17,(Aa7+Aa6)/2,vec(((Aa7-Aa6):length())*M,Width,Thickness),((Aa6-Aa7):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(18,(Aa5+Aa8)/2,vec(3.6,1.5,0.4),ang(Aa5-Aa8),Color)
holoCreate(19,(Aa8+Aa9)/2,vec(((Aa8-Aa9):length())*M,Width,Thickness),((Aa8-Aa9):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(20,(Aa9+Aa10)/2,vec(((Aa9-Aa10):length())*M,Width,Thickness),((Aa9-Aa10):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(51,(Aa11+Aa7)/2,vec(((Aa11-Aa7):length())*M,Width,Thickness),((Aa11-Aa7):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(52,(Aa12+Aa10)/2,vec(((Aa12-Aa10):length())*M,Width,Thickness),((Aa12-Aa10):toAngle():setRoll(entity():angles():roll())),Color)
if(Trackrun ==1) {
holoCreate(21,(Am),vec(((Am):length() * 0.95)*M,Width,Thickness),((A12-A11):toAngle():setRoll(entity():angles():roll())),Color)
holoCreate(22,(Aam),vec(((Aam):length() * 0.95)*M,Width,Thickness),((Aa12-Aa11):toAngle():setRoll(entity():angles():roll())),Color)
holoMaterial(21,Skin)
holoMaterial(22,Skin)
}
holoMaterial(1,Skin)
holoMaterial(2,Skin)
holoMaterial(3,Skin)
holoMaterial(4,Skin)
holoMaterial(5,Skin)
holoMaterial(6,Skin)
holoMaterial(7,Skin)
holoMaterial(8,Skin)
holoMaterial(9,Skin)
holoMaterial(10,Skin)
holoMaterial(11,Skin)
holoMaterial(12,Skin)
holoMaterial(13,Skin)
holoMaterial(14,Skin)
holoMaterial(15,Skin)
holoMaterial(16,Skin)
holoMaterial(17,Skin)
holoMaterial(18,Skin)
holoMaterial(19,Skin)
holoMaterial(20,Skin)
holoMaterial(51,Skin)
holoMaterial(52,Skin)
holoMaterial(61,Skin)
holoMaterial(62,Skin)
holoAng(6,(A0-A6):toAngle():setRoll(entity():angles():roll()))
holoScale(6,vec(((A0-A6):length())*M,Width,Thickness))
holoAng(7,(A6-A7):toAngle():setRoll(entity():angles():roll()))
holoScale(7,vec(((A6-A7):length())*M,Width,Thickness))
holoAng(9,(A8-A9):toAngle():setRoll(entity():angles():roll()))
holoScale(9,vec(((A8-A9):length())*M,Width,Thickness))
holoAng(10,(A9-A10):toAngle():setRoll(entity():angles():roll()))
holoScale(10,vec(((A9-A10):length())*M,Width,Thickness))
holoAng(21,(A12-A11):toAngle():setRoll(entity():angles():roll()))
holoScale(21,vec(((A12-A11):length()-8)*M,Width,Thickness))
holoAng(16,(Aa0-Aa6):toAngle():setRoll(entity():angles():roll()))
holoScale(16,vec(((Aa0-Aa6):length())*M,Width,Thickness))
holoAng(17,(Aa6-Aa7):toAngle():setRoll(entity():angles():roll()))
holoScale(17,vec(((Aa6-Aa7):length())*M,Width,Thickness))
holoAng(19,(Aa8-Aa9):toAngle():setRoll(entity():angles():roll()))
holoScale(19,vec(((Aa8-Aa9):length())*M,Width,Thickness))
holoAng(20,(Aa9-Aa10):toAngle():setRoll(entity():angles():roll()))
holoScale(20,vec(((Aa9-Aa10):length())*M,Width,Thickness))
holoScale(22,vec(((Aa12-Aa11):length()-8)*M,Width,Thickness))
holoParent(1,entity())
holoParent(2,entity())
holoParent(3,entity())
holoParent(4,entity())
holoParent(5,entity())
holoParent(6,entity())
holoParent(7,entity())
holoParent(8,entity())
holoParent(9,entity())
holoParent(10,entity())
holoParent(11,entity())
holoParent(12,entity())
holoParent(13,entity())
holoParent(14,entity())
holoParent(15,entity())
holoParent(16,entity())
holoParent(17,entity())
holoParent(18,entity())
holoParent(19,entity())
holoParent(20,entity())
holoParent(21,entity())
holoParent(22,entity())
holoParent(51,entity())
holoParent(52,entity())
holoParent(61,entity())
holoParent(62,entity())
}
#cleanup on the fly
if(lastSpoke() == entity():owner())
{
Chat = lastSaid()
if(Chat == "tracks off") {Off = 1}
if(Chat == "tracks on") {Off = 0}
if(Chat == "tracks on tracks off") {print("Mr Myagi does not approve. -.-")}
}
if(changed(Off))
{
if(changed(Off) & (Off ==0)) {hint("Turning on tracks.",1)
reset()
}
if(changed(Off) & (Off ==1)) {hint("Turning off tracks.",1)
holoDeleteAll()
}
}