[SCRIPT] Ladders/Stairs/Climbing Area/Halcove + Water Puddle (Interact Entities)

White Dragon

New member
Ladders/Climbing Area/Halcove/Stairs/Waves + Water Puddle (Interact Entities)

Maybe this is my more complex script!!

Download and install in your game these my libraries:
lib_interact_ent.zip

add an ondrawscript event to your player entity like:
ondrawscript data/scripts/player_ondrawscript.c

add an ondrawscript event for every enemy you want to interact with these entities like:
ondrawscript data/scripts/enemy_ondrawscript.c

[WATER PUDDLE]
Add a water puddle into your level simply spawning the entity as follows and set its parameters:

Code:
spawn water_puddle_test 1
@script
void main() {
    void self = getlocalvar("self");
    setentityvar(self, "type", "water_puddle"); // name/type
    setentityvar(self, "width", 300); // width
    setentityvar(self, "depth", 80);  // depth
    setentityvar(self, "height", 50); // height
}
@end_script
coords 0 180 0
at 0

For water puddle you can set additional params like:
  • setentityvar(self,"transp",value): 0,1,.., 255 --> from 0 to 255 is the opacity of immersed part of your entity
  • setentityvar(self,"map",value): value is the map that you want. this value impacts on ripple/splash
  • setentityvar(self,"shift_horizontal",value): float value (positive or negative) in pixels to deform horizontally the rectangle in a diagonal shape (parallelogram)
  • setentityvar(self,"shift_vertical",value): float value (positive or negative) in pixels to deform vertically the rectangle in a diagonal shape (parallelogram)
  • setentityvar(self, "no_shadow",value); // show or not the shadows in water puddle)

Attributes for character:
  • setentityvar(self,"subject_to_water_puddle",value): 0,1 --> detect water puddle or not
  • getentityvar(self,"water_puddle"): --> returns entity handler if the character is on water puddle, else returns NULL()

[STAIRS/WAVES]
Add a stair into your level simply spawning the entity as follows and set its parameters:

Code:
spawn stair_empty 1
@script
void main() {
    void self = getlocalvar("self");
    setentityvar(self, "type", "stair_r"); // name/type
    setentityvar(self, "width", 300); // width
    setentityvar(self, "depth", 80);  // depth
    setentityvar(self, "height", 50); // height
}
@end_script
coords 0 180 0
at 0

There are 3 types of stair:
  • stair_r = right part is more high than left part
  • stair_l = left part is more high than right part
  • stair_c = frontal stair
  • stair_q = square stair (like a bridge)

and for waves:
  • wave_r = right part is more high than left part
  • wave_l = left part is more high than right part
  • wave_c = square wave

For stairs you can set additional params like:
  • setentityvar(self,"subject_to_base",value): 0,1 --> the enity cant stay under the stair
  • setentityvar(self,"subject_to_depth",value): 0,1,2 --> USE IT TO BLOCK THE ENTITY. 0 means that you can walk in depth. 2 is for blockade totally in the middle and 1 to block only when the player is stopped. ### I like subject_to_depth to 1 ###
  • setentityvar(self,"subject_to_edges",value): 0,1 --> blockade on edges

Attributes for character:
  • setentityvar(self,"subject_to_stair",value): 0,1 --> detect stair or not
  • getentityvar(self,"is_on_stair"): returns entity handler if the character is on stair, else returns NULL()

For waves you can set additional params like:
  • setentityvar(self,"adjust_wave_base_value",value): threshold (float value) --> an additional threshold to detect wave

Attributes for character:
  • setentityvar(self,"subject_to_wave",value): 0,1 --> detect wave or not
  • getentityvar(self,"is_on_wave"): returns entity handler if the character is on wave, else returns NULL()

For wave you can change the T_WALKOFF variable into .c file.
This is a defined variable that change the minimum distance detection between the character and the wave.
Default value to 4.

Last but not least you must to use a custom shadow when you use a stair. So in your level insert:
Code:
updatescript @script
#import "data/scripts/lib_level.c"

void main() {
	int i = 0;

	for( i = 0; i <= openborvariant("count_entities"); ++i) {
        	void ent = getentity(i);

		check_shadow(ent,180,-5,0,256,50,220,0,0,1);
	}
}
@end_script

[LADDERS/CLIMBING AREA/HALCOVE]
This is more complex.
My library add an AI while the enemy climb a ladder or search a ladder.

