View unanswered posts | View active topics It is currently Fri Jan 10, 2025 12:06 am



Reply to topic  [ 3 posts ] 
 Sudden crash when swapping actors 
Author Message
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Sudden crash when swapping actors
Very well. I decided to try my hand at making a pilotable vehicle script, and after a few hours of ironing out bugs, came up with this:

Code:
function Create(self)

   self.IsPiloted = 0;
   self.Pilot = nil;
   self.DeathTimer = Timer();
   self.timer = Timer();
   self.IsDying = 0;
   

   
         
end



function Update(self)

if self.timer:IsPastSimMS(25) then

   if self.IsPiloted == 0 then
      if self:IsPlayerControlled() then
         ActivityMan:GetActivity():SwitchToActor(ActivityMan:GetActivity():GetPlayerBrain(self:GetController().Player),self:GetController().Player,self.Team);
      end
      
      for actor in MovableMan.Actors do
         if actor.ClassName == "AHuman" and actor.Mass < 300 then
            local avgx = actor.Pos.X - self.Pos.X;
                local avgy = actor.Pos.Y - self.Pos.Y;
               local dist = math.sqrt(avgx ^ 2 + avgy ^ 2);    
            if dist < 30 then
               if actor:IsPlayerControlled() and actor:GetController():IsState(Controller.PIE_MENU_ACTIVE) and actor.AIMode == Actor.AIMODE_GOLDDIG then
                  self.Pilot = actor;
                  self.IsPiloted = 1;
                  ActivityMan:GetActivity():SwitchToActor(self,self:GetController().Player,self.Team);
                  actor.HitsMOS = false;
                  actor.GetsHitByMOS = false;
                  actor.AIMode = Actor.AIMODE_NONE;
                  
               end
            end
         end
      end
      
      self.AIMode = Actor.AIMODE_NONE;


   else
      

      if MovableMan:IsActor(self.Pilot) then
         self.Pilot.Pos.X = 0;
         self.Pilot.Pos.Y = 0;
         self.Pilot.Vel = Vector(0,0);
         self.Pilot.AngularVel = 0;   
         if self.Pilot:IsPlayerControlled() then
            ActivityMan:GetActivity():SwitchToActor(self,self:GetController().Player,self.Team);
         end
         if self.AIMode == Actor.AIMODE_GOLDDIG and self:IsPlayerControlled() and actor:GetController():IsState(Controller.PIE_MENU_ACTIVE)  then
            self.Pilot.Pos = self.Pos + Vector(5,5);
            self:FlashWhite(500);
            self.Pilot:FlashWhite(1000);
            self.Pilot.HitsMOS = true;
            self.Pilot.GetsHitByMOS = true;
            ActivityMan:GetActivity():SwitchToActor(self.Pilot,self:GetController().Player,self.Team);
            self.Pilot = nil;
            self.IsPiloted = 0;
         end
         if self.Health < 2 then
            self.Pilot.Pos = self.Pos + Vector(5,5);
            self:FlashWhite(500);
            self.Pilot:FlashWhite(500);
            self.Pilot.HitsMOS = true;
            self.Pilot.GetsHitByMOS = true;
            ActivityMan:GetActivity():SwitchToActor(self.Pilot,self:GetController().Player,self.Team);
            self.Pilot = nil;
            self.IsPiloted = 0;
            self.IsDying = 1;
         end
         


      else
         self.Pilot = nil;
         self.IsPiloted = 0;
      end
      
   end
   
   if self.IsDying == 0 then
      self.DeathTimer:Reset();
   end
   if self.Health < 2 then
      self.IsDying = 1;
   end
   if self.DeathTimer:IsPastSimMS(1000) then
      self:GibThis();
   end
   
self.timer:Reset();
end



end   


CC crashes instantly when I turn AI to gold dig on the pie menu. I assume it must be the game trying to refer to a null entry, but I can't see where the code would allow that to happen. It also gives no error message whatsoever, just stops working. Any thoughts on this?


Sun May 23, 2010 2:41 am
Profile WWW
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Sudden crash when swapping actors
In the actor switching function after the gold dig check, you're trying to get the player who's controlling the vehicle when I think you inted to get the player of the pilot.


Sun May 23, 2010 3:01 am
Profile
User avatar

Joined: Fri Oct 17, 2008 9:46 pm
Posts: 5212
Location: The Grills Locker.
Reply with quote
Post Re: Sudden crash when swapping actors
Why yes, you're right! That did the trick. Many thanks to ya, good sir.


Sun May 23, 2010 3:10 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.078s | 13 Queries | GZIP : Off ]