I made an ANTI-FLYING system for you.

I made an ANTI-FLYING system for you.

Postby Herocane » 05 May 2014, 16:07

Okay- so people are always able to bypass the "-hax" extension to motd's and blah blah. So I decided- as there are both Anti pillaring and Anti speedhack systems- why not make an anti-flying system aswell?

I hope this works well- I have tested it and it seems to work lovely on MCDerp. Here is the code if you're interested. It should be placed in the "HandleInput" void, as shown below.

Code: Select all
void HandleInput( object m ) {
            if ( !loggedIn || trainGrab || following != "" || frozen )
                return;

            byte[] message = (byte[])m;
            byte thisid = message[0];

            ushort x = NTHO( message, 1 );
            ushort y = NTHO( message, 3 );
            ushort z = NTHO( message, 5 );
            byte rotx = message[7];
            byte roty = message[8];

            // Check for flying

            ushort xx = (ushort)( x / 32 );
            ushort yy = (ushort)( y / 32 );
            ushort zz = (ushort)( z / 32 );

            if ( y == oldpos[1] || y > oldpos[1] ) {
                byte currBlock = level.GetTile( xx, (ushort)( yy - 1 ), zz );
                byte belowBlock = level.GetTile( xx, (ushort)( yy - 2 ), zz );

                if ( currBlock != Block.waterstill
                    && currBlock != Block.water
                    && currBlock != Block.water_portal
                    && currBlock != Block.lavastill
                    && currBlock != Block.lava
                    && currBlock != Block.lava_portal ) {

                        if ( belowBlock == Block.air ) {
                            flyingTickCount++;
                        } else {
                            flyingTickCount = 0;
                        }
                } else {
                    flyingTickCount = 0;
                }
            }

            if ( flyingTickCount >= 30 ) {
                ushort Y = 0;
                for ( ushort YY = 0; YY <= yy; YY++ ) {
                    if ( level.GetTile( xx, YY, zz ) != Block.air ) {
                        Y = YY;
                    }
                }
                unchecked {
                    SendMessage( this, "&cFlying is not permitted on this server!" );
                    SendPos( (byte)-1, x, (ushort)( ( ( Y + 2 ) * 32 ) ), z, rot[0], rot[1] );
                }
            }

            pos = new ushort[3] { x, y, z };
            rot = new byte[2] { rotx, roty };
        }


If you implement this- I hope I get credit ;) Naa, only kidding. Have fun with it, hope it helps.
Herocane
 
Posts: 7
Joined: 11 Feb 2011, 02:08

Re: I made an ANTI-FLYING system for you.

Postby Herocane » 05 May 2014, 17:31

This is some revised code- as the previous one proved buggy when a player jumped repeatedly- this version is less sensitive, and requires a player to me more than 2 blocks off the ground before they are pulled down.

Code: Select all
void HandleInput( object m ) {
            if ( !loggedIn || trainGrab || following != "" || frozen )
                return;

            byte[] message = (byte[])m;
            byte thisid = message[0];

            ushort x = NTHO( message, 1 );
            ushort y = NTHO( message, 3 );
            ushort z = NTHO( message, 5 );
            byte rotx = message[7];
            byte roty = message[8];

            // Check for speedhacks

            int diffX = Math.Max( x, oldpos[0] ) - Math.Min( x, oldpos[0] );
            int diffY = Math.Max( y, oldpos[1] ) - Math.Min( y, oldpos[1] );
            int diffZ = Math.Max( z, oldpos[2] ) - Math.Min( z, oldpos[2] );

            if ( diffX > 70 || diffZ > 70 ) {
                unchecked {
                    SendPos( (byte)-1, oldpos[0], oldpos[1], oldpos[2], rot[0], rot[1] );
                }
                return;
            }
           
            if(y > oldpos[1] && diffY > 70) {
                unchecked {
                    SendPos( (byte)-1, oldpos[0], oldpos[1], oldpos[2], rot[0], rot[1] );
                }
                return;
            }

            // Check for flying

            ushort xx = (ushort)( x / 32 );
            ushort yy = (ushort)( y / 32 );
            ushort zz = (ushort)( z / 32 );

            if ( y == oldpos[1] || y > oldpos[1] ) {
                byte currBlock = level.GetTile( xx, (ushort)( yy - 1 ), zz );
                byte belowBlock = level.GetTile( xx, (ushort)( yy - 2 ), zz );
                byte evenBelowerBlock = level.GetTile( xx, (ushort)( yy - 3 ), zz );

                if ( currBlock != Block.waterstill
                    && currBlock != Block.water
                    && currBlock != Block.water_portal
                    && currBlock != Block.lavastill
                    && currBlock != Block.lava
                    && currBlock != Block.lava_portal ) {

                        if ( belowBlock == Block.air && evenBelowerBlock == Block.air ) {
                            flyingTickCount++;
                        } else {
                            flyingTickCount = 0;
                        }
                } else {
                    flyingTickCount = 0;
                }
            }

            if ( flyingTickCount >= 30 ) {
                ushort Y = 0;

                for ( ushort YY = 0; YY <= yy; YY++ ) {
                    if ( level.GetTile( xx, YY, zz ) != Block.air ) {
                        Y = YY;
                    }
                }

                unchecked {
                    SendPos( (byte)-1, x, (ushort)( ( ( Y + 2 ) * 32 ) ), z, rot[0], rot[1] );
                }

                flyingTickCount = 0;
            }

            pos = new ushort[3] { x, y, z };
            rot = new byte[2] { rotx, roty };
        }
Herocane
 
Posts: 7
Joined: 11 Feb 2011, 02:08

Re: I made an ANTI-FLYING system for you.

Postby Conor » 05 May 2014, 18:23

What happens when they jump from a platform to the floor? The blocks underneath them will be air, this will trigger the mechanism.
Conor (Conanza121)
User avatar
Conor
Coder
 
Posts: 390
Joined: 10 Oct 2012, 21:36
Location: @21Conor

Re: I made an ANTI-FLYING system for you.

Postby Herocane » 05 May 2014, 19:56

It won't- I accounted for that. I only checks if the Y pos is the same or greater than the old Y pos :)
Herocane
 
Posts: 7
Joined: 11 Feb 2011, 02:08


Return to Zombie Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron