@name Magical Snake Vector by Gobo

@persist Obj:array MyPos:vector C Num TurnSpeed



if (first()) { # If it is the first time the Chip has run

    findIncludePlayerProps(owner()) # Add the owner to the list of props to find

    findByClass("prop_physics")

    Obj = findToArray() # Shove them in an array

    C = Obj:count() # Get the size of the array

    hint("Objects found: " + C, 2)

    TurnSpeed = 140 # Speed of the props going round your head

}



runOnTick(1) # Run this script every 'Tick'



MyPos = owner():pos() + vec(0, 0, owner():height() + 150) # Position above your head



if (owner():isCrouch()) { # If you are crouching



    TempE = 1

    while (TempE <= C) { # Loop through all the Entities

        TempE++

        Num++ # Go through each object

        # Move the object from the top of the stack to the bottom

        Obj:insertEntity(1, Obj:popEntity()) 

        if ((Num % C) != 1) { # If object is not the LEADING object

            TempEnt = Obj:entity(1) # Get the object at the start of the array

            # Set starting Vector

            TempV = (Obj:entity(2):massCenter() - TempEnt:massCenter()) * 10

            # Apply force in direction of next object

            TempEnt:applyForce(TempEnt:mass() * (TempV - TempEnt:vel())) 

            # Apply a fading colour scheme

            TempEnt:setColor(0 + 30*(Num % C), 0 + 30*(Num % C), 0 + 30*(Num % C)) 

        } else { # Head

            TempEnt = Obj:entity(1) # Get the object at the start of the array

            # Create a vector that points from the object to the owners aiming position

            TempV = (owner():aimPos() - TempEnt:massCenter()) * 10 

            # Follow the aiming position of owner

            TempEnt:applyForce(TempEnt:mass() * (TempV - TempEnt:vel())) 

            TempEnt:setColor(0, 0, 0) # Set colour to black

        }

    }



} else {



    TempE = 1

    while (TempE <= C) { # Loop through all the Entities

        TempE++

        Num++ # Go through each object

        # Move the object from the top of the stack to the bottom

        Obj:insertEntity(1, Obj:popEntity()) 

        TempEnt = Obj:entity(1) # Grab the first entity in the array

        TempV = (MyPos - TempEnt:massCenter()) # Set initial vector

        TempV += vec(30 * C * (TurnSpeed/200) * sin((curtime() + 

                                        (Num % C)/(C)*360/TurnSpeed) * TurnSpeed),

                     30 * C * (TurnSpeed/200) * cos((curtime() + 

                                        (Num % C)/(C)*360/TurnSpeed) * TurnSpeed),

                     0) # Add the circular algorithm to it

        TempV *= 10 # Mult Vector to make objects fly to the correct position faster

        # Subtract the velocity to smooth out the movement. 

        # Multiply by the mass to make it consistent with objects of different mass.

        # Then apply the force.

        TempEnt:applyForce((TempV - TempEnt:vel()) * TempEnt:mass())

        TempEnt:applyAngForce(ang(90, 90, 90) * 200) # Give it a little rotationq

    }

        

}