Following Script Points AND Shooting Enemies

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Following Script Points AND Shooting Enemies

Post by metal_head » Fri Jul 03, 2009 11:37 am

Hey, I was thinking if it's possible to make perfectai.s follow follow script points, than when an enemy is in the range, shoot it and proceed...actually this is already done, the thing that's not done is having multiple commands in the Patrol order, rather than only NextPoint(); RotateMoveToPoint(); MoveToPoint and RestartOrder();
This is the Patrol order I modified:

Code: Select all

Patrol[ ()
{
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Idle", 3, "Grunt/3.wav");
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
SetEventState("razpad", true);
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
MoveToPoint("SG_Walk_N_Run", 200, "");
NewOrder("PatrolCheck1");
} ]

PatrolCheck1[ ()
{
PlayerDistOrder(150, "Patrol1");
LoopAnimation(STAND, 0, "");
} ]

Patrol1[ ()
{
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Walk_N_Stop", 0.85, "");
NewOrder("PatrolCheck2");
} ]

PatrolCheck2[ ()
{
PlayerDistOrder(150, "Patrol2");
LoopAnimation(STAND, 0, "");

} ]

Patrol2[ ()
{
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Walk_N_Stop", 0.85, "");
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N", 90, "");
Delay("SG_Holster", 1.65, "");
Delay("Push_Button_Low", 1.7, "");
SetEventState("gen1dtrig", true);
LowLevel("CheckIfOk");
} ]

CheckIfOk[ ()
{
if (GetEventState("gen14ever"))
{
HighLevel("PatrolCheck3");
}
} ]

PatrolCheck3[ ()
{
PlayerDistOrder(200, "Patrol3");
} ]

Patrol3[ ()
{
Delay("SG_Draw", 1, "");
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Walk_N_Stop", 0.85, "");
Delay("SG_Radio_Call", 5.18, "");
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Holster", 1.65, "");
Delay("SG_Reload", 2.33, "");
SetEventState("bombspawn", true);
NextPoint();
RotateToPoint("SG_TurnLeft", 210, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
NextPoint();
SetNoCollision();
MoveToPoint("SG_Roll_N", 150, "");
SetCollision();
Delay("SG_Idle", 1, "");
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
Delay("SG_Walk_N_Stop", 0.85, "");
Delay("SG_Idle", 0.85, "");
LowLevel("CheckIfOk2");
} ]

CheckIfOk2[ ()
{
if (GetEventState("gen24ever"))
{
HighLevel("PatrolCheck4");
}
} ]

PatrolCheck4[ ()
{
PlayerDistOrder(200, "Patrol5");
} ]

Patrol5[ ()
{
NextPoint();
RotateToPoint("SG_TurnLeft", 190, false, "" );
MoveToPoint("SG_Walk_N_Run", 200, "");
NextPoint();
RotateMoveToPoint("SG_Walk_N_Run", 130, 150, false, "");
SetEventState("wayblock", true);
MoveToPoint("SG_Walk_N_Run", 200, "");
} ]
}
It's not only one order though, there are several, if the script goest to attack mode, it will forget which is the current order being executed...ok, I can fix this by simply creating a variable, which in every order gets the name of the order. Yeah, but if before the monster has seen an enemy it has reached he SetEventState(); command of the Patrol5 order, when the monster shoots the enemy it will go back to Patrol5 (using the variable and NewOrder();), but it will get back to the begining, which means that it will execute everything again. HALO has that cool thing, the troopers talk to you, then they say follow me, and than the trooper starts following some path, shooting every enemy arround him, he even talks, moving his mouth while walking (but that's not important). I need this, because I'm planing to use this on many places in the game, after all everyone in Metal Force help each other :D . For example, in the 4-th part of the first level you meet up with your pals (Jenity and Bolt) and than you gotta find a shuttle and evacuate, but for this you'll all need to go through the level together, my plan was for them to run infront of you, than stop at some places, checking if you're near enough and than proceed if you are, also they shoot enemies on their way so they don't die when they pass :D

Any suggestions for this guys?

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Following Script Points AND Shooting Enemies

