@name Ladder Detector
@inputs 
@outputs Ground Noclip OnLadder ZVel Accel ZAccel Time
@persist ZVel
@trigger 
###Time=50/1000
###runOnTick(1)
##
##
###findInSphere(O:pos(),10000)
###findIncludeClass("ladder")
###findExcludeClass("dismount")
###findExcludeClass("illusionary")
###findExcludeClass("door")
###findExcludeClass("player")
###findExcludeClass("weapon")
###findExcludeClass("gmod")
###findSortByDistance(O:pos())
##
###timer("1sec",1000)
##
###Time=curtime()-Past
###Past=curtime()
###if(changed(Time)){print("Time="+Time)}
##
###ZAccel=round($ZVel/(Time))

if(0){
    #@persist ZVel
    interval(20)
    Mode=0 #0 ladder detection, 1 jump detection, 2 fall detection
    O=owner() #you, or whom ever you want
    ZVel=round(O:vel()):z() #persist this value
    Accel=$ZVel #Z Acceleration calibrated to interval of 20ms or less
    AR=300 #Acceleration Range this filters out jerk from changing direction on a ladder
        Falling=-18 #acceleration when falling
        JumpAccel=178 #acceleration when jumping    

    if(Mode==0){ #this infers your on a ladder 
        Jumping=(Accel!=JumpAccel)&Accel!=187
        Fall=(Accel!=Falling)
    }
    elseif(Mode==1){ #this detects you pressed your jump key based on your acceleration
        Jumping=(Accel==JumpAccel)
        Fall=(Accel!=Falling)
    }
    elseif(Mode==2){  #This will still detect you falling after you press jump
        Jumping=(Accel!=JumpAccel)
        Fall=(Accel==Falling)
    }
    
    if(!isSinglePlayer()&0){
        Falling=-18
        Jumping=(Accel>=178)&(Accel<200)
    }
    OnLadder=!O:isUnderWater()&!O:isOnGround()&!O:inNoclip()&Fall&Jumping&(Accel>-AR)&(Accel<AR)
    if(changed(OnLadder)){print("Accel="+Accel)}
}


Ground=O:isOnGround()
Noclip=O:inNoclip()


if(0){
    #@persist ZVel
    interval(20)
    O=owner() #you, or whom ever you want
    ZVel=round(O:vel()):z() #persist this value this is Z velocity obviously
    Accel=$ZVel #Z Acceleration calibrated to interval of 20ms or less
    AR=300 #Acceleration Range this filters out jerk from changing direction on a ladder
    if(isSinglePlayer()){JumpAccel=178} #acceleration when jumping
    if(!isSinglePlayer()){JumpAccel=0}
    Falling=-18 #acceleration when falling
    OnLadder=!O:isOnGround()&!O:inNoclip()&(Accel!=Falling)&(Accel!=JumpAccel)&(Accel>-AR)&(Accel<AR)
    if(changed(OnLadder)){print("OnLadder="+Accel)}
}


if(1){
    #@persist ZVel
    interval(20)
    O=owner()
    ZVel=round(O:vel()):z() #persist this value this is Z velocity obviously
    OnLadder=!O:isUnderWater()&!O:isOnGround()&!O:inNoclip()&($ZVel!=-18)&($ZVel!=178)&$ZVel!=187&($ZVel>-300)&($ZVel<300)
}
#
##V=D/T
##A=V/T = D/T^2
#
##Find=findToArray()
##if(Find:count()){
##    C=1
##    #for(C=1,Find:count()){
##        rangerIgnoreWorld(1)
##        rangerHitWater(0)
##        rangerHitEntities(1)
##        OnLadder=rangerOffset(10000,Find[C,entity]:pos(),vec(0,0,-1)):hit()
##    #}
##}
##PointHasLadder = pointHasContent(O:aimPos(), "ladder")
##
###Point=pointContents(O:aimPos())
###Water=O:isUnderWater()
##Ground=O:isOnGround()
##NoClip=O:inNoclip()
###Crouch=O:isCrouch()
###if(first()&0){timer("delay",100)}
##if(clk("delay")){
##    for(C=1,Find:count()){
##        holoCreate(C,Find[C,entity]:pos())
##    }
##}
