[SOLVED] Script_ Obstacle react differently to different attack types

Glitch

Member
Hi guys, I have began my foray into scripting, I have no experience in programming other then Excel formulas, so even though I have an understanding of the logical steps in variable interaction I am unable as yet to write my own scripts in Openbor. I could really use some help.

I have a drum obstacle that I need to react differently based on the attack type that has hit it.

If it is hit by:

attack1 or attack2: (normal attacks)
fall down and roll a little (depending on direction of attack), remain in floor in a idle2 position being vulnerable to all attacks, all attacks would then make it roll a little more (depending on direction of attack)

attack3 to attack 6: (hard attacks)
get damaged and fall down being damaged (depending on direction of attack), remain on floor in damaged state vulnerable too all attacks, all attacks will not move it in anyway

attack7: (shoot attack)
play explode animation

attack8: (player use/interact animation)
would play an attack animation (0 damage) that would then make player kneel/crouch to hide using drum as cover

I have researched the many different scripts available on the forum, so many that can do so much, however I am unable to understand scripting enough to modify them.

I have tried with some success in regards to Ilu’s obstacle pain and facing script (
[http://www.chronocrash.com/forum/index.php?topic=3973.msg54825#msg54825), which is the base for what I require. However there is the ’’react differently based on the attack type that has hit it’’ problem which I can not solve.

Any help and/or suggestions would be greatly appreciated.

Below are the current drum obstacle text files, and the image files:
 
Drum Text file:

name drumbig
type obstacle

health 1000
gfxshadow 1
noatflash 1
flash bflash
hostile    player enemy
candamage  player npc enemy obstacle

bounce 1
nolife 1
jumpheight 3
nodieblink  2
falldie 1

subject_to_gravity  1

takedamagescript data/scripts/facingpain.c


load dust


anim attack
range 1 200
loop 0
offset 33 132
bbox 11 55 44 78 5
delay 10
counterrange 0 2 1 1
followanim 1
platform 33 135 -45 -45 45 45 16 69
jumpframe 0 2 0 0
frame data/chars/misc/barel
frame data/chars/misc/barel
frame data/chars/misc/barel

anim death
bounce 0
offset 33 132
bbox 7 5 44 71
delay 10
seta 0
bbox 0 0 0 0
throwframe 42 -1
custknife expl
spawnframe 44 0 0 0 0
subentity dust
jumpframe 46 7 1 0
landframe 63
platform 33 135 -45 -45 45 45 16 69
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 9
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 8
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 7
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 6
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 5
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 4
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 3
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 5
sound data/sounds/bdie.wav
frame data/chars/misc/barfire
frame data/chars/misc/barfire1
frame data/chars/misc/barfire2
frame data/chars/misc/barfire3
delay 5
sound data/sounds/bdie.wav
frame data/chars/misc/barbura
frame data/chars/misc/barburb
frame data/chars/misc/barbur
sound data/sounds/drum.wav
frame data/chars/misc/barbur1
delay 3
frame data/chars/misc/barbur2
frame data/chars/misc/barbur3
movea 20
frame data/chars/misc/empty
frame data/chars/misc/empty
frame data/chars/misc/empty
movea 0
delay 10
offset 38 32
summonframe 64 0 0 0 0
subentity dust
attack 16 30 44 14 5 5 0 0 10 5
frame data/chars/misc/barlid
sound data/sounds/swing.wav
frame data/chars/misc/barlid1
frame data/chars/misc/barlid2
sound data/sounds/swing.wav
frame data/chars/misc/barlid3
frame data/chars/misc/barlid4
frame data/chars/misc/barlid5
sound data/sounds/swing.wav
frame data/chars/misc/barlid
frame data/chars/misc/barlid1
sound data/sounds/swing.wav
frame data/chars/misc/barlid2
frame data/chars/misc/barlid3
sound data/sounds/swing.wav
frame data/chars/misc/barlid4
frame data/chars/misc/barlid5
frame data/chars/misc/barlid
sound data/sounds/swing.wav
frame data/chars/misc/barlid1
frame data/chars/misc/barlid2
sound data/sounds/swing.wav
frame data/chars/misc/barlid3
frame data/chars/misc/barlid4
frame data/chars/misc/barlid5
sound data/sounds/tingg.wav
delay 6
seta 0
offset 38 32
frame data/chars/misc/barlid
attack 0 0 0 0 0 0 0 0 0 0
frame data/chars/misc/barlid
frame data/chars/misc/barlid
frame data/chars/misc/barelida
delay 20000
frame data/chars/misc/barelidb

anim fall
loop 0
offset 30 114
bbox 0 0 0 0
delay 15

platform 33 114 -45 -45 45 45 16 48
frame data/chars/misc/barelf
frame data/chars/misc/barelf
delay 30
frame data/chars/misc/barelroll1
frame data/chars/misc/barelroll2
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll4

anim follow1
loop 0
offset 30 114
bbox 7 51 47 63
delay 10
jumpframe` 0 2 -2 0
attack 7 51 47 63 12 1 1 0 12 10
platform 33 114 -45 -45 45 45 16 48
move -10
sound data/sounds/drum.wav
frame data/chars/misc/barelroll1
frame data/chars/misc/barelroll4
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll2
move -8
sound data/sounds/drum.wav
frame data/chars/misc/barelroll1
frame data/chars/misc/barelroll4
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll2
move -5
sound data/sounds/drum.wav
frame data/chars/misc/barelroll1
frame data/chars/misc/barelroll4
move -2
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll2
move 0
delay 1
attack 0 0 0 0 0 0 0 0 0 0
@cmd setidle getlocalvar("self") openborconstant("ANI_IDLE3") 1
frame data/chars/misc/barelroll2

anim follow2
loop 0
offset 30 114
bbox 7 51 47 63
delay 10
jumpframe` 0 2 2 0
attack 7 51 47 63 12 1 1 0 12 10
platform 33 114 -45 -45 45 45 16 48
move 10
sound data/sounds/drum.wav
frame data/chars/misc/barelroll2
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll4
frame data/chars/misc/barelroll1
move 8
sound data/sounds/drum.wav
frame data/chars/misc/barelroll2
frame data/chars/misc/barelroll3
frame data/chars/misc/barelroll4
frame data/chars/misc/barelroll1
move 5
sound data/sounds/drum.wav
frame data/chars/misc/barelroll2
frame data/chars/misc/barelroll3
move 2
frame data/chars/misc/barelroll4
frame data/chars/misc/barelroll1
move 0
delay 1
attack 0 0 0 0 0 0 0 0 0 0
@cmd setidle getlocalvar("self") openborconstant("ANI_IDLE2") 1
frame data/chars/misc/barelroll1

anim grabbed
loop 0
offset 30 114
bbox 7 51 47 63
delay 10
platform 33 114 -45 -45 45 45 16 48

frame data/chars/misc/barelf
frame data/chars/misc/barelf

anim idle
loop 1
offset 33 132
bbox 11 55 44 78 5
delay 5
seta 0
platform 33 135 -45 -45 45 45 16 69
frame data/chars/misc/barel
frame data/chars/misc/barel
frame data/chars/misc/barel
frame data/chars/misc/barel
frame data/chars/misc/barel
frame data/chars/misc/barel

anim idle2
loop 1
offset 30 114
bbox 7 51 47 63
delay 10
platform 33 114 -45 -45 45 45 16 48
frame data/chars/misc/barelroll1

anim idle3
loop 1
offset 30 114
bbox 7 51 47 63
delay 10
platform 33 114 -45 -45 45 45 16 48
frame data/chars/misc/barelroll2

anim land
loop 0
offset 30 114
bbox 0 0 0 0
delay 1
platform 33 114 -45 -45 45 45 16 48
frame data/chars/misc/barelroll3

anim rise
loop 1
offset 30 114
bbox 7 51 47 63
delay 10
platform 33 114 -45 -45 45 45 16 48
frame data/chars/misc/barel1

anim spawn
loop 0
offset 33 132
bbox 11 55 44 78 5
delay 1
seta 0
platform 33 135 -45 -45 45 45 16 69
frame data/chars/misc/barel

#|edited by openBor Stats v 0.67

 
Ilu's Facingpain script, tried to modify it to my needs, I removed a line that checks entity is in idle animation, so that now it will work in all animations. Pretty sure it isn't right:

// Force obstacles to execute a different custom animations when taking hit plus based on which side the hit comes from.
// Douglas Baldan / O Ilusionista - 2018.07.28
// www.brazilmugenteam.com
void actual_main()
{
void self = getlocalvar("self"); // Get the caller
  {
      void opp = getentityproperty(self,"opponent"); // Gets who is attacking it
  int direction = getentityproperty(opp,"direction"); // Gets opponent facing
  if(direction == 1)performattack(self,openborconstant("ANI_FOLLOW1")); //Is entity facing right? 
  if(direction == 0)performattack(self,openborconstant("ANI_FOLLOW2")); //Is entity facing left? 
  }
}


 
Currently it is working as follows:

Any attack makes it fall and roll a little (depending on attacker direction), it then remains on floor allowing it to be attacked by any attack  again and then roll a little (depending on attacker direction).
Should the attack kill it in one hit then it will play death animation (explode)

Just need to get it to react to different attack types differently.

Also there is a glitch?, the drum can only be grabbed in rolled on floor idle position and not on stand up idle position??? When thrown it falls and rolls a little however sometimes after landing it rolls back towards the player (wrong roll direction)

 
Obstacles have default behavior regardless of the attack type. This is both for backwards compatability and memory saving. If you want more dynamic behavior you either have to script it or use a different type of entity for that object.
 
You would need to add a attack type check:

Code:
    int Type = getlocalvar("attacktype");// Get attack type
    if(Type == openborconstant("ATK_NORMAL2")){// if hit by attack2
 *INSERT YOUR LOGIC HERE*
    }
 
Noted well @Damon, I think I will go the script route.

Damon Caskey said:
Obstacles have default behavior regardless of the attack type. This is both for backwards compatability and memory saving. If you want more dynamic behavior you either have to script it or use a different type of entity for that object.

Noted well @Damon, I think I will go the script route.

O Ilusionista said:
You would need to add a attack type check:

Code:
    int Type = getlocalvar("attacktype");// Get attack type
    if(Type == openborconstant("ATK_NORMAL2")){// if hit by attack2
 *INSERT YOUR LOGIC HERE*
    }

Aha! so that is how to get the attack type variable. Thank you Ilu :)  :D
I will insert this in the script and try it out tomorrow
 
Glitch, have you tried changing types trick like this:
Code:
name		Drum
health		100
type		npc
gfxshadow	1
speedf		0
risetime	300
icon		data/chars/misc/drumicon.gif
diesound 	data/sounds/klunk.wav


anim idle
	delay	100
	offset	22 63
	bbox	0 -25 43 92
	platform 1 1 1 1 1 1 1 1
	frame	data/chars/misc/drum.gif

anim	walk
@script
	void self = getlocalvar("self"); //Get calling entity.

	changeentityproperty(self, "velocity", 0, 0);
        setidle(self, openborconstant("ANI_IDLE"));
@end_script
	delay	100
	offset	22 63
	bbox	0 -25 43 92
	platform 1 1 1 1 1 1 1 1
	frame	data/chars/misc/drum.gif

anim spawn
@script
    if(frame==1){
      void self = getlocalvar("self");

      changeentityproperty(self, "type", openborconstant("TYPE_OBSTACLE"));
    }
@end_script
	delay	10
	offset	22 63
	frame	data/chars/misc/drum.gif
	frame	data/chars/misc/drum.gif


anim pain
	delay	20
	offset	22 63
	bbox	0 -25 43 92
	frame	data/chars/misc/drum2.gif

anim fall
	delay	1000
	offset	23 63
	frame	data/chars/misc/drum2.gif

anim death
	delay	20
	offset	22 63
	frame	data/chars/misc/drum2.gif

anim rise
	delay	20
	offset	22 63
	frame	data/chars/misc/drum.gif

This drum is spawned as NPC at first however as soon as it is spawned, its type is changed into obstacle. After the type change, this drum will play PAIN if it's hit by non-knockdown attack
 
Bloodbane said:
Glitch, have you tried changing types trick like this:
Code:
name		Drum
health		100
type		npc
gfxshadow	1
speedf		0
risetime	300
icon		data/chars/misc/drumicon.gif
diesound 	data/sounds/klunk.wav


anim idle
	delay	100
	offset	22 63
	bbox	0 -25 43 92
	platform 1 1 1 1 1 1 1 1
	frame	data/chars/misc/drum.gif

anim	walk
@script
	void self = getlocalvar("self"); //Get calling entity.

	changeentityproperty(self, "velocity", 0, 0);
        setidle(self, openborconstant("ANI_IDLE"));
@end_script
	delay	100
	offset	22 63
	bbox	0 -25 43 92
	platform 1 1 1 1 1 1 1 1
	frame	data/chars/misc/drum.gif

anim spawn
@script
    if(frame==1){
      void self = getlocalvar("self");

      changeentityproperty(self, "type", openborconstant("TYPE_OBSTACLE"));
    }
@end_script
	delay	10
	offset	22 63
	frame	data/chars/misc/drum.gif
	frame	data/chars/misc/drum.gif


anim pain
	delay	20
	offset	22 63
	bbox	0 -25 43 92
	frame	data/chars/misc/drum2.gif

anim fall
	delay	1000
	offset	23 63
	frame	data/chars/misc/drum2.gif

anim death
	delay	20
	offset	22 63
	frame	data/chars/misc/drum2.gif

anim rise
	delay	20
	offset	22 63
	frame	data/chars/misc/drum.gif

This drum is spawned as NPC at first however as soon as it is spawned, its type is changed into obstacle. After the type change, this drum will play PAIN if it's hit by non-knockdown attack

I have read somewhere of this change type via in file script, easier than creating actual script file. Never knew how to do it until now, thank you Bloodbane :)

