Solved Branch in specific hole

Question that is answered or resolved.

dantedevil

Well-known member
I have a new level with two holes, one close to another.

The idea is this:
- In one hole if you fall, dies normally.
- In the other hole if you fall, you branch to the next level without losing any life.

I try to find a way to make this possible, buut I can't...
 
Solution
That is strange. I can record a video if you want.

Anyway, here is the optmized script. Now you can use it for more than one stage
http://www.chronocrash.com/forum/index.php?topic=3976.0

See the "case" block? Just copy and paste for more options, changing the value.
O Ilusionista said:
Hole has a type parameter:
{type} the type is a param useful for decide what type of terrain is that hole.

You can check for its type when you fall and change the branch.

I understand the idea my friend, but there are things that are not very clear to me.
Here my two holes:
Hole 107 281 31 -11 159 159 45
Hole 307 281 -40 -40 42 90 45    <= This is the branch hole.

Hole has a type parameter:
{type} the type is a param useful for decide what type of terrain is that hole.
About this, i see in the manual the reference of this, but I do not understand what kind of values reference "type".

Code:
hole {xpos} {zpos} {upperleft} {lowerleft} {upperright} {lowerright} {depth} {alt} {type}

    ~A 4-sided invisible hole will be created at the specified point. OpenBoR won't draw a hole or anything there. If you want hole to be visible, use panels or entity.
    ~In Beats of Rage, a hole with default size and special sprite is used. That sprite is hole.gif located in sprites folder. If you want to change the size and visual, you need to set this command AND replace that hole.gif with blank gif.
    ~This is a bit complicated, so listen up! {xpos} and {zpos} are the x and z positions at which the hole is spawned (how far from the start of the stage, and how far from the top of the screen, respectively).
    ~{lowerleft}, {upperleft}, {lowerright}, and {upperright} determine the x position of the four corners of the hole. These numbers are how far from the {xpos} the corners are, not how far from the start of the stage.
    ~{depth} is the z depth of the hole: how far it stretches from the {zpos} to the top of the screen.
    ~{alt} is used to control the height of the hole. (4287+)
    ~{type} the type is a param useful for decide what type of terrain is that hole.
    ~As an example, if you wanted to create a 10x40 parrallelagram ( /_/ ) hole at the bottom of the screen (256) at scroll position 500, you might put
        hole 500 256 0 10 10 20 40
    ~If you create a hole which is not at the bottom of the screen, entities will be visible as they fall off the stage. Probably bad. So place an entity with type none right below the bottom of the hole which resembles the floor. This will cover up almost any entities which fall in the hole.
    ~If used in a stage which scrolls left, the holes will start at the left edge of the starting screen and move right from there. So only holes which would appear in the first 320 or so pixels of the screen will actually be visible, and they'll be at the start of the stage.
    ~The default values are 240, 12, 1, 200, 287, and 45, respectively.
    ~{alt} {type} are optional

I understand that the idea is to differentiate the two goals with the "type", but I do not understand what values are valid in "type".

On the other hand, I know that I must use an "ondeathscript" in the players, to check the hole when they fall on it.
Currently I have a script on the enemies, so that they emit a specific cry when falling in a hole. Dc helped me with it.
I guess it would be useful for me to modify it and create the one I need, but I do not have enough knowledge to do it.

Here the actual ondeathscript of some enemies, courtesy of DC:
Code:
void main()
{
    int sample_id;      // Sound sample ID.
    int attack_type;    // Damaging attack type.
    
    // Get attack type that killed us.
    attack_type = getlocalvar("attacktype");
    
    // Get the pre-loaded sample ID.
    sample_id = getlocalvar(ONDEATH_KEY_SAMPLE_ID);
    
    // If a pit killed us, play the pit sound. "Ahhhhhhhhhhhhh!"...*splat* >:)
    if(attack_type == openborconstant("ATK_PIT"))
    {
      playsample(sample_id, ONDEATH_SOUND_PRIORITY, ONDEATH_SOUND_VOLUME_LEFT, ONDEATH_SOUND_VOLUME_RIGHT, ONDEATH_SOUND_VOLUME_SPEED, ONDEATH_SOUND_LOOP);  
    }
    
    log("\n\n Main.");
    log("\n Attack type: " + attack_type);
    log("\n Sample id: " + sample_id);
} 

// This function runs when a script is first loaded. It's good for initializing things that
// only need to be done one time, like pre-loading a sound or image file.
void oncreate()
{
    int sample_id;
   
    // Load the sound file and establish its ID.
    sample_id = loadsample("data/sounds/m1pain3.wav", 0);
   
    // Store the sound sample for other functions.
    setlocalvar("sndsample_0", sample_id);

    // Put entries in the log for testing.
    log("\n\n Create.");
    log("\n Sample loaded: " + sample_id);
}

// This function runs when a script is unloaded. It's good for cleaning stuff up.
void ondestroy()
{
     log("\n\n Destroyed.");
}

