@name O2's Gun Chip
@inputs Unequip Pad1 Pad2 Pad3 W1:entity W2:entity W3:entity
@outputs Ranger:ranger Slot V:vector A:angle Clamp:angle Weapon:string Fire1 Fire2 Fire3 AimEnt:entity GPS:vector Props:array

runOnTick(1)
rangerFilter(Props)
rangerFilter(owner())
Ranger=rangerOffset(10^10,owner():shootPos(),owner():eye())
if(!Ranger:entity():isWorld()){
    if(changed(Ranger:entity())&Ranger:entity()){
        if(W1==Ranger:entity()){
            Props=W1:getConstraints()
            Props:pushEntity(W1)
        }
        elseif(W2==Ranger:entity()){
            Props=W2:getConstraints()
            Props:pushEntity(W2)
        }
        elseif(W3==Ranger:entity()){
            Props=W3:getConstraints()
            Props:pushEntity(W3)
        }
        else{
            AimEnt=Ranger:entity()
        }
    }
}
if(AimEnt){
    GPS=AimEnt:pos()+vec(0,0,AimEnt:height()/2)
}
Weapon=owner():weapon():type()
if(first()|duped()){
    Slot=1
}
if(changed(Pad1)&Pad1){
    Slot=Pad1
    print(4,"You Chose Slot1.")
}
if(changed(Pad2)&Pad2){
    Slot=Pad2+1
    print(4,"You Chose Slot2.")
}
if(changed(Pad3)&Pad3){
    Slot=Pad3+2
    print(4,"You Chose Slot3.")
}
if(changed(Unequip)&Unequip){
    Slot=4
    print(4,"Unequip Weapon.")
}
if((Weapon=="weapon_crowbar"|Weapon=="weapon_rpg"|Weapon=="weapon_frag")&Slot!=4&Slot!=0){
    Slot=4
    print(4,"Unequip Weapon.")
    owner():weapon():setMaterial("")
}
if((Slot>0&Slot<4)){
    owner():weapon():setMaterial("models/effects/vol_light001")
}
if(changed(Slot)|(changed(W1)&W1)){
    W1:setMass(50000)
}
if(changed(Slot)|(changed(W2)&W2)){
    W2:setMass(50000)
}
if(changed(Slot)|(changed(W2)&W2)){
    W2:setMass(50000)
}
if(Slot==1){
    Clamp=clamp(owner():eyeAngles(),-ang(60,180,0),ang(60,180,0))
    A=angnorm(Clamp-W1:angles())
    V=(owner():attachmentPos("anim_attachment_rh")+vec(-0.5,-2,1):rotate(owner():attachmentAng("anim_attachment_rh"))-W1:massCenter())
    W1:applyForce((V*20-W1:vel())*W1:mass())
    W1:applyAngForce((A*20-W1:angVel())*W1:inertia():length()*10)
    W2:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*2)*100,cos(curtime()*50+360/3*2)*100,sin(curtime()*100+360/3*2)*25+200)-W2:massCenter())*10-W2:vel())*W2:mass())
    W3:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*3)*100,cos(curtime()*50+360/3*3)*100,sin(curtime()*100+360/3*3)*25+200)-W3:massCenter())*10-W3:vel())*W3:mass())
}
if(Slot==2){
    Clamp=clamp(owner():eyeAngles(),-ang(60,180,0),ang(60,180,0))
    A=angnorm(Clamp-W2:angles())
    V=(owner():attachmentPos("anim_attachment_rh")+vec(-0.5,-2,1):rotate(owner():attachmentAng("anim_attachment_rh"))-W2:massCenter())
    W2:applyForce((V*20-W2:vel())*W2:mass())
    W2:applyAngForce((A*20-W2:angVel())*W2:inertia():length()*10)
    W1:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*1)*100,cos(curtime()*50+360/3*1)*100,sin(curtime()*100+360/3*1)*25+200)-W1:massCenter())*10-W1:vel())*W1:mass())
    W3:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*3)*100,cos(curtime()*50+360/3*3)*100,sin(curtime()*100+360/3*3)*25+200)-W3:massCenter())*10-W3:vel())*W3:mass())
}
if(Slot==3){
    Clamp=clamp(owner():eyeAngles(),-ang(60,180,0),ang(60,180,0))
    A=angnorm(Clamp-W3:angles())
    V=(owner():attachmentPos("anim_attachment_rh")+vec(-0.5,-2,1):rotate(owner():attachmentAng("anim_attachment_rh"))-W3:massCenter())
    W3:applyForce((V*20-W3:vel())*W3:mass())
    W3:applyAngForce((A*20-W3:angVel())*W3:inertia():length()*10)
    W1:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*1)*100,cos(curtime()*50+360/3*1)*100,sin(curtime()*100+360/3*1)*25+200)-W1:massCenter())*10-W1:vel())*W1:mass())
    W2:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*2)*100,cos(curtime()*50+360/3*2)*100,sin(curtime()*100+360/3*2)*25+200)-W2:massCenter())*10-W2:vel())*W2:mass())
}
if(Slot<1|Slot>3){
    A=angnorm(ang()-W3:angles())
    W1:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*1)*100,cos(curtime()*50+360/3*1)*100,sin(curtime()*100+360/3*1)*25+200)-W1:massCenter())*10-W1:vel())*W1:mass())
    W2:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*2)*100,cos(curtime()*50+360/3*2)*100,sin(curtime()*100+360/3*2)*25+200)-W2:massCenter())*10-W2:vel())*W2:mass())
    W3:applyForce(((owner():shootPos()+vec(sin(curtime()*50+360/3*3)*100,cos(curtime()*50+360/3*3)*100,sin(curtime()*100+360/3*3)*25+200)-W3:massCenter())*10-W3:vel())*W3:mass())
    W1:applyAngForce((angnorm(ang()-W1:angles())*10-W1:angVel())*W1:inertia():length())
    W2:applyAngForce((angnorm(ang()-W2:angles())*10-W2:angVel())*W2:inertia():length())
    W3:applyAngForce((angnorm(ang()-W3:angles())*10-W3:angVel())*W3:inertia():length())
}
if(owner():keyUse()&Slot==1&Slot!=4&Slot!=0){
    Fire1=1
}
else{
    Fire1=0
}
if(owner():keyUse()&Slot==2&Slot!=4&Slot!=0){
    Fire2=1
}
else{
    Fire2=0
}
if(owner():keyUse()&Slot==3&Slot!=4&Slot!=0){
    Fire3=1
}
else{
    Fire3=0
}