Some questions though:

I assume that even though enemies will be hostile to NPC, they will not be hostile and wont attack the drum, because in spawn frame it is an NPC for a 1/100th of second delay, is this correct?

Beside attacking it to make it roll and remain for more rolling, will I be able  grab the drum and throw making it play a roll animation and then remain in on floor in another idle to be attacked for more rolling?

Will try it out as well, already have a drum NPC type from a previous try, will add the in file scripts and hopefully it will do all that i require.

Sorry for the questions, I have no experience with script. I hope this type change via script instills all the properties of an NPC in the drum :D
 
It's is working 98% perfectly, thank you guys. I used Bloodbane's suggestion of change type via in file script.

Only one problem is that it cannot be grabbed in normal standing idle, any suggestions as to why? Or how to make it grabbable?

I will share the drum obstacle with different reactions to different attacks here for anyone to use if they interested. It adds more interaction, immersion, and change of gameplay :D
 
O Ilusionista said:
Nice trick, BB. I wasnt aware that some behaviour are inherited when the type changes.

Not just some, quite a few actually. This can get a bit confusing to explain, but I'll do my best.

Part 1.

Internally, OpenBOR sets up a series of flags and logic routines when a model is loaded based on what type it is. In turn those are passed on to entities as they are spawned from the model. In other words, a specific set of behaviors is given to the entity when it first spawns. Most of these routines don't bother to verify the type of entity they belong to. Why would they? It would be a waste of resources 99.99% of the time. And since all changing Type does is alter the Type flag itself, the entity's behavior isn't changed much at all. You'd have to alter a whole crap ton of other stuff too.

