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



Reply to topic  [ 2 posts ] 
 Invisible brains 
Author Message

Joined: Sat Nov 29, 2008 11:11 pm
Posts: 11
Reply with quote
Post Invisible brains
How would I go about placing invisible brains (that are unselectable to players and also invisible to the AI) if there happens to be additional human players (2-4) for either team 1 or 2 in a mission?

So far i tried the "invisible brain" code from exodus mission and got it to work somewhat, but the AI still goes after it and the brain can be selected. Also, when multiple human players are present (for example 2 in team 1 and one person in team 2) the game just crashes right after the mission starts.

I don't have alot of previous coding experience, so I apologize beforehand for my mistakes!

I think here I also tried to create a soldier (or a dummy) that would get selected at start instead of the brain

Code:
   for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
      if self:PlayerActive(player) and self:PlayerHuman(player) then
         -- Check if we already have a brain assigned
         if not self:GetPlayerBrain(player) then
            self.braindead[player] = false;
            local foundBrain = MovableMan:GetUnassignedBrain(self:GetTeamOfPlayer(player));
            -- If we can't find an unassigned brain in the scene to give each player, then force to go into editing mode to place one
            if not foundBrain then
               --Create an invisible brain.
               self.brain = CreateActor("Base.rte/Brain Case");
               self.brain.Team = self:GetTeamOfPlayer(player);
               self.brain.Pos = Vector(320,234);
               self.brain:SetAimAngle(math.pi / -5)
               self.brain.HFlipped = true;
               self.brain.Scale = 0;
               self.brain.GetsHitByMOs = false;
               self.brain.HitsMOs = false;
               if self.brain.Team == Activity.TEAM_2 then
                  self.p2soldier = CreateAHuman("Dummy");
                  self.p2soldier.Team = Activity.TEAM_2;
                  self.p2soldier.Pos = Vector(1704,1428);
                  self.p2soldier:AddInventoryItem(CreateHDFirearm("Blaster"));
                  MovableMan:AddActor(self.p2soldier);
                  MovableMan:AddActor(self.brain);
               else
                  self.p2soldier = CreateAHuman("Soldier Light");
                  self.p2soldier.Team = Activity.TEAM_1;
                  self.p2soldier.Pos = Vector(1704,1428);
                  self.p2soldier:AddInventoryItem(CreateHDFirearm("Coalition.rte/Assault Rifle"));
                  MovableMan:AddActor(self.p2soldier);
                  MovableMan:AddActor(self.brain);
               end
               self:SetPlayerBrain(self.brain,player);
               self:SwitchToActor(self.p2soldier,player,-1);
            else
               -- Set the found brain to be the selected actor at start
               self:SetPlayerBrain(foundBrain, player);
               self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player));
               -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
               self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
            end
         end
      end
   end


Thu Dec 30, 2010 2:05 am
Profile

Joined: Fri Dec 18, 2009 11:00 pm
Posts: 167
Reply with quote
Post Re: Invisible brains
Attach this script to a copy of the "brain case"

function Create(self)
     self.Scale = 0
end

function Update(self)
     for Actor in MovableMan.Actors do
          if Actor.Team ~= self.Team then
               if Actor.AIMode == 4 then
                    Actor.AIMode = 1;
               end
          end
     end

     if self:IsPlayerControlled() then
          local NextActor = MovableMan:GetNextTeamActor(self.Team, self);
          if NextActor.ID ~= self.ID then
               self.Activity:SwitchToActor(NextActor, self.Team, self.Team);
          end
     end
end


This is untested but should work.


Fri Jan 07, 2011 5:39 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.043s | 15 Queries | GZIP : Off ]