Simple scripts to share

Bloodbane

Well-known member
These are simple animation scripts usually used by enemies. It should be pasted on an animation header.

1. Desperation
Code:
@script	
    if(frame==0){
      void vSelf = getlocalvar("self");
      int MHealth = getentityproperty(vSelf,"maxhealth");
      int Health = getentityproperty(vSelf,"health");

      if(Health <= MHealth/3){
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FOLLOW1"));
      }
    }
@end_script

This animation script changes enemy's animation to FOLLOW1 if his/her/its HP fall below 1/3 of it's maximum HP.
Also useful for players too ;)
In detail, it works like this: at 1st frame of animation, entity's HP is compared with maximum HP. If it is 1/3 of maximum HP or less, animation is changed to FOLLOW1.

2. Randomness
Code:
@script	
    if(frame==0){
      void vSelf = getlocalvar("self");
      int r = rand()%30;

      if(r > 0){
        changeentityproperty(vSelf, "animation", openborconstant("ANI_FOLLOW1"));
      }
    }
@end_script

As name implies, it changes enemy's current animation to FOLLOW1 randomly with about 50% chance to change.
Players could use this too for attacks or spells which has low success rate ;).
It works like this: at 1st frame, an integer value between -30 and 30 is picked randomly. If it is higher than 0, animation is changed to FOLLOW1. If it is lower or same as 0, nothing will be done and the rest of animation will be played normally

3. Lonely
Code:
@script
    void self = getlocalvar("self");
    int Enemy = openborvariant("count_enemies");

    if(Enemy == 1){
      changeentityproperty(self, "velocity", 0, 0, 0); // Should be omitted if declared in IDLE
      performattack(self, openborconstant("ANI_FOLLOW1"));
    }
@end_script

Okay, this one has catchy name :) actually, this is used to change animation to summon backups animation which is usually performed when boss is alone. Summon backups animation could be anything from calling backups from offscreen to raising zombies from ground ;).
I usually declare this in boss's IDLE and WALK animation but it works in other animation as well.
The script works like this: in every frame of animation, number of enemies is counted. If it is higher than 1, nothing will happen and the animation will be played normally. But if it is 1, animation is changed to FOLLOW1.
Bear in mind that the enemy using this script is also counted

Values used in scripts above aren't fixed of course, you can change it for different randomness, different HP limit (for desperation) or for different loneliness.
 
Thanks, Bloodbane!

I would like to share something too. I used this script to do an attack like  the special attack of Mack the Knife (from Captain Commando). So you can move your character while he is performing his animation.

03481509077342708abfcd9.png



(It should be pasted on an animation header)
Code:
@script

	void self       = getlocalvar("self");
	int pindex 	= getentityproperty(self,"playerindex");
	void moveright 	=  playerkeys(pindex, 0, "moveright");
	void moveleft 	=  playerkeys(pindex, 0, "moveleft");
	void moveup 	=  playerkeys(pindex, 0, "moveup");
	void movedown 	=  playerkeys(pindex, 0, "movedown");

	changeentityproperty(self, "velocity", 0,0,0);

	if (moveright)
	{
	changeentityproperty(self, "velocity", 0.5,NULL(),NULL());
	}
	 if (moveleft)
	{
	changeentityproperty(self, "velocity", -0.5,NULL(),NULL());
	}

	 if (moveup)
	{
	changeentityproperty(self, "velocity", NULL(),-0.5,NULL());
	}

	 if (movedown)
	{
	changeentityproperty(self, "velocity", NULL(),0.5,NULL());
	}
	@end_script
 
Very good initiative to share simple but useful scripts to give more custom features to the generic openbor mod!

And thanks so much for explaining it with example, since this is the only way most of us can understand it.
This is great!
 
Thanks to allowance to paste scripts in level texts, there are more effects we could make and it reduces number of entities which was used for this before.