That's why you can spawn in an NPC, change it to an Obstacle type, and it will still behave like an NPC .

Part 2.

OK, those same routines I just talked about - that logic does verify the type of other entities. That's how an Enemy type knows to attack Players and ignore other Enemies, just as an example. So while altering the Type flag may not change an entity's own basic behavior, it does change how other entities will behave toward it.

Thus, why changing an NPC to an Obstacle type will cause other entities to treat it like an Obstacle.


Put those two parts together, and that's how/why Bloodbane's trick works.

DC
 
Thanks for the explanation @DC, this trick is amazing. So much can be done with it @Ilu, I noticed it can make the obstacle a moving platform which can actually be controlled with attacks by player, like the controllable movable platform in Mario3 (picture below) or even a soccer ball that can be kicked around differently, even a movable obstacle to block paths/open paths/jump higher etc... :o ;D so many possibilities

edit: makes a funny ''skateboard'' that character stands on/rides, character kicks/pushes on ground (attacks skateboard) to move forward :o just like in real life, the more you kick/push the more you maintain the high speed and not slow down

I am using BB's trick in my game to make movable obstacles to block paths/open paths/jump higher etc and to be used as cover when being shot at or just to rest against lol.

Just one question though guys, why can I not grab the obstacle while it is in idle position, how can I make it grabbable?
 

