Switching player actor in game?

Topics regarding Scripting with Reality Factory
Post Reply
User avatar
blutwurstchen
Posts: 57
Joined: Wed Mar 19, 2008 8:51 pm

Switching player actor in game?

Post by blutwurstchen »

Does anyone know of a way to switch a player actor in game. I know something similiar is done with a destroyable model.

I was thinking about reaching a checkpoint in a level and have a player switch to a different one to carry on with a game, kind of like a relay.

If this is possible via a scripted player, and anybody has done this successfully, please tell me how.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Switching player actor in game?

Post by Juutis »

Yes, it should possible with a scripted player. You could have two different pawns: one for each player character. Then, when you reach the checkpoint, the first pawn would be disabled (removed, or whatever) and the second pawn would spawn, or gain the control some other way.
Pain is only psychological.
User avatar
blutwurstchen
Posts: 57
Joined: Wed Mar 19, 2008 8:51 pm

Re: Switching player actor in game?

Post by blutwurstchen »

Well I've got a scripted player to work using a modified genericplayer.s.

I'll put two pawns in the level: one for the original player and one for the new one. Maybe for the 'checkpoint' I could use a trigger entity attached to an invisible brush, so that when a player touches it the transformation takes place.

I'm thinking of using PlayAnimation so that the player looks like they are getting changed, or brushing their hair etc. Perhaps the screen could momentarily fade to black, during which time the old pawn will disappear and the new one will spawn.

The question I have is, how should I set up the trigger within the script to make this things happen? If anyone has used triggers in their scripts like this or done it any other way, maybe they could post an extract. I would really appreciate it.
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Switching player actor in game?

Post by Juutis »

Well, the easiest way would be to simply remove the old pawn and spawn the new one. So in the script for the first pawn you would have to check if the trigger (called 'checkpoint' in my example) is on and then remove the pawn:

Code: Select all

if(GetEventState("checkpoint"))
{
     HighLevel("remove");
     return 0;
}
The 'remove' order should be something like this:

Code: Select all

remove[ ()
{
     Remove(true);
} ]
Of course, you can and you should add some special effects like the ones you mentioned. They should be relatively simple with commands such as FillScreenArea for fading the screen in/out, Animate (and all its variants) for animation, etc.


Spawning the new pawn should be even easier. Just use the SpawnTrigger field in the editor.
Pain is only psychological.
User avatar
blutwurstchen
Posts: 57
Joined: Wed Mar 19, 2008 8:51 pm

Re: Switching player actor in game?

Post by blutwurstchen »

Hmm,

I tried this and now the pawn is not showing up. Can anyone tell me if there is something wrong with my script. It is just a patrol script with Juutis' addition added on.

Code: Select all

{
start[ ()
{
Console(true);
PlayAnimation("Idle", true, "");
Delay("Idle", 3, "");
RotateMoveToPoint("Walk", 50, 20, true, "footsteps\\footstep.wav");
MoveToPoint("Walk", 50, "footsteps\\footstep.wav");
NewOrder("Patrol");
}]
Patrol [ ()
{
NextPoint();
RotateMoveToPoint("Walk", 50, 20, true, "footsteps\\footstep.wav");
MoveToPoint("Walk", 50, "footsteps\\footstep.wav");
RestartOrder();
} ]
if(GetEventState("checkpoint"))
{
     HighLevel("remove");
     return 0;
}
remove[ ()
{
     Remove(true);
} ]
}
User avatar
Juutis
Posts: 1511
Joined: Thu Jan 12, 2006 12:46 pm
Location: Finland

Re: Switching player actor in game?

Post by Juutis »

This part isn't inside any order:

Code: Select all

if(GetEventState("checkpoint"))
{
     HighLevel("remove");
     return 0;
}
To work, the script should be something like:

Code: Select all

{
start[ ()
{
Console(true);
PlayAnimation("Idle", true, "");
Delay("Idle", 3, "");
RotateMoveToPoint("Walk", 50, 20, true, "footsteps\\footstep.wav");
MoveToPoint("Walk", 50, "footsteps\\footstep.wav");
NewOrder("Patrol");
}]
Patrol [ ()
{
NextPoint();
RotateMoveToPoint("Walk", 50, 20, true, "footsteps\\footstep.wav");
MoveToPoint("Walk", 50, "footsteps\\footstep.wav");

if(GetEventState("checkpoint"))
{
     NewOrder("remove");
}

RestartOrder();
} ]

remove[ ()
{
     Remove(true);
} ]
}
But even now the script won't work like it's supposed to. It does the eventstate check only after rotating and moving to the next scriptpoint. That is because it's a high level order, and in high level only one command is executed at a time. You could, however, add the following line to the 'start' order:

Code: Select all

AddTriggerOrder("remove","checkpoint",0);
And then, whenever the trigger 'checkpoint' is on, the order 'remove' is executed (the pawn is removed).


Anyway, this has little to do with your player script because it is almost fully low level (well, at least it should be). There's an order called 'RunPlayer' in genericplayer.s and that's the main loop of the script. So that's where you should throw the if-stuff from my last post. Then just paste the 'remove' order in the script and you should be good to go. :)
Pain is only psychological.
User avatar
blutwurstchen
Posts: 57
Joined: Wed Mar 19, 2008 8:51 pm

Re: Switching player actor in game?

Post by blutwurstchen »

Wow, It worked. Thanks so much for your help.

I tried it with an NPC pawn, and it disappeared to be replaced with the other one. Have not yet tried it with the scripted player. I've got to fix the view angle first, as there is no third person viewable.
Post Reply