In Lavalit forum I shared a trick to change where players would start in a level using entities. This trick useful for placing players ontop of platform or walls at beginning of a level.
That thread is gone but no worries, that trick is obsolete anyways. Script in level is sufficient, here's an example:

spawn empty
@script
void main()
{
    int P1 = getplayerproperty(0, "entity");
    int P2 = getplayerproperty(1, "entity");

    if(P1){
      changeentityproperty(P1, "position", 30,355, 226);
      changeentityproperty(P1, "direction", 1); //Face right
    }
    if(P2){
      changeentityproperty(P2, "position", 30, 375, 226);
      changeentityproperty(P2, "direction", 1); //Face right
    }
}
@end_script
coords 430 430
at 0

This script puts player 1 at 30 pixels from left edge, at z = 355 and 226 pixels above ground. Player 2 is 20 pixels in front (z axis) of Player 1.
I used this script to put player on top of wall at start of level with walls.

You can change the values for your purpose. Here's the order of parameters:

P1, "position",x, z, y

This script can be expanded for 3 or 4 players.
You can paste this script in any entity but make sure it is spawned/accessed at 0 to ensure it is run when level starts.

[EDIT]

I added facing control to script above. It changes respective player's facing direction.
It is useful if you want players to face different directions, e.g P1 faces right while P2 faces left (VS mode)

I should mention it too that this script doesn't change where players are respawned
 
This is what i call "scripts made easy" !

Keep this up!  ;)
 
I'm listing these in 'Helpful Links' thread, under the 'Script Index' section. 
http://www.chronocrash.com/forum/index.php?topic=13.msg57#msg57

It also links various posts in other threads that contain scripts and examples, where Bloodbane or others have given script solutions.
 
Feel free to post links to anything good you see in other threads.

 
There's another useful script I usually use, it is spawnscript which spawns entity at defined coordinates ignoring current scroll position.

Since I can attach anything here, I just post the whole script here:

Code:
// Removes scroll pos effect allowing entities to be spawned exactly at defined x coordinate
void main()
{
    void self = getlocalvar("self"); //Get calling entity.
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int XPos = openborvariant("xpos");

    changeentityproperty(self, "position", x - XPos);
}

Save this as noscpos.c
Example of usage is:

spawn DoorG
spawnscript data/scripts/noscpos.c
flip 1
coords 1000 400
at 0

There's a script tag version for this, here:

spawn DoorG
@script
void main()
{
    void self = getlocalvar("self");
    int x = getentityproperty(self,"x"); //Get character's x coordinate
    int XPos = openborvariant("xpos");

    changeentityproperty(self, "position", x - XPos);
}
@end_script
flip 1
coords 1000 400
at 0

Works same as spawnscript version. Good thing about the 2nd version is that it allows you to insert more script.

This script is useful in direction both level in which you want to spawn entity in exact spot regardless of current scroll position such as door animation.
 
O Ilusionista said:
This should be combined with a offscreenkill, right?

No, it's not necessary to add that command.
But noone can forbid you from using this script to spawn decorations at exact spot :)
 
Another script to share, I call this: Projectile reaction.

Default knife usually disappears after hitting something. Now what if the knife is rocket and it should show explosion animation instead of disappearing? here's a script and example on how to make such effect:
name AcidShot
type none
candamage enemy obstacle
speed 25
remove 0


anim idle
loop 1
delay 4
followanim 1
followcond 1
fastattack 1
offset  22 12
hitfx data/sounds/burnt.wav
attack2 35 3 24 18 12 1 0 0 30
DOT 1 300 4 2 20
frame data/chars/misc/magic/acid1.png
frame data/chars/misc/magic/acid2.png
frame data/chars/misc/magic/acid3.png
frame data/chars/misc/magic/acid4.png
frame data/chars/misc/magic/acid5.png

anim follow1
@script
    void self = getlocalvar("self");

    if(frame == 0){
      changeentityproperty(self, "velocity", 0, 0, 0);
      changeentityproperty(self, "speed", 0);
    }
    if(frame == 6){
      killentity(self);
    }
