Stop screen scrolling with script

I don't know what the solution on LavaLit was, but off the top of my head, you could store the scroll position you want to "save" in a global variable, and use changeopenborvariant("xpos", scrollpos) in update.c to overwrite any attempts by the engine to scroll.

There might be a more elegant way, though.
 
try my lib:

level_lib.c
Code:
#import "data/scripts/lib.c"

#define gpp getplayerproperty
#define cpp changeplayerproperty
#define gep getentityproperty
#define cep changeentityproperty
#define ov  openborvariant
#define cv  changeopenborvariant
#define oc  openborconstant
#define clp changelayerproperty
#define glv getlocalvar
#define slv setlocalvar
#define sev setentityvar
#define gev getentityvar
#define sgv setglobalvar
#define ggv getglobalvar

#define MAX_PLAYERS openborvariant("maxplayers")

void set_min_level_bound(float scroll_pos, float scroll_speed, void localvar_name) {
	// Trova xmin di un player esistente, poi sottrai a xmin hres/2.
	if ( openborvariant("xpos") > scroll_pos ) { if ( getlocalvar(localvar_name) != 1 ) setlocalvar(localvar_name,1); }
	if ( getlocalvar(localvar_name) == 1 && openborvariant("xpos") < scroll_pos && getlevelproperty("scrollspeed") != 0 ) {
		float xmin = NULL();
		int hres = openborvariant("hresolution");
		int i;

		for (i = 0; i < MAX_PLAYERS; ++i) {
			void player = getplayerproperty(i, "entity");

			if ( !getentityproperty(player, "exists") ) continue;
			if ( getentityproperty(player, "x") < xmin || xmin == NULL() ) xmin = getentityproperty(player, "x") ;
		}
		if ( xmin < scroll_pos+(hres/2) ) changelevelproperty("scrollspeed",0);
	} else if ( getlocalvar(localvar_name) == 1 && openborvariant("xpos") <= scroll_pos && getlevelproperty("scrollspeed") != scroll_speed ) {
		float xmax = NULL();
		int hres = openborvariant("hresolution");
		int i;

		for (i = 0; i < MAX_PLAYERS; ++i) {
			void player = getplayerproperty(i, "entity");

			if ( !getentityproperty(player, "exists") ) continue;
			if ( getentityproperty(player, "x") > xmax || xmax == NULL() ) xmax = getentityproperty(player, "x") ;
		}

		if ( xmax >= scroll_pos+(hres/2) ) changelevelproperty("scrollspeed",scroll_speed);
	}
}

void set_max_level_bound(float scroll_pos, float scroll_speed, void localvar_name) {
	// Trova xmin di un player esistente, poi sottrai a xmin hres/2.
	if ( openborvariant("xpos") > scroll_pos ) { if ( getlocalvar(localvar_name) != 1 ) setlocalvar(localvar_name,1); }
	if ( getlocalvar(localvar_name) == 1 && openborvariant("xpos") > scroll_pos && getlevelproperty("scrollspeed") != 0 ) {
		float xmax = NULL();
		int hres = openborvariant("hresolution");
		int i;

		for (i = 0; i < MAX_PLAYERS; ++i) {
			void player = getplayerproperty(i, "entity");

			if ( !getentityproperty(player, "exists") ) continue;
			if ( getentityproperty(player, "x") > xmax || xmax == NULL() ) xmax = getentityproperty(player, "x") ;
		}

		if ( xmax >= scroll_pos+(hres/2) ) changelevelproperty("scrollspeed",0);
	} else if ( getlocalvar(localvar_name) == 1 && openborvariant("xpos") >= scroll_pos && getlevelproperty("scrollspeed") != scroll_speed ) {
		float xmin = NULL();
		int hres = openborvariant("hresolution");
		int i;

		for (i = 0; i < MAX_PLAYERS; ++i) {
			void player = getplayerproperty(i, "entity");

			if ( !getentityproperty(player, "exists") ) continue;
			if ( getentityproperty(player, "x") < xmin || xmin == NULL() ) xmin = getentityproperty(player, "x") ;
		}
		if ( xmin < scroll_pos+(hres/2) ) changelevelproperty("scrollspeed",scroll_speed);
	}
}

then in your level.txt write:
Code:
updatescript @script

#import "data/scripts/level_lib.c"

void main() {
	set_min_level_bound(3000,1,"lv_xpos1"); // 3000 is my xpos position
}
@end_script

in my example after xpos > 3000 you can't go back =)

ps the key for my script is: getlevelproperty("scrollspeed").

However if u want u can change the openbor variant "wait"
 
Thanks!

I actually want to stop screen from scrolling up or down cause by default, nothing stops this.
 
Bloodbane said:
Thanks!

I actually want to stop screen from scrolling up or down cause by default, nothing stops this.

So in your lev.txt write:
cameratype    0 #This sets camera's movement relative to player's movement. Camdaera means screen which shows level we are playing.
direction      right #or both
 
Well, I used script cause first part of level, screen can be scrolled for free by players but after reaching certain wait, scrolling should stop.
The script volcanic posted works right! thanks.

However, the job's not done yet cause I had to code scrolling manually to prevent player from scrolling to wrong part. It was tough work but I've done it :D
 
Back
Top Bottom