@name DC_system
@inputs  Ragdoll:entity P:wirelink Screen:wirelink 
@outputs Cam_on View_ang:angle View_pos:vector Shoot OPS Rocket_power Aim_pos:vector ASD:entity TEST:angle Grabb_relative1:entity Grabb_relative2:entity Grabb_pos1:vector Grabb_pos2:vector 
@persist Dance Dance_i Screams:array Vel_cc Fly Ass_id:bone L_hand_id:bone R_hand_id:bone L_fot_id:bone R_fot_id:bone Body_id:bone Head_id:bone DISTANCE2 For_speed Walk_pos:vector Walk_i Walk_ii Right_speed
@persist  Owner_M2 ACT D_P RH_entity:entity M2_2 Fly2 Dir_home Iii M1 Swim_i Cam_on2 Function_i Function R
@trigger none
interval(50)
Owner_M2=owner():keyAttack2()
ACT=P:number("Active")
#LOL=keyClk("X")
OPS=ops()
Screen:writeString("ops:"+toString(OPS)+"     ",0,17,999,0)

if(duped() | $ACT | first())
    {

    
    entity():setAlpha(0)
    runOnChat(1)
    Screen:writeCell(2041,1)
    Screen:writeString("_______DRUNK_COMBINE__v3______",0,1,990,8)
    Screen:writeString("||||||||||||||||||||||||||||||",0,0,0,9)
    Screen:writeString("_______Made_by_MoPaZoDoZ______",0,2,660,7)
    Screen:writeString("                              ",0,3,0,6)
    Screen:writeString("                              ",0,4,0,5)
    Screen:writeString("                              ",0,5,0,4)
    Screen:writeString("                              ",0,6,0,3)
    Screen:writeString("                              ",0,7,0,2)
    Screen:writeString("                              ",0,8,0,1)
    Screen:writeString("Mouse1=Grabb props",0,4,999,5)
    Screen:writeString("Mouse1",0,4,9,5)
    Screen:writeString("Mouse2=fly",0,5,999,4)
    Screen:writeString("Mouse2",0,5,9,4)
    Screen:writeString("Space =Jump",0,6,999,3)
    Screen:writeString("Space",0,6,9,3)
    Screen:writeString("Climb =Shift+(M1 or M2)",0,7,999,2)
    Screen:writeString("Climb",0,7,9,2)
    Screen:writeString("Chat commands= hi,dance,dance2,dance3,spin,kick,sit,weirdo,madness,rape",0,8,999,0)
    Screen:writeString("Chat commands",0,8,9,0)
    Screen:writeString("You can download this on",2,12,666,0)
    Screen:writeString("www.garrysmod.org",5,13,666,0)
    Screen:writeString("Have fun! :D",8,15,666,0)
    hint("Drunk Combine v3",5)

    Ragdoll:soundPlay(2,0,"vehicles/fast_windloop1.wav")
    soundPitch(2,0)
    Dance=0
    if(1)
    {
    Ragdoll:soundPlay(1,0,"npc/combine_soldier/vo/off3.wav")
    }
    L_hand_id=Ragdoll:bone(7)
    R_hand_id=Ragdoll:bone(5)
    L_fot_id=Ragdoll:bone(13)
    R_fot_id=Ragdoll:bone(14)
    Body_id=Ragdoll:bone(1)
    Head_id=Ragdoll:bone(10)
    Ass_id=Ragdoll:bone(0)
    
    L_hand_id:setMass(3)
    R_hand_id:setMass(3)
    L_fot_id:setMass(10.7)
    R_fot_id:setMass(10.7)
    Body_id:setMass(22.4)
    Head_id:setMass(7)
    Ass_id:setMass(11)

  
    
holoParent(1,Body_id)
#holoParent(1,Ragdoll,"beam_damage") 

    Screams[1, string] = "vo/npc/male01/hitingut01.wav"
    Screams[2, string] = "vo/npc/male01/hitingut02.wav"
    Screams[6, string] = "vo/npc/male01/myarm01.wav"
    Screams[7, string] = "vo/npc/male01/myarm02.wav"
    Screams[8, string] = "vo/npc/male01/mygut02.wav"
    Screams[9, string] = "vo/npc/male01/myleg01.wav"
    Screams[10, string] = "vo/npc/male01/myleg02.wav"
    Screams[11, string] = "vo/npc/male01/ow01.wav"
    Screams[12, string] = "vo/npc/male01/ow02.wav"
    Screams[13, string] = "vo/npc/male01/pain01.wav"
    Screams[14, string] = "vo/npc/male01/pain02.wav"
    Screams[15, string] = "vo/npc/male01/pain03.wav"
    Screams[16, string] = "vo/npc/male01/pain04.wav"
    Screams[17, string] = "vo/npc/male01/pain05.wav"
    Screams[18, string] = "vo/npc/male01/pain06.wav"
    Screams[5, string] = "vo/npc/male01/pain07.wav"
    Screams[4, string] = "vo/npc/male01/pain08.wav"
    Screams[3, string] = "vo/npc/male01/pain09.wav"
    
    }