Attachments

  • 7-6SMAS.png
    7-6SMAS.png
    3.2 KB · Views: 4
Check it your player has candamage obstacle and hostile obstacle.
But the last one can make you grab obstacles even when you don't want to (like in some moves). You can control this using grabforce or even by script.
 
Player has "candamage enemy obstacle npc", hostile was not in header, I added "hostile obstacle"  but still not able to grab entity.
I even removed platform in idle, but still not able to grab, simply passing through entity.

Thanks for suggesting it Ilu, how would I go about forcing grab with script?
 
I think its a side effect of changing the type. About the script, I was talking about to avoid the grab, not forcing it.
If you need a script to interact with obstacles, you can use ONBLOCKOSCRIPT, which triggers when you are blocked by an obstacle.
 
O Ilusionista said:
I think its a side effect of changing the type.

I thought so as well, so I removed the in file scripts. The entity was left as a normal walking NPC entity, still I was not able to grab it, simply passed through. So that means it is not a side effect of the script...hmm...will try to to get the entity able to be grabbed without it having the change types scripts, then upon hopeful success will add scripts back and see what happens.

O Ilusionista said:
About the script, I was talking about to avoid the grab, not forcing it.
If you need a script to interact with obstacles, you can use ONBLOCKOSCRIPT, which triggers when you are blocked by an obstacle.

Will search on forum for the ONBLOCKOSCRIPT, hopefully I will be able to decipher it :-X lol and use it to my needs.
 
Back
Top Bottom