Data Realms Fan Forums
http://45.55.195.193/

Invisible brains
http://45.55.195.193/viewtopic.php?f=73&t=20962
Page 1 of 1

Author:  einari [ Thu Dec 30, 2010 2:05 am ]
Post subject:  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

Author:  none [ Fri Jan 07, 2011 5:39 am ]
Post subject:  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.

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