Garry's Mod
spaceship / battlecruiser
tanghao  [δημιουργός] 27 Φεβ 2018, 21:11
ship main E2 code (core part)
@name Xbattlecruiser core
@inputs [POD EGP]:wirelink [Shield Targetin F1 F2]:entity Button C
@outputs L1 R1 C1 [AIM ANG]:angle GPSout:vector Tel [TargetAR]:array Target:entity
@persist Tfind TSH TShift TTarget Tegp [SH1A SH1B SH2A SH2B SHL SHR SHF SHB]:entity I T
@trigger
@model models/hunter/blocks/cube1x1x05.mdl
interval(50)

if(first()|duped()|dupefinished())
{
# if(owner():name()=="tanghao"){}else{entity():propNotSolid(1)}
# if(owner():name()=="tanghao"){}else{selfDestructAll()}
Tfind=0 TSH=0 TShift=0 TTarget=0 Tegp=0
}

if(Tfind<50)
{
Tfind++
}
else
{
findByClass("player")
findSortByDistance(owner():boxCenterW())
TargetAR=findToArray() TargetAR[1,entity]=noentity()
EGP:egpRemove(10) EGP:egpRemove(11)

if(Button)
{
if(POD["Active",number])
{F1:propFreeze(0) F2:propFreeze(0)}
else{F1:propFreeze(1) F2:propFreeze(1)}
}
else
{F1:propFreeze(0) F2:propFreeze(0)}

if(owner():name()=="tanghao"){}else{entity():propNotSolid(1)}
# if(owner():name()=="tanghao"){}else{selfDestructAll()}

Tfind=0
}

