Data Realms Fan Forums
http://45.55.195.193/

problem with actor:HasObject() (partially solved)
http://45.55.195.193/viewtopic.php?f=73&t=20809
Page 1 of 1

Author:  Raseri [ Tue Dec 21, 2010 8:02 pm ]
Post subject:  problem with actor:HasObject() (partially solved)

I want to make sure that the command unit could not leave the map on the ship.
It was assumed that this script creates a copy of the commander under the ship and destroy the ship with the commander sitting inside.
For some reason the script does not work.
And it does not work because of the presence of these words: actor:HasObject("Brain Robot").
I discovered this after a few attempts.
I'm shocked.
What's funny, once this script to work correctly.
How to get this bastard to work?

Code:
--function 1

function Equanimity:Return()
   for actor in MovableMan.Actors do
      if (actor:IsInGroup("Craft")) and (actor:HasObject("Brain Robot")) and (actor.Pos.Y < -20) then
         self.Brain2 = CreateAHuman("Brain Robot","Base.rte");
         self.Brain2.Pos = actor.Pos + Vector(0, 30);
         MovableMan:AddActor(self.Brain2);
         self:SetPlayerBrain(self.Brain2, 0);
         actor.ToDelete = true;
         self:SwitchToActor(self.Brain2,Activity.PLAYER_1,Activity.TEAM_1);
         self.MesRet = 1;
         self.TimerRet:Reset();
      end
   end
   if self.MesRet == 1 then
      if (self.TimerRet:IsPastSimMS(0)) and not (self.TimerRet:IsPastSimMS(5000)) then
         FrameMan:SetScreenText("Where are you going? The work is not finished yet.", 0, 0, 5000, false);
      end
   end

end


---
I rewrote the code in this way.
If the ship gets the "Robot 1" then the console displays only the numbers 2 and 4.
All other functions in the mission work.
Code:
--function 2

function Equanimity:Return2()
   print('2');
   for actor in MovableMan.Actors do
      if (actor.ClassName == "ACraft") and (actor:HasObject("Robot 1")) then
         print('3');
      end
   end
   print('4');
end

Author:  Zaits [ Tue Dec 21, 2010 9:29 pm ]
Post subject:  Re: problem with actor:HasObject()

I'm a complete noobie so this might be retarded but...

That line with actor:HasObject, thats checking if the actors in a ship and if the actors a brain or not.
So shouldn't it check to see if the actor belongs in the brain actor group, not if it's got a brain?

Author:  Coops [ Tue Dec 21, 2010 9:35 pm ]
Post subject:  Re: problem with actor:HasObject()

Instead of

Code:
(actor:IsInGroup("Craft"))


Try

Code:
(actor.ClassName == "ACraft")

Author:  mail2345 [ Wed Dec 22, 2010 7:04 pm ]
Post subject:  Re: problem with actor:HasObject()

The function you want is actor:HasObjectInGroup("Brains")
I think it works even if the actor itself is a brain.

Also I don't know when the Return() activity function is run, if at all, so try using <activityclassname>:CraftEnteredOrbit().
self.OrbitedCraft is the dropship that enters orbit.
Maybe you could just pass it to MovableMan:AddActor(), and return it to the ground.

Author:  Raseri [ Wed Dec 22, 2010 7:21 pm ]
Post subject:  Re: problem with actor:HasObject()

Thanks, I'll try =)

But I still do not understand why this design does not work here, though works fine elsewhere.
(Talking about the function of the number 2)

Author:  mail2345 [ Wed Dec 22, 2010 8:48 pm ]
Post subject:  Re: problem with actor:HasObject()

I don't think returned craft show up in MovableMan.Actors

Author:  Raseri [ Wed Dec 22, 2010 9:47 pm ]
Post subject:  Re: problem with actor:HasObject()

I do a check before the ship goes into orbit (Pos.Y ~ -20).
The ship disappears when its Pos.Y is ~ -100.
If you mean it o_0

-----
It's alive! It's alive! :D

Look:
Code:
--This function checks if the brain is alive or not
function Equanimity:Death()
   
   local brain = self:GetPlayerBrain(Activity.PLAYER_1);
   if not brain or not MovableMan:IsActor(brain) then
      self:SetPlayerBrain(nil, Activity.PLAYER_1);
      local newBrain = MovableMan:GetUnassignedBrain(Activity.TEAM_1);
      if newBrain then
         self:SetPlayerBrain(newBrain, Activity.PLAYER_1);
         self:SwitchToActor(newBrain, 0, Activity.TEAM_1);
      else
         self.WinnerTeam = Activity.TEAM_2;
         ActivityMan:EndActivity();
      end
   end
   
end

If the brain gets into the ship, the ship will be the brain.
If the brain (or ship == brain) is going to go into orbit and has the object of the "Brain Robot", then this is the thing that I need.

Code:
function Equanimity:Return2()

   local brain = self:GetPlayerBrain(Activity.PLAYER_1);
   if (brain.Pos.Y < -20) and brain:HasObject("Brain Robot") then
      self.Brain2 = CreateAHuman("Brain Robot","Base.rte");
      self.Brain2.Pos = brain.Pos + Vector(0, 30);
      MovableMan:AddActor(self.Brain2);
      self:SetPlayerBrain(self.Brain2, 0);
      brain.ToDelete = true;
      self:SwitchToActor(self.Brain2,Activity.PLAYER_1,Activity.TEAM_1);
      self.MesRet = 1;
      self.TimerRet:Reset();
   end

   if self.MesRet == 1 then
      if (self.TimerRet:IsPastSimMS(0)) and not (self.TimerRet:IsPastSimMS(5000)) then
         FrameMan:SetScreenText("Where are you going? The work is not finished yet.", 0, 0, 5000, false);
      end
   end
   
end


After several attempts, i got his, the program works.
But I do not understand why the code had not worked, and now works.
Do you have any ideas?

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