Dist=Ragdoll:pos():distance(entity():pos())


if(Dist>100 | ACT)
{
if(ACT)
{

W=P:number("W")
S=P:number("S")
D=P:number("D")
A=P:number("A")
ELE=P:number("Elevation")
BEA=P:number("Bearing")

AIMPOS=P:vector("AimPos")
M1=P:number("Mouse1")
M2=P:number("Mouse2")
SPACE=P:number("Space")
SHIFT=P:number("Shift")
DRIVER=P:entity("Entity"):driver()
}
else
    {

    if((Ragdoll:pos():z()-entity():pos():z())>-100)
    {
    M2=0

    ELE=0
    rangerFilter(Ragdoll)
    RI1=rangerOffset(120,Ragdoll:pos(),ang(0,Dir_home-45,0):forward()):distance()
    rangerFilter(Ragdoll)
    RI2=rangerOffset(120,Ragdoll:pos(),ang(0,Dir_home+45,0):forward()):distance()
    if(RI1+RI2<60)
        {
        For_speed=0
        Dir_home+=180
        W=0
        }
    else
        {
        W=1
        }
    SHIFT=0
    M1=0
    }
    else
        {
    rangerFilter(Ragdoll)
    RI1=rangerOffset(120,Ragdoll:pos(),ang(0,Dir_home,0):forward()):hit()
    if(RI1)
        {
        SHIFT=1
        ELE=0
        if(Iii>20)
            {
            M2=1
            SHIFT=0
            Iii=0
            if(M1)
                {
                M1=0
                }
            else
                {
                M1=1
                }
            }
        Iii+=1
        

        
        M2=1-M1

        
        }
    else
        {
        SHIFT=0
        M1=0
        M2=0
        W=0
        RI1=0
        RI2=0
        ELE=25
        }
        }
    W=1

    Dir_home+=sin((entity():pos()-Ragdoll:pos()):toAngle():yaw()-Dir_home)*(5+M2*12) +(-RI1+RI2)/5
    BEA=Dir_home
    }
SPEED=Ragdoll:vel():length()
rangerFilter(Ragdoll)
R2=rangerOffset(5000,Body_id:pos(),View_ang:forward())
Aim_pos=R2:position()
ACC=SPEED-Vel_cc
if(ACC>100)
    {
    Ragdoll:soundPlay(0,0,Screams:string(round(random(18))))
    }
View_ang=ang(-ELE,BEA,0)
View_ang_yaw=ang(0,BEA,0)
rangerFilter(Ragdoll)
View_pos=Head_id:pos()+vec(0,0,5)-View_ang:forward()*(rangerOffset(Head_id:pos(),Head_id:pos()-View_ang:forward()*200):distance()-40)


rangerFilter(Ragdoll)
rangerFilter(RH_entity)
RR=rangerOffset(70,Ragdoll:pos(),vec(0,0,-1))
if(Fly>0.1)
    {DISTANCE=30+Fly*40}
else
    {
    
    if(random(100)>99 & Dance==0)
        {
        Ragdoll:soundPlay(0,0,Screams:string(round(random(18))))
        }

    DISTANCE=RR:distance()
    if(DISTANCE>69 | ACC>220)
        {
        
        Fly=1
        "RH_entity=noentity()"
        }

    }


if((Ragdoll:vel()-RR:entity():vel()):length()<(100-Fly*49 + (1-D_P)*80) & RR:hit())
{Fly-=0.05 Fly2=0}

if(1) ############################if(!SHIFT)############3
    {
D_P=1-(DISTANCE/70)
D_D=DISTANCE-DISTANCE2

    Body_id:applyForce(vec(-Body_id:vel():x()*D_P,-Body_id:vel():y()*D_P,D_P*(50-D_D*5))*100)
    
    
    


Head_id:applyForce(vec(0,0,D_P*600))
if(M1 & !SHIFT) ############if(M1)################3
{
"rangerFilter(Ragdoll)"
"R2=rangerOffset(5000,Ragdoll:pos(),View_ang:forward())"
if(!RH_entity & R2:entity() & R2:distance()<50)
    {
    RH_entity=R2:entity()
    Ragdoll:soundPlay(0,0,Screams:string(4))
    }
else
    {
    if(RH_entity:type()=="gmod_wire_button")
    {
    #RH_entity:use()
    }
    Ipos=RH_entity:pos()+View_ang:forward()
    RH_entity:applyAngForce((-ang(RH_entity:elevation(Ipos),RH_entity:bearing(Ipos),RH_entity:angles():roll())*20 - RH_entity:angVel())*ang(1,1,0.2)*RH_entity:mass()/2)
    RH_entity:applyForce(((Head_id:pos()+Ragdoll:vel()/14+View_ang:forward()*RH_entity:radius()-RH_entity:pos())*20-RH_entity:vel())*RH_entity:mass()/2)
     #RH_entity:propFreeze(0)
    }
L_hand_id:applyForce(((-L_hand_id:pos()+Body_id:pos()+View_ang:forward()*22+View_ang:right()*11)*130-L_hand_id:vel()*8)*D_P)
R_hand_id:applyForce(((-R_hand_id:pos()+Body_id:pos()+View_ang:forward()*22-View_ang:right()*11)*130-R_hand_id:vel()*8)*D_P)

}
else
    {
    RH_entity=noentity()
    }
if(M2 & RH_entity )
{
#RH_entity:applyForce(View_ang:forward()*1000000000)
#R_hand_id:applyForce(View_ang:forward()*10000)
#L_hand_id:applyForce(View_ang:forward()*10000)
#RH_entity=noentity()
Shoot=1
}
else
    {
    Shoot=0
    }
}
if(SHIFT)  ############else###########
    {
    
    if(M2)
        {
        
    rangerFilter(Ragdoll)
    if(Grabb_pos1==vec())
        {
        G1=rangerOffset(30,L_hand_id:pos(),View_ang:forward())
        
        if(G1:hit())
            {
            Ragdoll:soundPlay(0,0,Screams:string(2))
            if(G1:entity())
                {
                Grabb_relative1=G1:entity()
                Grabb_pos1=G1:entity():toLocal(G1:position())

                }
            else
                {
                Grabb_pos1=G1:position()
                Grabb_relative1=noentity()
                }
            
            }
        }
    else
        {
        R_hand_id:applyForce((View_ang:up()*2500 - View_ang:right()*300)*!M1)
        if(Grabb_relative1)
            {
            G_force=(Grabb_relative1:toWorld(Grabb_pos1) - L_hand_id:pos())*50 -L_hand_id:vel()*4 + Grabb_relative1:vel()*5
            Grabb_relative1:applyOffsetForce(-G_force*14,L_hand_id:pos())
            }
        else
            {
            G_force=(Grabb_pos1-L_hand_id:pos())*50 -L_hand_id:vel()*4
            }
        Body_id:applyForce(G_force*4-Body_id:vel()*10)
        L_hand_id:applyForce(G_force)
       }
        }
    else
        {
        Grabb_relative1=noentity()
        Grabb_pos1=vec()
        }
    if(M1)
        {
        
    rangerFilter(Ragdoll)
    if(Grabb_pos2==vec())
        {
        G1=rangerOffset(30,R_hand_id:pos(),View_ang:forward())
        if(G1:hit())
            {
            Ragdoll:soundPlay(0,0,Screams:string(3))
            if(G1:entity())
                {
                Grabb_relative2=G1:entity()
                Grabb_pos2=G1:entity():toLocal(G1:position())

                }
            else
                {
                Grabb_pos2=G1:position()
                Grabb_relative2=noentity()
                }
            }
        }
    else
        {
        if(Grabb_relative2)
            {
            G_force=(Grabb_relative2:toWorld(Grabb_pos2) - R_hand_id:pos())*50 - R_hand_id:vel()*4 + Grabb_relative2:vel()*5
            Grabb_relative2:applyOffsetForce(-G_force*14,R_hand_id:pos())
 
            }
        else
            {
            G_force=(Grabb_pos2-R_hand_id:pos())*50 -R_hand_id:vel()*4
            }
        Body_id:applyForce(G_force*4-Body_id:vel()*10)
        R_hand_id:applyForce(G_force)
        L_hand_id:applyForce((View_ang:up()*2500 + View_ang:right()*300)*!M2)
        }
}
      else
        {
        Grabb_pos2=vec()
        Grabb_relative2=noentity()
        }      
    }
else
    {
    Grabb_pos2=vec()
    Grabb_relative2=noentity()
    Grabb_pos1=vec()
    Grabb_relative1=noentity()
    }
if(W)
    {
    For_speed=min(For_speed+700,5000)
    
    }
elseif(S)
    {
    For_speed=max(For_speed-700,-6000)
    }

else
    {
    For_speed=For_speed/1.3

    }
if(Fly<0.2)
    {
      
    
        
 Body_id:applyForce(RR:entity():vel()*50*vec(1,1,0.1)+(View_ang_yaw:forward()*For_speed*1.1+(((L_fot_id:pos()+R_fot_id:pos())/2)-Body_id:pos())*100+vec(0,0,3900))*D_P*2.5)
#Head_id:applyAngForce((ang(0,-Head_id:bearing(Head_id:pos()+View_ang:up()*1000)-30,-Head_id:elevation(Head_id:pos()+View_ang:forward()*1000))-Head_id:angVel()/2000)*ang(100,300,210)*D_P)

Head_F=Head_id:right():toAngle()
Head_id:applyAngForce((ang(0,sin(Head_F:pitch()-View_ang:pitch())*170,-sin(Head_F:yaw()-View_ang:yaw())*170)-Head_id:angVel()/9)*ang(100,100,100)*D_P)


#Head_id:applyAngForce(ang(0,0,1)*10000)
#Head_id:applyAngForce(ang(0,100000,0))
Walk_i+=For_speed/170

Walk_pos=View_ang_yaw:forward()*+sin(Walk_i)*27+View_ang_yaw:up()*cos(Walk_i)*30
  L_fot_id:applyForce(D_P*5*(-L_fot_id:vel()*4+(Ragdoll:pos()+vec(0,0,-40+For_speed/1000)-View_ang:right()*4+Walk_pos*(For_speed/6000)-L_fot_id:pos())*70)*abs(For_speed)/6000)
  R_fot_id:applyForce(D_P*5*(-R_fot_id:vel()*4+(Ragdoll:pos()+vec(0,0,-40+For_speed/1000)+View_ang:right()*4-Walk_pos*(For_speed/6000)-R_fot_id:pos())*70)*abs(For_speed)/6000)

L_fot_id:applyAngForce(ang(0,-sin(Walk_i)*2,0)*For_speed)
R_fot_id:applyAngForce(ang(0,sin(Walk_i)*2,0)*For_speed)

if(SPACE)
    {
    "Body_id:applyForce(vec(0,0,70000))"
    Body_id:applyForce(View_ang:forward()*10000+vec(0,0,17000))
    }
############FUNCTIONS""""


if(Function_i>0)
    {
    if(Function==1)
        {
        Function_i-=44
        R_hand_id:applyForce(((-R_hand_id:pos()+Body_id:pos()+View_ang:forward()*12-View_ang:right()*(15+sin(Function_i)*20)+vec(0,0,40))*110-R_hand_id:vel()*8)*D_P)
        }
    elseif(Function==2)
        {
        Function_i-=5
        L_hand_id:applyForce(((-L_hand_id:pos()+Body_id:pos()+View_ang:forward()*12+View_ang:right()*(10+20*sin(Function_i*4))+vec(0,0,1)*(abs(sin(Function_i*4))*67-30))*110-L_hand_id:vel()*8)*D_P)
        R_hand_id:applyForce(((-R_hand_id:pos()+Body_id:pos()+View_ang:forward()*12+View_ang:right()*(-10+20*sin(Function_i*4))+vec(0,0,1)*(abs(sin(Function_i*4))*67-30))*110-R_hand_id:vel()*8)*D_P)
    
        }
    elseif(Function==3)
        {
        Function_i-=55
        R_fot_id:applyForce(View_ang:forward()*sin(Function_i)*5000)
        }
    elseif(Function==4)
        {
        Function_i-=5
        L_hand_id:applyForce((Body_id:pos()-L_hand_id:pos()):rotate(0,100,0)*30)
        R_hand_id:applyForce((Body_id:pos()-R_hand_id:pos()):rotate(0,100,0)*30)    
        }
    elseif(Function==5)
        {
        Function_i-=5
        L_hand_id:applyForce(vec(5-random(10),5-random(10),random(10))*100)
        R_hand_id:applyForce(vec(5-random(10),5-random(10),random(10))*100) 
        }
    elseif(Function==6)
        {
        Function_i-=5
        Body_id:applyForce(vec(0,0,-8000))

        }
    elseif(Function==7)
        {
        Function_i-=44
        L_hand_id:applyForce((Body_id:pos()-L_hand_id:pos()+View_ang_yaw:forward()*17+vec(0,0,sin(Function_i)*20))*60-L_hand_id:vel()*4)
        R_hand_id:applyForce((Body_id:pos()-R_hand_id:pos()+View_ang_yaw:forward()*17-View_ang_yaw:right()*10+vec(0,0,sin(Function_i)*20))*60-R_hand_id:vel()*4)
        L_fot_id:applyForce((Body_id:pos()-L_fot_id:pos()+View_ang_yaw:forward()*17+vec(0,0,-30+sin(Function_i)*20))*110-L_fot_id:vel()*4)
        L_fot_id:applyAngForce(ang(0,2000,0))
    
 

        }
    elseif(Function==8)
        {
        Function_i-=64
        Body_id:applyForce(vec(0,0,-3000+sin(Function_i)*10000))
        L_hand_id:applyForce(vec(0,0,500)-L_hand_id:vel()*2)
        R_hand_id:applyForce(vec(0,0,500)-R_hand_id:vel()*2)
 

        }
    elseif(Function==9)
        {
        Function_i-=44
        Ass_id:applyForce(View_ang_yaw:forward()*cos(Function_i)*3000)
        
        L_hand_id:applyForce((Ragdoll:pos()-L_hand_id:pos()+vec(0,0,5)+View_ang_yaw:forward()*27+View_ang_yaw:right()*10)*60-L_hand_id:vel()*4)
        R_hand_id:applyForce((Ragdoll:pos()-R_hand_id:pos()+vec(0,0,5)+View_ang_yaw:forward()*27-View_ang_yaw:right()*10)*60-R_hand_id:vel()*4)

 

        }
    elseif(Function==10)
        {
        Function_i-=74
        Ass_id:applyForce(vec(0,0,-4000))
        
        L_hand_id:applyForce(vec(0,0,2000)+View_ang_yaw:right()*sin(Function_i)*1000)
        R_hand_id:applyForce(vec(0,0,2000)+View_ang_yaw:right()*sin(Function_i)*1000)

 

        }
    }
}
DISTANCE2=DISTANCE
Vel_cc=Ragdoll:vel():length()
    if(M2 & Rocket_power>0 & !SHIFT & !M1)
    {
    Rocket_power-=0.001
    if(M2_2)
        {
        Rocket_power=0
        M2_2=0
        Ragdoll:setTrails(10,100,1,"trails/smoke",vec(255,255,255),255)
        
        Ragdoll:soundPlay(3,0,"weapons/rpg/rocket1.wav")
        }

    Super_vec=View_ang:forward()*4000+vec(0,0,1000)
    L_hand_id:applyForce((Super_vec+View_ang:right()*500)*Rocket_power)
    R_hand_id:applyForce((Super_vec-View_ang:right()*500)*Rocket_power)
    Body_id:applyForce((Super_vec*8)*Rocket_power)
    }
elseif(M2_2==0)
    {
    
    M2_2=1
    soundStop(3)
    Ragdoll:removeTrails()
    holoPos(0,vec())
    }

Rocket_power=min(Rocket_power+0.02,1)

soundPitch(2,SPEED/15)
soundPitch(3,min(100,Rocket_power*300))




 if(W)
        {
rangerHitWater(1)   
rangerHitEntities(0)   
rangerIgnoreWorld(1)  
R2=rangerOffset(2,Ragdoll:pos(),vec(0,0,-1))
if(R2:hit())
    {
   
    Swim_i+=34
    Swim_pos1=View_ang:forward()*sin(Swim_i)*35+View_ang:right()*cos(Swim_i)*20
    Swim_pos2=View_ang:forward()*sin(Swim_i)*35-View_ang:right()*cos(Swim_i)*20
    R_hand_id:applyForce((-R_hand_id:pos()+Body_id:pos()-View_ang:right()*20 + Swim_pos1+View_ang:forward()*30)*110-R_hand_id:vel()*7)
    L_hand_id:applyForce((-L_hand_id:pos()+Body_id:pos()+View_ang:right()*20 + Swim_pos2+View_ang:forward()*30)*110-L_hand_id:vel()*7)
    
    L_fot_id:applyForce((-L_fot_id:pos()+Body_id:pos()-View_ang:right()*15 + Swim_pos1 - View_ang:forward()*10)*30-L_fot_id:vel()*2)
    R_fot_id:applyForce((-R_fot_id:pos()+Body_id:pos()+View_ang:right()*15 + Swim_pos2 - View_ang:forward()*10)*30-R_fot_id:vel()*2)
    Head_id:applyForce(View_ang:forward()*1000)
        
    }
}

if(chatClk(DRIVER))
    {
    TEXT=DRIVER:lastSaid() 
    if(TEXT:find("hi"))
        {
        soundPlay(31,0,"npc/combine_soldier/vo/affirmative.wav")
        Function_i=1800
        Function=1
        }
    if(TEXT:find("dance"))
        {
        soundPlay(31,0,"npc/combine_soldier/vo/affirmative.wav")
        Function_i=1100
        Function=2
        }
    if(TEXT:find("kick"))
        {
        Function_i=360
        Function=3
        }
    if(TEXT:find("spin"))
        {
        Function_i=1000
        Function=4
        }
    if(TEXT:find("weirdo"))
        {
        Function_i=1000
        Function=5
        }
    if(TEXT:find("sit"))
        {
        Function_i=1000
        Function=6
        }
  if(TEXT:find("dance2"))
        {
        Function_i=11000
        Function=7
        }
  if(TEXT:find("dance3"))
        {
        Function_i=11000
        Function=8
        }
  if(TEXT:find("rape"))
        {
        Function_i=11000
        Function=9
        }
  if(TEXT:find("madness"))
        {
        Function_i=11000
        Function=10
        }
    }
    
if(!RR:hit())
    {
    Fly=1
    }
}
TEST=Head_id:angles()