if(POD["Active",number]&Button)
{
ANG=ang(0,entity():angles():yaw(),0)

SH1A:setPos(entity():boxCenterW()+vec(-100, 200, 125):rotate(ANG)) SH1A:setAng(entity():angles()+ang( 15,90,0)) SH1A:propFreeze(1)
SH1B:setPos(entity():boxCenterW()+vec(-100,-200, 125):rotate(ANG)) SH1B:setAng(entity():angles()+ang(-15,90,0)) SH1B:propFreeze(1)
SH2A:setPos(entity():boxCenterW()+vec(-100, 200,-125):rotate(ANG)) SH2A:setAng(entity():angles()+ang(-15,90,0)) SH2A:propFreeze(1)
SH2B:setPos(entity():boxCenterW()+vec(-100,-200,-125):rotate(ANG)) SH2B:setAng(entity():angles()+ang( 15,90,0)) SH2B:propFreeze(1)

SHL:setPos(entity():boxCenterW()+vec(-100, 350,0):rotate(ANG)) SHL:setAng(ANG+ang(90,90,0)) SHL:propFreeze(1)
SHR:setPos(entity():boxCenterW()+vec(-100,-350,0):rotate(ANG)) SHR:setAng(ANG+ang(90,90,0)) SHR:propFreeze(1)

SHF:setPos(entity():boxCenterW()+vec(-850,0,0):rotate(ANG)) SHF:setAng(ANG+ang(90,0,0)) SHF:propFreeze(1)
SHB:setPos(entity():boxCenterW()+vec( 650,0,0):rotate(ANG)) SHB:setAng(ANG+ang(90,0,0)) SHB:propFreeze(1)

if(SH1A)
{}
else
{
SH1A=propSpawn("models/hunter/plates/plate8x32.mdl",entity():boxCenterW()+vec(-100, 0, 150),ANG+ang(0,90,0),1)
SH1A:setMaterial("models/effects/comball_tape") SH1A:setColor(vec4(255,0,0,100))
}

if(SH1B)
{}
else
{
SH1B=propSpawn("models/hunter/plates/plate8x32.mdl",entity():boxCenterW()+vec(-100, 0, 150),ANG+ang(0,90,0),1)
SH1B:setMaterial("models/effects/comball_tape") SH1B:setColor(vec4(255,0,0,100))
}

if(SH2A)
{}
else
{
SH2A=propSpawn("models/hunter/plates/plate8x32.mdl",entity():boxCenterW()+vec(-100, 0,-150),ANG+ang(0,90,0),1)
SH2A:setMaterial("models/effects/comball_tape") SH2A:setColor(vec4(255,0,0,100))
}

if(SH2B)
{}
else
{
SH2B=propSpawn("models/hunter/plates/plate8x32.mdl",entity():boxCenterW()+vec(-100, 0,-150),ANG+ang(0,90,0),1)
SH2B:setMaterial("models/effects/comball_tape") SH2B:setColor(vec4(255,0,0,100))
}

if(SHL)
{}
else
{
SHL=propSpawn("models/hunter/plates/plate3x32.mdl",entity():boxCenterW()+vec(-100, 350,0),ANG+ang(90,90,0),1)
SHL:setMaterial("models/effects/comball_tape") SHL:setColor(vec4(255,0,0,100))
}

if(SHR)
{}
else
{
SHR=propSpawn("models/hunter/plates/plate3x32.mdl",entity():boxCenterW()+vec(-100,-350,0),ANG+ang(90,90,0),1)
SHR:setMaterial("models/effects/comball_tape") SHR:setColor(vec4(255,0,0,100))
}

if(SHF)
{}
else
{
SHF=propSpawn("models/hunter/plates/plate4x8.mdl",entity():boxCenterW()+vec(-850,0,0),ANG+ang(90,0,0),1)
SHF:setMaterial("models/effects/comball_tape") SHF:setColor(vec4(255,0,0,100))
}

if(SHB)
{}
else
{
SHB=propSpawn("models/hunter/plates/plate4x8.mdl",entity():boxCenterW()+vec( 650,0,0),ANG+ang(90,0,0),1)
SHB:setMaterial("models/effects/comball_tape") SHB:setColor(vec4(255,0,0,100))
}


if(POD["Shift",number])
{
if(((AIM:pitch())>0)&((AIM:yaw())<0))
{SH1A:propNotSolid(1)}
elseif(((AIM:pitch())>0)&((AIM:yaw())>0))
{SH1B:propNotSolid(1)}
elseif(((AIM:pitch())<0)&((AIM:yaw())<0))
{SH2A:propNotSolid(1)}
elseif(((AIM:pitch())<0)&((AIM:yaw())>0))
{SH2B:propNotSolid(1)}
else
{}
TShift=1
}
else
{
if(TShift)
{
SH1A:propNotSolid(0) SH1B:propNotSolid(0)
SH2A:propNotSolid(0) SH2B:propNotSolid(0)
TShift=0
}
}


if(POD["Space",number])
{
TSH=550
SHF:propNotSolid(1)
}
elseif(TSH>500)
{
SHF:propNotSolid(1)
TSH--
}
elseif(TSH==500)
{
SHF:propNotSolid(0)
TSH=0
}
elseif(TSH<500)
{
TSH++
}
else
{
SH1A:propBreak() SH1B:propBreak() SH2A:propBreak() SH2B:propBreak() SHL:propBreak() SHR:propBreak() SHF:propBreak() SHB:propBreak()
TSH=0
}

}
else
{
SH1A:propBreak() SH1B:propBreak() SH2A:propBreak() SH2B:propBreak() SHL:propBreak() SHR:propBreak() SHF:propBreak() SHB:propBreak()
}


if(POD["Active",number])
{
if(Targetin)
{TargetAR[1,entity]=Targetin}
else{TargetAR[1,entity]=noentity()}

if(POD["ThirdPerson",number]&(T<=2))
{
if(TargetAR[T,entity]==owner())
{}
else{Target=TargetAR[T,entity]}
}
if(POD["ThirdPerson",number])
{}
else
{
if(TargetAR[T,entity]==owner())
{}
else{Target=TargetAR[T,entity]}

if((POD["PrevWeapon",number]|POD["NextWeapon",number]|POD["Light",number])&(TTarget==8))
{
if((T<TargetAR:count())&(T>=1)){if(POD["NextWeapon",number]){T--}else{T++}}
else{T=1}
TTarget=0
}
else{if(TTarget<8){TTarget++} if(T<=0){T=1}}
}
Shield:propNotSolid(0)
}
else
{
Shield:propNotSolid(1)
Target=noentity()
TTarget=0 T=0
}