You need to write your animations. For my agreement I list animations:
  • FOLLOW50 # (FRONT CLIMBING)
  • FOLLOW51 # (SIDE CLIMBING LEFT)
  • FOLLOW52 # (SIDE CLIMBING RIGHT)
  • FOLLOW53 # (FRONT CLIMBING OVER) -> to climb on a ledge
  • FOLLOW54 # (SIDE CLIMBING OVER) -> to climb on a ledge
  • FOLLOW55 # (FRONT CLIMBING OVER REVERSE) -> to move from one ledge to ladder
  • FOLLOW56 # (SIDE CLIMBING OVER REVERSE) -> to move from one ledge to ladder
  • FOLLOW57 # (FRONT CLIMBING AREA)
  • FOLLOW58 # (SIDE CLIMBING AREA)
  • FOLLOW59 # (FRONT CLIMBING AREA OVER REVERSE) -> to move from one ledge to climbing area
  • FOLLOW120 # (LADDER H CLIMB)
  • FOLLOW121 # (LADDER H GRAB)

To simulate a climbing animation add an animation script like:
Code:
anim	FOLLOW50 # (FRONT CLIMBING)
	loop 	1

	@script
		void self = getlocalvar("self");
		int p = getentityproperty(self, "playerindex");
		int frm = 0, tot_frm = 8;
		int press_btn = 0;

		if ( !playerkeys(p,press_btn,"moveup") && !playerkeys(p,press_btn,"movedown") ) {
			if ( getglobalvar("p"+p+"climbing") != NULL() ) changeentityproperty(self, "animpos", getglobalvar("p"+p+"climbing"));
			else {
				setglobalvar("p"+p+"climbing", 0);
				changeentityproperty(self, "animpos", getglobalvar("p"+p+"climbing"));
			}
		} else if ( getglobalvar("p"+p+"climbing") != NULL() )  {
			frm = getglobalvar("p"+p+"climbing")+1;
			if ( frm >= tot_frm ) frm = 0;
			setglobalvar("p"+p+"climbing", frm);
			changeentityproperty(self, "animpos", getglobalvar("p"+p+"climbing"));
		} else if ( getglobalvar("p"+p+"climbing") == NULL() ) {
			setglobalvar("p"+p+"climbing", 0);
			changeentityproperty(self, "animpos", getglobalvar("p"+p+"climbing"));
		}
	@end_script

	delay	8
	offset  24  63
	bbox  9  5  31  47
	frame	data/chars/don/climb3.gif
	frame	data/chars/don/climb1.gif
	frame	data/chars/don/climb0.gif
	frame	data/chars/don/climb1.gif
	frame	data/chars/don/climb3.gif
	frame	data/chars/don/climb1a.gif
	frame	data/chars/don/climb0a.gif
	frame	data/chars/don/climb1a.gif

There are 4 types of ladder:
  • ladder_r = right ladder
  • ladder_l = left ladder
  • ladder_v = vertical ladder
  • ladder_h = horizontal ladder

So you can spawn a ladder in this way:
Code:
spawn ladder_name 1
@script
void main() {
    void self = getlocalvar("self");
    setentityvar(self, "type", "ladder_v"); // name/type
    setentityvar(self, "width", 300); // width
    setentityvar(self, "height", 50); // height
}
@end_script
coords 0 180 0
at 0

Attributes for character for ladder/climbable area/halcove:
  • getentityvar(self,"ladder"): returns entity handler if the character is on ladder/climbable area/halcove, else returns NULL()

The similar todo list is for halcove.
The animations are:
  • FOLLOW46 # (HALCOVE TURN LEFT)
  • FOLLOW47 # (HALCOVE TURN RIGHT)
  • FOLLOW48 # (HALCOVE CLIMBING)
  • FOLLOW49 # (HALCOVE SLIDING DOWN)

and the halcove name is just: setentityvar(self, "type", "halcove");

I know that isn't too easy to add a ladder...

[attachment deleted by admin]
 
Congratulations my friend!

No doubt is your more complex script.

Need time to study and undesrstand exactly how use it, but is really great your work.

Thanks for share!
 
Okay so I tested out the scripts in my game, but for some reason, I got this compile error:

Code:
Script compile error: can't find function 'get_main_opp'

Script compile error in 'data/scripts/ladder.c': get_main_opp line 415, column 86
Script error: failed to import 'data/scripts/ladder.c': failed to compile
Script error: failed to import 'data/scripts/player_check_entities.c': failed to compile

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'ondrawscript' data/chars/Playable/Neptune/Neptune.txt
Total Ram: 2147483647 Bytes
 Free Ram: 1869918208 Bytes
 Used Ram: 41197568 Bytes

Release level data...........	Done!
Release graphics data........	Done!
Release game data............


Release game data............	Done!
Release timer................	Done!
Release input hardware.......	Done!
Release sound system.........	Done!
Release FileCaching System...	Done!

**************** Done *****************

