View unanswered posts | View active topics It is currently Fri Dec 27, 2024 8:54 am



Reply to topic  [ 11 posts ] 
 Switching actors via Lua 
Author Message
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Switching actors via Lua
...Specifically to no one. As in, for example, when you aren't controlling anything until the rocket spits out the brain in Zombie Cave.


Sun Jul 18, 2010 8:46 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Switching actors via Lua
To do that you need to either be forced to control an invisible actor, or force the view point directly(I think you would also need to disable controls for the actual actor selected).
Functions are on activities(get em from ActivityMan:GetActivity(), or self if running from a activity script), they are SwitchToActor(actor,player,team) and SetBbservationTarget(pos?)


Sun Jul 18, 2010 9:00 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Switching actors via Lua
Also, how can I force someone to stay switched to a certain actor?


Sun Jul 18, 2010 10:59 pm
Profile

Joined: Sat Jun 16, 2007 8:04 pm
Posts: 42
Reply with quote
Post Re: Switching actors via Lua
Awesomeness wrote:
...Specifically to no one. As in, for example, when you aren't controlling anything until the rocket spits out the brain in Zombie Cave.


self:SetViewState(Activity.ACTORSELECT, player);

where self is the current activity, if it's not, then do this: ActivityMan:GetActivity():SetViewState(Activity.ACTORSELECT, player);

and player is the player number. 0, unless it's multiplayer.

This gives the effect in Zombie Cave where in the start you have the actor select cursor on until the brain robot pops out from the rocket. The only problem is, I couldn't control where it appears.... (with console at least)

I can only guess that self:SetActorSelectCursor(Vector(3024, 324), player); would set the position of the actor select cursor, if only it would work. But somehow it seems that the activity you get from Activity:GetActivity() isn't the same that ZombieCaveMission:StartActivity() gets. Because game complains that such method does not exist. Same goes for self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player). Weird :/

EDIT:
Awesomeness wrote:
Also, how can I force someone to stay switched to a certain actor?


One way (script attached to game object):

Code:
function Update(self)
   local Activity = ActivityMan:GetActivity();
   local ForcedControlledActor; --This should have the actor reference that you want the player to be forced to "control"
   local CurrentActor = Activity:GetControlledActor(0);
   if CurrentActor.ID ~= ForcedControlledActor.ID then -- Warning: may need to use MovableMan:IsActor() for invalid pointer checks, depending how you handle your variables.
      Activity:SwitchToActor(ForcedControlledActor, 0, 0);
   end
end


If you are planning on using a mission script for this, you can use SetViewState, SetActorSelectCursor, SetObservationTarget etc. functions. Zombie Cave mission script is good example.


Sun Jul 18, 2010 11:05 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Switching actors via Lua
Thanks. Lastly, (I hope) how do you make an actor move? I tried the actor controller but it didn't work... It didn't even give an error.


Mon Jul 19, 2010 2:46 am
Profile

Joined: Sat Jun 16, 2007 8:04 pm
Posts: 42
Reply with quote
Post Re: Switching actors via Lua
I assume you mean this? It's all in various mission scripts and LuaDocs btw.
Code:
local ronin = CreateAHuman("Dafred");
ronin.AIMode = Actor.AIMODE_GOTO;
ronin:ClearAIWaypoints();
ronin:AddAISceneWaypoint(Vector(200, 500));
-- ronin:SetControllerMode(Controller.CIM_AI, -1); You should only need to set controller mode if it's in your team and you want AI to control it. That is done automatically when you switch away from actor. I don't know what it does if you set the mode for currently controlled actor.
ronin.Team = 0; -- don't forget to set team and Pos if you need to.
ronin.Pos = Vector(0, 900);
MovableMan:AddActor(ronin);


Or if it's invisible actor you could just set it's Pos member property directly. Or if you're doing tightly controlled cutscene style stuff, SceneMan:SetScroll(actor.Pos, player) seems like a good tool. Depends what you're planning.


Mon Jul 19, 2010 2:13 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Switching actors via Lua
I need more help. I can't seem to control my actor (Dimitri) at all for my cutscene. If I make him walk, he just collapses and does the splits on the ground: (I tried the goto snippet you showed me, and nothing happened)
Code:
      if self.PlayerActor.Pos.X <= 175 then
         self.PlayerActor:GetController():SetState(Controller.MOVE_RIGHT, true)
      end

If I try to make him look at something, or even face the other way, it fails:
Code:
      self.PlayerActor.HFlipped = false; -- This does nothing
      self.PlayerActor.ViewPoint = Vector(175, 570); -- So does this...


I can't even change the AI mode:
Code:
      self.PlayerActor.AIMode = Actor.AIMODE_SENTRY; -- He isn't even looking around like he's supposed to when I set this


All I can do is change his position. I don't understand why... What am I missing?


Mon Jul 19, 2010 8:30 pm
Profile
REAL AMERICAN HERO
User avatar

Joined: Sat Jan 27, 2007 10:25 pm
Posts: 5655
Reply with quote
Post Re: Switching actors via Lua
Is the actor being controlled by the player? If there's a player doing anything at all, it'll pretty much ruin your ability to control it. Even the AI fights Lua scripts, though not as successfully.


Mon Jul 19, 2010 8:44 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Switching actors via Lua
Nope, it isn't.


Mon Jul 19, 2010 8:46 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: Switching actors via Lua
actor:GetController().InputMode is your friend to make the AI stop fiddling with the actor. Set it to Controller.CIM_NETWORK and then just set it back to whatever it was originally after you do the controlling stuff.


Mon Jul 19, 2010 8:54 pm
Profile
User avatar

Joined: Sat Jun 19, 2010 5:02 pm
Posts: 331
Location: Mekkan
Reply with quote
Post Re: Switching actors via Lua
Thanks, mail! It worked! Lol, by the time you figured it out, I had set the actor to do so many things that he exploded. Now that I've cleaned it up, it works perfectly!

EDIT: How can I have an actor look at something? I tried self.PlayerActor:SetAimAngle(angle) but no matter what angle is, he always looks at a certain angle almost straight up. I also tried self.PlayerActor.ViewPoint = Vector(x, y) with x and y being where my object is, but nothing happens and there's no error.
Figured it out.


Mon Jul 19, 2010 8:56 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.047s | 13 Queries | GZIP : Off ]