PDA

View Full Version : Anti-Blocking Script


HolySheepy
07-16-2007, 11:49 AM
Hi,

so there was this Spar Room, but outside of the Spar the people where annoyed because they were blocked by other people. So i made this script.

Credits

Misconception - for helping me with testing it
kc/KirbyZen - for helping me with testing it
Tortoise - for allowing me to make it public
The people on these forums, that told me to use player.level.name instead of player.level :p


This Script was made for Delteria and was first used there. But you can use it on your server if you want.

If you find any bugs, let me know.

This script was styled with the /style command of the rc, so don't blame me for styling :P

this.includelevels = if you have this.exmode = 1; this is a list of levels where the script will be enabled

this.excludelevels = if you have this.exmode = 0; this is a list of levels where the script will be disabled

this.disabledzones = a list of arrays
format for each array: { level, startx, starty, endx, endy }
if the players x and y are in startx/starty and endx/endy then the script will be disabled


//#CLIENTSIDE
function onCreated() {
this.oldx = -1;
this.oldy = -1;
this.oldkeydown = { 0, 0, 0, 0 };
this.includelevels = { "kaljun_sparcomplexmain.nw" };
this.excludelevels = { };
this.disabledzones = { { "kaljun_sparcomplexmain.nw", 17.5, 17, 43.5, 32 } };
this.exmode = 1;
// Ex Modes:
// 0 - Used in every Level except for those in this.excludelevels
// 1 - Used only in Levels of this.includelevels
setTimer( 0.05 );
}
function onTimeout() {
this.speed = player.shieldpower == 3 ? 0.6 : 0.5;
this.modx = { 0, -this.speed, 0, this.speed };
this.mody = { -this.speed, 0, this.speed, 0 };
this.cmodx = { 0, 0, 0, 2 };
this.cmody = { 0, 0, 2, 0 };
this.mods = { "y", "x", "y", "x" };
if ( checkLevel() == true ) {
if ( checkDisabled() == true) {
setTimer( 0.05 );
return ;
}
for ( i = 0; i < this.modx.size(); i++ ) {
if ( keydown( i ) ) {
if ( this.oldkeydown[ i ] == 0 ) {
this.oldkeydown[ i ] = 1;
} else {
if ( this.(@ "old" @ this.mods[ i ] ) == player.(@ this.mods[ i ] )) {
if ( !onwall3( player.x + 0.5 + this.modx[ i ], player.y + 1 + this.mody[ i ], 2, 2 ) && testplayer2( player.x + 0.5 + this.modx[ i ] + this.cmodx[ i ], player.y + 1 + this.mody[ i ] + this.cmody[ i ] ) != -1 ) {
if ( player.ani != "walk" ) {
if ( player.ani == "grab" || player.ani == "pull" ) {
if ( keydown( 6 ) ) {
setTimer( 0.05 );
return ;
}
}
if ( checkTiletypes( player.x + 0.5 + this.modx[ i ], player.y + 1 + this.mody[ i ], 2, 2, { 3 } ) == true ) {
setani( "sit", "");
}
else if ( checkTiletypes( player.x + 0.5 + this.modx[ i ], player.y + 1 + this.mody[ i ], 2, 2, { 11, 12 } ) == true ) {
setani( "swim", "" );
}
else {
setani( "walk", "" );
}
}
player.x += this.modx[ i ];
player.y += this.mody[ i ];
}
}
}
} else {
if ( this.oldkeydown[ i ] == 1 )
this.oldkeydown[ i ] = 0;
}
}
}
this.oldx = player.x;
this.oldy = player.y;

setTimer( 0.05 );
}

function checkDisabled() {
for ( cz: this.disabledzones ) {
if ( cz[ 0 ] == player.level.name ) {
if ( player.x in | cz[ 1 ], cz[ 3 ] | && player.y in | cz[ 2 ], cz[ 4 ] | )
return true;
}
}
return false;
}

function checkLevel() {
switch ( this.exmode ) {
case 0: {
return ( !( player.level.name in this.excludelevels ) );
}
break;
case 1: {
return ( player.level.name in this.includelevels );
}
break;
}
return false;
}

function onwall3( startx, starty, checkw, checkh ) {
return ( checkTiletypes( startx, starty, checkw, checkh, { 20, 21, 22 } ) );
}

function checkTiletypes( startx, starty, checkw, checkh, tilec ) {
this.foundw = 0;
if ( tiletype( startx, starty ) in tilec ) {
this.foundw = 1;
}
if ( this.foundw == 0 ) {
for ( cx = startx; cx < startx + checkw; cx += 0.1 ) {
for ( cy = starty; cy < starty + checkh; cy += 0.1 ) {
if ( tiletype( cx, cy ) in tilec ) {
this.foundw = 1;
break;
}
}
}
}
return ( this.foundw );
}

function testplayer2( checkx, checky ) {
for ( p: players ) {
if ( player.id != p.id )
if ( checkx in | p.x - 1.5, p.x + 3 | && checky in | p.y - 0.5, p.y + 3 | )
return ( p.id );
}
return ( -1 );
}



p.s.: maybe i will do some optimization and post a updated version