// This is the main function. This is what runs each time the script executes. It is required
// for all scripts except "animation" (because animation inserts a main() automatically). If
// you forget to add it, the engine will shut down and log an error.
void main()
{
     log("\n\n Main.");
}


 
About this, i see in the manual the reference of this, but I do not understand what kind of values reference "type".
For example, you can set the type (as you can do with walls to) 1, other with type 2.
Them, at your logic (probably on a onmoveascript) you check the hole type and change the branch.

And I won't use the ondeathscript because, you know, you are already dead when it runs. It's different from the DC case because that will happens when you die, but in your case, it should happens BEFORE the dead.
Trying to change the branch with a already dead entity can lead to strange behaviours, probably.
 
try setting this as your heroes ondeathscript set the value after x to where your hole starts on the stage and remember to change the "branch" to your branch name with the "".

Code:
void main()
{//msmalik681 custom hole teleport script

void self = getlocalvar("self"); //get self
float x = getentityproperty(self,"x"); //get your current x value

    if(getlocalvar("attacktype") == openborconstant("ATK_PIT") && x=>267) //the x should be where the hole starts
    {
      jumptobranch("branch", 1); //replace branch with name of the branch
    }
}
 
msmalik681 said:
try setting this as your heroes ondeathscript set the value after x to where your hole starts on the stage and remember to change the "branch" to your branch name with the "".

Code:
void main()
{//msmalik681 custom hole teleport script

void self = getlocalvar("self"); //get self
float x = getentityproperty(self,"x"); //get your current x value

    if(getlocalvar("attacktype") == openborconstant("ATK_PIT") && x=>267) //the x should be where the hole starts
    {
      jumptobranch("branch", 1); //replace branch with name of the branch
    }
}

Thanks my friend!

Your method works, but the problem is the hero lose 1 life after fall.
Also with this system we have certain limitations, since I can not use the ondeathscript again to use a branch to a different level.

But it's a start, thank you very much my friend.
 
Also with this system we have certain limitations, since I can not use the ondeathscript again to use a branch to a different level.
Plus, its tied to a specific X position, which ins't too much reliable.

I was taking a look at the source code and looks like the checkhole function doesn't retrieves the TYPE yet, but I remember he had added the wall Type to check wall (althought I can't find it on the source code).

So, maybe you will need to set different ALT for those holes and check for them using "checkhole_between(float x, float z, float a1, float a2);"
 
Dante, maybe we can make a workaround.

Save this as antihole.c and use it as ONMOVEASCRIPT:

Code:
void main()
{ // Performs FOLLOW50 if character falls to hole and reduces 10 HP
// Won't perform if HP is below 10
    void self = getlocalvar("self");
    float x = getentityproperty(self,"x"); //get your current x value
    int y = getentityproperty(self,"y");
    int HP = getentityproperty(self,"health");
    int Vy = getentityproperty(self,"tossv");

    if(Vy < 0 && y < -120 && HP > 10 && x=>267 ){ //the x should be where the hole starts
    jumptobranch("branch", 1); //replace branch with name of the branch
    }
}

Change the "branch" to the one you want and the X to the actual X position of the hole.

It's not the best option. but it will work.

Edit: another option would be to use "checkholeindex" instead of the X pos, so we can target the specific hole.

 
O Ilusionista said:
Dante, maybe we can make a workaround.

Save this as antihole.c and use it as ONMOVEASCRIPT:

Code:
void main()
{ // Performs FOLLOW50 if character falls to hole and reduces 10 HP
// Won't perform if HP is below 10
    void self = getlocalvar("self");
    float x = getentityproperty(self,"x"); //get your current x value
    int y = getentityproperty(self,"y");
    int HP = getentityproperty(self,"health");
    int Vy = getentityproperty(self,"tossv");

    if(Vy < 0 && y < -120 && HP > 10 && x=>267 ){ //the x should be where the hole starts
    jumptobranch("branch", 1); //replace branch with name of the branch
    }
}

Change the "branch" to the one you want and the X to the actual X position of the hole.

It's not the best option. but it will work.

Edit: another option would be to use "checkholeindex" instead of the X pos, so we can target the specific hole.

Thanks my friend, works ok.

First give me this error in the log:
Code:
Script error: data/scripts/antihole.c, line 10: Unknown error '>' (in production 'cond_expr')

    if(Vy < 0 && y < -120 && HP > 10 && x=>307 ){ //the x should be where the hole starts
                                          ^

Then, I change x part to this:  x>=307

And now works ok.


Edit: another option would be to use "checkholeindex" instead of the X pos, so we can target the specific hole.
Maybe that could be the best solution
 
I think you have got a solution but allow me to offer another solution which is to put a platform in other hole to prevent player from falling + a branch entity ontop of that platform for the branching
 
Bloodbane said:
I think you have got a solution but allow me to offer another solution which is to put a platform in other hole to prevent player from falling + a branch entity ontop of that platform for the branching

Hello my friend!

I try this:
Code:
put a platform in other hole to prevent player from falling + a branch entity ontop of that platform for the branching
It does not really look like I want.
So if you can give me the other solution, it would be great.

Thanks my friend!
 
I've tried using inholescript but for some reason it won't work if the hole is clogged with platform inside  ???

Nonetheless, the script works great in normal hole and it could be better solution than using onmoveascript :)
I'm going to try acquiring hole type with this

