View unanswered posts | View active topics It is currently Thu Dec 26, 2024 5:52 pm



Reply to topic  [ 7 posts ] 
 problem with actor:HasObject() (partially solved) 
Author Message
User avatar

Joined: Tue Dec 21, 2010 4:46 pm
Posts: 13
Reply with quote
Post 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


Last edited by Raseri on Wed Dec 22, 2010 11:05 pm, edited 14 times in total.



Tue Dec 21, 2010 8:02 pm
Profile ICQ
User avatar

Joined: Sun Jun 21, 2009 11:57 pm
Posts: 32
Reply with quote
Post 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?


Tue Dec 21, 2010 9:29 pm
Profile
User avatar

Joined: Wed Feb 17, 2010 12:07 am
Posts: 1545
Location: That small peaceful place called Hell.
Reply with quote
Post Re: problem with actor:HasObject()
Instead of

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


Try

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


Tue Dec 21, 2010 9:35 pm
Profile
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post 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.


Wed Dec 22, 2010 7:04 pm
Profile
User avatar

Joined: Tue Dec 21, 2010 4:46 pm
Posts: 13
Reply with quote
Post 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)


Wed Dec 22, 2010 7:21 pm
Profile ICQ
User avatar

Joined: Tue Nov 06, 2007 6:58 am
Posts: 2054
Reply with quote
Post Re: problem with actor:HasObject()
I don't think returned craft show up in MovableMan.Actors


Wed Dec 22, 2010 8:48 pm
Profile
User avatar

Joined: Tue Dec 21, 2010 4:46 pm
Posts: 13
Reply with quote
Post 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?


Wed Dec 22, 2010 9:47 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.083s | 13 Queries | GZIP : Off ]