@end_script
delay 6
offset  32 50
frame data/chars/misc/magic/acidB1.png
frame data/chars/misc/magic/acidB2.png
frame data/chars/misc/magic/acidB3.png
frame data/chars/misc/magic/acidB4.png
frame data/chars/misc/magic/acidB5.png
frame data/chars/misc/magic/acidB6.png
frame data/chars/misc/empty.gif

Setting remove 0 is essential to ensure knife, acidshot in this case doesn't disappear after hitting something.

In IDLE, followanim and followcond are set so when acidshot hits, it changes to FOLLOW1 animation, which is the acidhit animation.

In FOLLOW1, a script is run. At 1st frame, its velocity in all directions are dropped to 0 and its speed is dropped too IOW acidshot is stopped. At last frame, it removes itself.
 
This is just simple script to forcefully apply alias to an entity:
Code:
anim spawn
@script
    if(frame == 1){
      void self = getlocalvar("self");
      changeentityproperty(self, "name", "Rider");
    }
@end_script
...

This is useful if the entity is summoned by other entity and we don't want them to use their original name.
 
lagarto said:
Thanks, Bloodbane!

I would like to share something too. I used this script to do an attack like  the special attack of Mack the Knife (from Captain Commando). So you can move your character while he is performing his animation.

03481509077342708abfcd9.png



(It should be pasted on an animation header)
Code:
@script

	void self       = getlocalvar("self");
	int pindex 	= getentityproperty(self,"playerindex");
	void moveright 	=  playerkeys(pindex, 0, "moveright");
	void moveleft 	=  playerkeys(pindex, 0, "moveleft");
	void moveup 	=  playerkeys(pindex, 0, "moveup");
	void movedown 	=  playerkeys(pindex, 0, "movedown");

	changeentityproperty(self, "velocity", 0,0,0);

	if (moveright)
	{
	changeentityproperty(self, "velocity", 0.5,NULL(),NULL());
	}
	 if (moveleft)
	{
	changeentityproperty(self, "velocity", -0.5,NULL(),NULL());
	}

	 if (moveup)
	{
	changeentityproperty(self, "velocity", NULL(),-0.5,NULL());
	}

	 if (movedown)
	{
	changeentityproperty(self, "velocity", NULL(),0.5,NULL());
	}
	@end_script

I am really lovin' this movement script! Thanks for sharing! ;D Although, I was wondering if it was possible to make it so the movement is only allowed from one frame to another certain frame.
 
Liu-Kang said:
I am really lovin' this movement script! Thanks for sharing! ;D Although, I was wondering if it was possible to make it so the movement is only allowed from one frame to another certain frame.

Sure.  Let's say you want to allow movement from frame 3 to frame 10 . IOW , before frame 3 and after frame 10, the entity will  have velocity 0 0 0 (full stop).

This is the code for that:
Code:
@script

	void self       = getlocalvar("self");
	int pindex 	= getentityproperty(self,"playerindex");
	void moveright 	=  playerkeys(pindex, 0, "moveright");
	void moveleft 	=  playerkeys(pindex, 0, "moveleft");
	void moveup 	=  playerkeys(pindex, 0, "moveup");
	void movedown 	=  playerkeys(pindex, 0, "movedown");

	changeentityproperty(self, "velocity", 0,0,0);
   if(frame>=3 && frame <=10)
    {
	if (moveright)
	{
	changeentityproperty(self, "velocity", 0.5,NULL(),NULL());
	}
	 if (moveleft)
	{
	changeentityproperty(self, "velocity", -0.5,NULL(),NULL());
	}

	 if (moveup)
	{
	changeentityproperty(self, "velocity", NULL(),-0.5,NULL());
	}

	 if (movedown)
	{
	changeentityproperty(self, "velocity", NULL(),0.5,NULL());
	}
   }
	@end_script	
 

One more thing, don't forget: the first frame is frame 0 (not frame 1).
 
Back
Top Bottom