Data Realms Fan Forums
http://45.55.195.193/

Switching actors via Lua
http://45.55.195.193/viewtopic.php?f=73&t=19281
Page 1 of 1

Author:  Awesomeness [ Sun Jul 18, 2010 8:46 pm ]
Post subject:  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.

Author:  mail2345 [ Sun Jul 18, 2010 9:00 pm ]
Post subject:  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?)

Author:  Awesomeness [ Sun Jul 18, 2010 10:59 pm ]
Post subject:  Re: Switching actors via Lua

Also, how can I force someone to stay switched to a certain actor?

Author:  ScifiSpirit [ Sun Jul 18, 2010 11:05 pm ]
Post subject:  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.

Author:  Awesomeness [ Mon Jul 19, 2010 2:46 am ]
Post subject:  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.

Author:  ScifiSpirit [ Mon Jul 19, 2010 2:13 pm ]
Post subject:  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.

Author:  Awesomeness [ Mon Jul 19, 2010 8:30 pm ]
Post subject:  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?

Author:  Grif [ Mon Jul 19, 2010 8:44 pm ]
Post subject:  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.

Author:  Awesomeness [ Mon Jul 19, 2010 8:46 pm ]
Post subject:  Re: Switching actors via Lua

Nope, it isn't.

Author:  mail2345 [ Mon Jul 19, 2010 8:54 pm ]
Post subject:  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.

Author:  Awesomeness [ Mon Jul 19, 2010 8:56 pm ]
Post subject:  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.

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/