Post by Juutis » Fri Jul 03, 2009 12:17 pm

Off the top of my head, splitting the orders even further would be the only option if you want to keep the patrol stuff in high level. Split them so that each contain only one NextPoint() command and the commands that will get the pawn to the next scriptpoint.

Another approach would be to get rid of the high level parts and make the script run fully in low level. That's what I'm doing with my AI scripts. Low level is much more versatile and it lets you do all kinds of cool things. The NPC's could, for example, shoot the enemies and run towards the scriptpoint instead of staying and fighting the enemy. That would be great in a situation where the NPC's are retreating and you don't want them to kill every single enemy they see. Also, the script would probably be shorter if you made it low level. If done carefully, a handful of orders would be enough to do the whole thing.

Of course, going fully low level is a lot harder and needs some serious thinking but I'm sure it would pay off eventually.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Following Script Points AND Shooting Enemies

Post by metal_head » Fri Jul 03, 2009 8:03 pm

Woo, so I'm going for the big fish (low level)!
Amm, I got some question then:
About the scriptpoints - there's no NextPoint or MoveToPoint order in low level, so I guess that I'll have to find the location or something of the script point, than move it somehow to the script point... but how can I do this, I mean can you help me with this one?

The NPC's could, for example, shoot the enemies and run towards the scriptpoint instead of staying and fighting the enemy. That would be great in a situation where the NPC's are retreating and you don't want them to kill every single enemy they see.

Hmm, I didn't quite get what you mean by this one (I'm still using perfectai.s btw). You mean like they follow the path and just shoot the enemies in rage while walking and never stopping to shoot them? That would be cool (I gotta place where I could use such thing).

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Following Script Points AND Shooting Enemies

Post by Juutis » Fri Jul 03, 2009 10:30 pm

metal_head wrote:Woo, so I'm going for the big fish (low level)!
Amm, I got some question then:
About the scriptpoints - there's no NextPoint or MoveToPoint order in low level, so I guess that I'll have to find the location or something of the script point, than move it somehow to the script point... but how can I do this, I mean can you help me with this one?
NextPoint() actually does exist in low level too.

For the other stuff you could use

Code: Select all

walkmove(GetYawToPoint(),SPEED);
or

Code: Select all

self.ideal_yaw = GetYawToPoint();
ChangeYaw();

walkmove(self.current_yaw,SPEED);
The former will move the pawn towards the scriptpoint no matter where the pawn is facing. The latter will rotate the pawn towards the scriptpoint while moving the pawn forward (where the pawn is facing).

You'll also have to check manually if the pawn has reached the scriptpoint:

Code: Select all

if(FastPointCheck(DISTANCE))
{
     NextPoint();
}
This will check if the current scriptpoint is within DISTANCE texels and if so, change the scriptpoint.

metal_head wrote:Hmm, I didn't quite get what you mean by this one (I'm still using perfectai.s btw). You mean like they follow the path and just shoot the enemies in rage while walking and never stopping to shoot them? That would be cool (I gotta place where I could use such thing).
Yes, exactly. :)
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Following Script Points AND Shooting Enemies

Post by metal_head » Sat Jul 04, 2009 10:58 am

Thanks!
This will check if the current scriptpoint is within DISTANCE texels and if so, change the scriptpoint.
And what value should best be there, I mean it's not a problem if I put 0, the pawn would be able to get in 0 texels of the point,right :lol: ?

So I checked all the commands you gave for example and it got pretty clear to me, I'm gonna try to create an example for myself, can you tell me if it's OK? :D

Code: Select all

Someorder[ ()
{
self.ThinkTime = 0.0;
UpdateEnemyVis(true); 			
UpdateTarget();
NextPoint();
self.ideal_yaw = GetYawToPoint();
ChangeYaw();
walkmove(self.current_yaw,SPEED);
if(enemy_vis = true)
{
self.think = "SomeorderShoot"; 
}
if(FastPointCheck(0))
{
     NextPoint();
}
} ]
SomeorderShoot[ ()
{
And the shooting order here (sorry, not very familiar with the hostility, shooting and such)
} ]
I got inspired from your idea with the walking, shooting and not stopping, but for that the pawn will need to rotate it's upper body part while playing the animation for walking...yeah..about that :lol: how would such thing be possible, I once saw some demo, made by someone for a mouse controled player, the player was turning his head to whereve the mouse pointed, but I don't have that demo and I can't see, I'll take a look at the manual, but I don't believe I'll find what I need :D

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Following Script Points AND Shooting Enemies