if(Tegp==4)
{
AIM=toLocalAng(Target:boxCenterW(),(entity():boxCenterW()-Target:boxCenterW()):toAngle(),entity():boxCenterW(),entity():angles())

EGP:egpCircle(1,vec2(256,256),vec2(50,50)) EGP:egpColor(1,vec(0,255,0))
EGP:egpText(2,"made by tanghao",vec2(250,450)) EGP:egpColor(2,vec(255,255,0)) EGP:egpSize(2,32)
EGP:egpText(3,"maincannon: "+toString(C),vec2(10,10)) EGP:egpColor(3,vec(0,255,0)) EGP:egpSize(3,40)
EGP:egpText(4,"speed: "+toString(round(abs(quat(entity():vel())))),vec2(280,10)) EGP:egpColor(4,vec(0,255,0)) EGP:egpSize(4,40)
EGP:egpText(5,"< ops:"+ops():toString()+" cpu:"+round(cpuUsage()*1000000):toString()+" > < "+(TTarget>20):toString()+(TSH>500):toString()+T:toString()+" >",vec2(80,410))
EGP:egpColor(5,vec(0,127,255)) EGP:egpSize(5,30)
EGP:egpBox(6,vec2(256-144*sin(entity():bearing(vec(0,0,0))),256+144*cos(entity():bearing(vec(0,0,0)))),vec2(10,10)) EGP:egpColor(6,vec(255,255,255))

if(T==1) {
EGP:egpText(7,"target npc: "+Target:model(),vec2(10,50))
EGP:egpBox(8,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(20,20))
EGP:egpLine(9,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(256,256))
}
elseif(T==2){
EGP:egpText(7,"target near player: "+T:toString()+" "+Target:name(),vec2(10,50))
EGP:egpBox(8,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(20,20))
EGP:egpLine(9,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(256,256))
}
else {
EGP:egpText(7,"target player: "+T:toString()+" "+Target:name(),vec2(10,50))
EGP:egpBox(8,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(20,20))
EGP:egpLine(9,vec2(256-128*sin(entity():bearing(Target:boxCenterW())),256+128*cos(entity():bearing(Target:boxCenterW()))),vec2(256,256))
}

for(I1=1,TargetAR:count())
{
if(TargetAR[I1,entity]:health())
{
EGP:egpBox(I1+9,vec2(256-128*sin(entity():bearing(TargetAR[I1,entity]:boxCenterW())),256+128*cos(entity():bearing(TargetAR[I1,entity]:boxCenterW()))),vec2(10,10))
EGP:egpColor(I1+9,vec(255,255,0)) EGP:egpRemove(I1+11)
}
else{EGP:egpRemove(I1+9)}
}
EGP:egpColor(7,vec(255,0,0)) EGP:egpSize(7,30) EGP:egpColor(8,vec(255,0,0)) EGP:egpColor(9,vec(255,0,0))
Tegp=0
}
else{Tegp++}

if ((POD["W",number]==1)&(POD["A",number]==1)&(POD["D",number]==1)==1) {L1= 5 R1= 5 C1=4}
elseif ( POD["S",number]==1) {L1=-4 R1=-4 C1=0}
elseif ((POD["W",number]==1)&(POD["A",number]==0)&(POD["D",number]==0)==1) {L1= 4 R1= 4 C1=4}
elseif ((POD["W",number]==1)&(POD["A",number]==1)&(POD["D",number]==0)==1) {L1= 1 R1= 5 C1=2}
elseif ((POD["W",number]==1)&(POD["A",number]==0)&(POD["D",number]==1)==1) {L1= 5 R1= 1 C1=2}
elseif ((POD["W",number]==0)&(POD["A",number]==1)&(POD["D",number]==1)==1) {L1= 2 R1= 2 C1=0}
elseif ((POD["W",number]==0)&(POD["A",number]==1)&(POD["D",number]==0)==1) {L1=-4 R1= 4 C1=0}
elseif ((POD["W",number]==0)&(POD["A",number]==0)&(POD["D",number]==1)==1) {L1= 4 R1=-4 C1=0}
else {L1=0 R1=0 C1=0}

if(POD["W",number]&POD["R",number]>0)
{
GPSout=(-entity():forward())*2000+entity():boxCenterW()
Tel=POD["R",number]
}
elseif (POD["R",number]>0)
{
GPSout=vec(random(5000)-2500,random(5000)-2500,random(100)-50)+entity():pos()
ANG=ang(0,entity():angles():yaw(),0)
Tel=POD["R",number]
}
elseif (owner():lastSaid()=="/relocate")
{
GPSout=owner():pos()+vec(0,0,300) Tel=1
}
else {GPSout=vec(0,0,0) Tel=0}