Can't compile script 'ondrawscript' data/chars/Playable/Neptune/Neptune.txt

Am I doing something wrong?
 
question one way to begin to climb without using the special button , eg moving up and down movement thanks
 
monomartin said:
question one way to begin to climb without using the special button , eg moving up and down movement thanks

Sure!! see ladder_commons and search get_ladder_btn();
That function retrieves the special button (you can change it from defines)
Or you can edit the rows in ladder.c that call get_ladder_btn(); in your buttons
Better if you add your playerkeys func with  DOWN or UP
 
I understand the defining part , but I do not understand this part if ( playerkeys ( p , 1, get_ladder_btn () ) must be so ? ( playerkeys ( p , 1, get_ladder_btn ( " moveUp " ) )
 
Ok, forget my previous posts.
I updated the script (re-download it).

To add in easy way the possibility to use UP/DOWN buttons to grab a ladder simply:
1) open ladder_commons.c
2) see 3 func: is_action_btn_pressed_ladder_by_down(), is_action_btn_pressed_ladder_by_up(), is_action_btn_pressed_ladder_by_air()
these funcs retrieve a value 1 or 0 (true or false) if you pressed the right button to climb the ladder.
is_action_btn_pressed_ladder_by_down() is to grab the ladder from base (example this func has to retrieve TRUE if you press UP).
is_action_btn_pressed_ladder_by_up() is to grab the ladder from top (modify it to retrieve TRUE if you press DOWN)
is_action_btn_pressed_ladder_by_air() is to grab the ladder while you are in air (modify it to retrieve TRUE if you press DOWN or UP (all buttons))

so change them!!

Example:
Code:
int is_action_btn_pressed_ladder_by_down(int p_index) {
    return playerkeys(p_index,1,"moveup");
}

int is_action_btn_pressed_ladder_by_up(int p_index) {
    return playerkeys(p_index,1,"movedown");
}

int is_action_btn_pressed_ladder_by_air(int p_index) {  
   if ( playerkeys(p_index,1,"moveup") || playerkeys(p_index,1,"movedown") ) {
         return 1;
   }

   return 0;
}
 
I now understand , works perfect , thank you very much for your time and support. soon will see my work completed
 
Got another compile error after downloading the update:

Code:
Script compile error: can't find function 'get_bindtype'

Script compile error in 'data/scripts/player_check_entities.c': get_bindtype line 126, column 25
Script error: failed to import 'data/scripts/player_check_entities.c': failed to compile

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'ondrawscript' data/chars/Playable/Neptune/Neptune.txt
Total Ram: 2147483647 Bytes
 Free Ram: 1753063424 Bytes
 Used Ram: 46133248 Bytes

Release level data...........	Done!
Release graphics data........	Done!
Release game data............


Release game data............	Done!
Release timer................	Done!
Release input hardware.......	Done!
Release sound system.........	Done!
Release FileCaching System...	Done!

**************** Done *****************

Can't compile script 'ondrawscript' data/chars/Playable/Neptune/Neptune.txt
 
I've experienced a bug when testing out the water puddles. When one of the characters get in the water and then back out, they end up disappearing.

Neptune in the water:
Gamindustri%2BRiot%2B-%2B0011.png


Neptune out of the water:
Gamindustri%2BRiot%2B-%2B0012.png
 
There isn't a bug like this on the water puddle.
Maybe there is something wrong on the inclusion of the script in your game.
Exactly what did you do?
 
Added another Script Update:

added additional params for water puddle:
  • setentityvar(self,"shift_horizontal"): float value (positive or negative) in pixels to deform horizontally the rectangle in a diagonal shape (parallelogram)
  • setentityvar(self,"shift_vertical"): float value (positive or negative) in pixels to deform vertically the rectangle in a diagonal shape (parallelogram)

Example of shifting:
index.php


The shift is a method to avoid the regular rectangle shape and to be more accordant to level visual.

IMPORTANT: Now the origin is the corner UP/LEFT (like in picture that the origin is the point A)
 
Does the "get_bindtype" function even exist? I searched through the scripts and found nothing.
Script compile error: can't find function 'get_bindtype'

Script compile error in 'data/scripts/player_check_entities.c': get_bindtype line 149, column 25
Script error: failed to import 'data/scripts/player_check_entities.c': failed to compile

********** An Error Occurred **********
*            Shutting Down            *

Can't compile script 'ondrawscript' data/chars/Playable/Neptune/Neptune.txt
 
White Dragon said:
There isn't a bug like this on the water puddle.
Maybe there is something wrong on the inclusion of the script in your game.
Exactly what did you do?
All I did was add the ondrawscript to my characters. nothing was changed.
 
Back
Top Bottom