[some time later]

This doesn't work:

Code:
     int Type = getlocalvar("type");

so what is the correct variable name?
 
White Dragon said:
You can retrieve type value (integer) in 2 ways :
1. By inholescript with localvar
2. Getlevelproperty

INHOLESCRIPT is not documented - I wasn't even aware there is such script. When it was added in the engine?
And for god sake, why this isn't documented?? Sometimes, I feel myself trying to dry ice...

Reading the source code, there is another not documented type of script: THINKSCRIPT

I will try to document it myself.

Here is the list of the script types (remove the "_" from the name to call it):
Code:
    Script         *animation_script;               //system generated script
    Script         *update_script;                  //execute when update_ents
    Script         *think_script;                   //execute when entity thinks.
    Script         *takedamage_script;              //execute when taking damage.
    Script         *ondeath_script;                 //execute when killed in game.
    Script         *onkill_script;                  //execute when removed from play.
    Script         *onpain_script;                  //Execute when put in pain animation.
    Script         *onfall_script;                  //execute when falling.
    Script         *inhole_script;                  //execute when yoy're in a hole
    Script         *onblocks_script;                //execute when blocked by screen.
    Script         *onblockw_script;                //execute when blocked by wall.
    Script         *onblockp_script;                //execute when blocked by platform.
    Script         *onblocko_script;                //execute when blocked by obstacle.
    Script         *onblockz_script;                //execute when blocked by Z.
    Script         *onblocka_script;                //execute when "hit head".
    Script         *onmovex_script;                 //execute when moving along X axis.
    Script         *onmovez_script;                 //execute when moving along Z axis.
    Script         *onmovea_script;                 //execute when moving along A axis.
    Script         *didhit_script;                  //execute when attack hits another.
    Script         *onspawn_script;                 //execute when spawned.
    Script         *key_script;                     //execute when entity's player presses a key
    Script         *didblock_script;                //execute when blocking attack.
    Script         *ondoattack_script;              //execute when attack passes do_attack checks.
    Script         *onmodelcopy_script;				//execute when set_model_ex is done
    Script         *ondraw_script;					//when update_ents is called

so what is the correct variable name?
Yes, here are the variables for INHOLESCRIPT:

"self", "height", "index", "depth", "type"
 
I see this problem still without progress.
For now I use the script for Ilusionista and works ok, but the problem is that I can only use it in a Stage with those coordinates.
So the idea is find a more flexible solution, to use in any level, with the freedom of change the coordinates as you want.
 
Hi Dante. Something had crossed my mind just now.

instead of using
Code:
&& x=>267

we could use
Code:
&&checkhole(1,0,1)

So the code would be:
Code:
void main()
{ // Performs FOLLOW50 if character falls to hole and reduces 10 HP
// Won't perform if HP is below 10
    void self = getlocalvar("self");
    float x = getentityproperty(self,"x"); //get your current x value
    int y = getentityproperty(self,"y");
    int HP = getentityproperty(self,"health");
    int Vy = getentityproperty(self,"tossv");

    if(Vy < 0 && y < -120 && HP > 10 &&checkhole(1,0,1) ){ //check for a hole
    jumptobranch("branch", 1); //replace branch with name of the branch
    }
}

Try and see if it works.
 
Not work my fiend...

For now, only your previous method works perfect, but has the limitation for use only in a specific level.

Here my holes of the stage8-4:
Hole 107 281 31 -11 159 159 45
Hole 267 281 0 0 78 123 45    <= This is the branch hole.

And here your script for use here:
Code:
void main()
{ // Performs FOLLOW50 if character falls to hole and reduces 10 HP
// Won't perform if HP is below 10
    void self = getlocalvar("self");
    float x = getentityproperty(self,"x"); //get your current x value
    int y = getentityproperty(self,"y");
    int HP = getentityproperty(self,"health");
    int Vy = getentityproperty(self,"tossv");

    if(Vy < 0 && y < -120 && HP > 10 && x>=267 ){ //the x should be where the hole starts
    jumptobranch("Stage8-5", 1); //replace branch with name of the branch
    }
}

As you se the script is perfect, but only is usefull fo use in this level.

I thing the concept is the right, but the better idea is convert this script in something you can set the coordinates of the hole and the branch stage.
This exceeds my knowledge and I do not know if it is possible.
 
Back
Top Bottom