Post by Juutis » Sat Jul 04, 2009 10:43 pm

metal_head wrote:And what value should best be there, I mean it's not a problem if I put 0, the pawn would be able to get in 0 texels of the point,right :lol: ?
If I read the source code correctly, the method FastPointCheck(0) will always return false. Even if the pawn is right there in the exact same spot.

The value you should use depends on the scale of your game. My characters are about 100 texels high and I'm using a distance of 64 in my scripts. The smaller the value the more precise the pawns are. If you have lots of tight turns and narrow places I recommend using a very low value.
Someorder[ ()
{
self.ThinkTime = 0.0;
UpdateEnemyVis(true);
UpdateTarget();
NextPoint();
self.ideal_yaw = GetYawToPoint();
ChangeYaw();
walkmove(self.current_yaw,SPEED);
if(enemy_vis = true)
{
self.think = "SomeorderShoot";
}
if(FastPointCheck(0))
{
NextPoint();
}
} ]
This will mess the script up pretty badly. If you put it like that it will get the next point each frame no matter where the pawn is, cycling through the whole path in the blink of an eye.
metal_head wrote:I got inspired from your idea with the walking, shooting and not stopping, but for that the pawn will need to rotate it's upper body part while playing the animation for walking...yeah..about that :lol: how would such thing be possible, I once saw some demo, made by someone for a mouse controled player, the player was turning his head to whereve the mouse pointed, but I don't have that demo and I can't see, I'll take a look at the manual, but I don't believe I'll find what I need :D
Not possible with RF. RF can only play one animation per actor at a time, so you'd need two actors (the legs and the upper body) or a motherload of different animations where the upper body points at slightly different angles.


Also, in the original script you posted you have a lot of special animations. Like:

Code: Select all

Delay("SG_Walk_N_Stop", 0.85, "");
Delay("SG_Radio_Call", 5.18, "");
It's gonna be tricky to do these in low level. I'm still not quite sure of the optimal solution. Of course you could do it the hard way and write a new order for each of the animations but that's hardly what you want to do. I'll try to think of a simpler and prettier way to do it.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Following Script Points AND Shooting Enemies

Post by metal_head » Sat Jul 04, 2009 11:30 pm

Yeah, I though that it would be getting the point every frame, so I'll need to make an order which is only consisted of the next point order, it would be something like

Code: Select all

NextPoint();
self.think = "and a variable, telling the order that the script should go to, cuz I'm planning to use one NextPoint(); command a lot times, that should save some writing"
Hmm, well then I'll just set the view distance to a lower value while they are running so they shoot only at the enemies that are dangerously near (sounds OK). The problem here is that I'm not sure if I can do that in low level, but theese are just ideas, the real start will come when I'm ready to begin my jorney...as a jedy...wtf am I talking :lol:

User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Following Script Points AND Shooting Enemies

Post by Juutis » Sun Jul 05, 2009 12:21 am

metal_head wrote:Yeah, I though that it would be getting the point every frame, so I'll need to make an order which is only consisted of the next point order, it would be something like
Oh, no, no. That is already taken care of by the part:

Code: Select all

if(FastPointCheck(DISTANCE))
{
NextPoint();
}
Remember, it's low level, so this check is made every frame. So whenever the pawn is near the scriptpoint it targets the next one.
Pain is only psychological.

User avatar
metal_head
Posts: 1244
Joined: Sat Jan 05, 2008 8:31 pm
Location: Bulgaria,Sofia
Contact:

Re: Following Script Points AND Shooting Enemies

Post by metal_head » Sun Jul 05, 2009 8:42 am

...oh yeah, I forgot about this :D

Post Reply