@name Remote Viewer And Teleporter (RVAT)
@inputs [AdvPod Teleport CamCon Field]:wirelink
@outputs [Last JumpTarget]:vector
@persist X Y Z Direction:vector Position:vector JumpTarget:vector
@persist Last:vector HoverDrive:entity Off:vector FieldOn
@trigger 
@model models/props_junk/PopCan01a.mdl
runOnChat(1)
O=owner()
Chat=O:lastSaid()
if(dupefinished()){reset()}
K=chatClk()

interval(10)

#Outputs
W=AdvPod["W",number]
A=AdvPod["A",number]
S=AdvPod["S",number]
D=AdvPod["D",number]
Mouse1=AdvPod["Mouse1",number]
Mouse2=AdvPod["Mouse2",number]
R=AdvPod["R",number]
Space=AdvPod["Space",number]
Shift=AdvPod["Shift",number]
Zoom=AdvPod["Zoom",number]
Alt=AdvPod["Alt",number]
TurnLeftKey=AdvPod["TurnLeftKey",number]
TurnRightKey=AdvPod["TurnRightKey",number]
PrevWeapon=AdvPod["PrevWeapon",number]
NextWeapon=AdvPod["NextWeapon",number]
AimPos=AdvPod["AimPos",vector]
ThirdPerson=AdvPod["ThirdPerson",number]
Distance=AdvPod["Distance",number]
Light=AdvPod["Light",number]
Active=AdvPod["Active",number]
Team=AdvPod["Team",number]
Health=AdvPod["Health",number]
Armor=AdvPod["Armor",number]
Bearing=AdvPod["Bearing",number]
Elevation=AdvPod["Elevation",number]
Entity=AdvPod["Entity",entity]


#chat induce teleport function (rescue)
Com="RVAT"
Here="here"
Aim="aim"
Attract="grav"
On1="on"
On0="off"
Help="help"
Sp=" "


COM=Chat:find(Com)
HERE=Chat:find(Here)
AIM=Chat:find(Aim)
HELP=Chat:find(Help)
ON1=Chat:find(On1)
ON0=Chat:find(On0)
ATTRACT=Chat:find(Attract)


if(first()){
    print("Type "+Com+Sp+Help+" to get chat commands.")
    HoverDrive=entity():isConstrainedTo()
    Pos=entity():pos()
    X=Pos:x()
    Y=Pos:y()
    Z=Pos:z()
    Off=vec(0,0,20)
}



if(K&COM){
    hideChat(1)
    if(HELP){
        print(Com+Sp+Here+Sp+" -teleports "+Com+" just in front of owner")
        print(Com+Sp+Aim+Sp+" -teleports "+Com+" to where owner looks")
        print(Com+Sp+Help+Sp+" -Dislays this message")
        print(Com+Sp+Attract+On1+" -Activates Gravity generator.")
        print(Com+Sp+Attract+On0+" -Deactivates Gravity generator.")
    }
    if(AIM){
        Last=HoverDrive:pos()+Off
        JumpTarget=O:aimPos()+Off
        Jump=1
        SetJump=1
        timer("disable",500)
    }
    if(HERE){
        Last=HoverDrive:pos()+Off
        JumpTarget=O:pos()+Off+O:forward()*30
        Jump=1
        SetJump=1
        timer("disable",500)
    }
    if(ATTRACT){
        if(ON1){FieldOn=1}
        if(ON0){FieldOn=0}   
    }
}else{hideChat(0)}
if(clk("disable")){
    Jump=0
    SetJump=0
}

User=Entity
Angle=User:passenger():eye():toAngle()
Speed=4
Run=16
Sprint=16
if(Active){

    if(changed(Active)){
        User:printDriver("Press the Zoom key for assistance")
    }
    SinY0=sin(Angle:yaw())
    SinP90=sin(Angle:pitch()+90)
    CosP90=cos(Angle:pitch()+90)
    CosY0=cos(Angle:yaw())
    
    timer("kick",10)
    if(W) {Y +=SinY0*SinP90*Speed*((Shift*Run)+1)
           X +=CosY0*SinP90*Speed*((Shift*Run)+1)
           Z +=CosP90*Speed*((Shift*Run)+1)}
    if(S) {Y -=SinY0*Speed*SinP90*((Shift*Run)+1)
           X -=CosY0*Speed*SinP90*((Shift*Run)+1)
           Z -=CosP90*Speed*((Shift*Run)+1)}
    if(A) {Y +=CosY0*Speed*((Shift*Run)+1)
           X -=SinY0*Speed*((Shift*Run)+1)}
    if(D) {Y -=CosY0*Speed*((Shift*Run)+1)
           X +=SinY0*Speed*((Shift*Run)+1)}
    if(Space) {Z +=1*(Shift*Sprint)+1}
    if(Alt) {Z -=1*(Shift*Sprint)+1}
    
    if(R){
        X=entity():pos():x()
        Y=entity():pos():y()
        Z=entity():pos():z()
    }
    if(vec(X,Y,Z):isInWorld()){Position=vec(X,Y,Z)}
    
    Direction = User:passenger():eye()
    if(Zoom&changed(Zoom)){
        User:printDriver("Welcome to the Remote Viewer And Teleporter")
        User:printDriver("To use RVAT simply fly to some place as if using noclip.")
        User:printDriver("left click to teleport there, or right click to go to last location.")
        User:printDriver("jump and walk keys (space and alt) go up and down if needed.")
    }
    CM1=changed(Mouse1)
    if(Mouse2&!Mouse1){
        JumpTarget=Last
        Jump=1
        SetJump=1
    }elseif(Mouse1&!Mouse2&CM1){
        Last=entity():isConstrainedTo():pos()
        Jump=1 
        SetJump=1
        JumpTarget=vec(X,Y,Z)
        
    }else{Jump=0 SetJump=0}
}





Sound=0
Activated=Active

#Field Generator
Field["Active",number]=FieldOn
Field["Distance",number]=1000
Field["Multiplier",number]=600


#Inputs
Teleport:setNumber("SetJumpTarget",SetJump)
Teleport:setNumber("Jump",Jump)
Teleport:setVector("JumpTarget",JumpTarget)
Teleport:setNumber("Sound",Sound)

#Input
CamCon:setNumber("Activated",Activated)
CamCon:setVector("Position",Position)
CamCon:setVector("Direction",Direction)
