Data Realms Fan Forums
http://45.55.195.193/

Could you give me a quick hand?
http://45.55.195.193/viewtopic.php?f=73&t=16289
Page 1 of 1

Author:  xerxys [ Thu Aug 20, 2009 9:49 am ]
Post subject:  Could you give me a quick hand?

Right, I asked mail about this a while ago but I still can't get it to work.

There are two scripts. One attached to a particle fired from a gun, the other to an actor. When the particle is created it creates the actor and destroys the firer of the gun.

What I want is for the player to automaticaly select the actor after the gun is fired.

I know this should involve the code
Code:
ActivityMan:GetActivity():SwitchToActor()
, with some args.

Were should I put that snippet to have it work? I have tried different positions with different args. and I can't get it to work.

Here's the code for the actor

Code:
function Create(self)   
   self.reloadTimer = Timer();
   self.reloadTime = 3000
   self.repartTimer = Timer();
   self.repartTime = 10000
self.gravTester = CreateMOPixel("3DSniper Grav Tester");
   self.gravTester.Pos = Vector(self.Pos.X, self.Pos.Y);
   self.gravTester.Vel = Vector(0,0);
   MovableMan:AddParticle(self.gravTester);
self.gravAcc = 0
self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
   self.gravTester2.Pos = Vector(self.Pos.X, self.Pos.Y);
   self.gravTester2.Vel = Vector(0,0);
   MovableMan:AddParticle(self.gravTester2);
self.Fog2 = CreateMOSParticle("Fog of War Inverter");
self.Fog2.Pos = Vector(self.Pos.X, self.Pos.Y - 3);
self.Fog2.Vel = Vector(0,0);
MovableMan:AddParticle(self.Fog2);
self.Fog = CreateMOSParticle("Fog of War");
self.Fog.Pos = Vector(self.Pos.X, self.Pos.Y - 3);
self.Fog.Vel = Vector(0,0);
MovableMan:AddParticle(self.Fog);

end

function Update(self)
   
   if not(self:IsDead()) then
   
   
   
      if self.gravAcc == 0 then
         if self.gravTester.Vel.Y > 0 then
            self.gravAcc = self.gravTester.Vel.Y;
         end
      end
   
      self.RotAngle = 0;
      
      local ownController = self:GetController();
      
      
      
      if ownController:IsState(Controller.HOLD_LEFT) then
         self.Vel.X = self.Vel.X - 0.5;
         
         if self.Vel.X < -15 then
         self.Vel.X = -15;
         end
      elseif ownController:IsState(Controller.HOLD_RIGHT) then
         self.Vel.X = self.Vel.X + 0.5;
         if self.Vel.X > 15 then
            self.Vel.X = 15;
         end
      elseif self.Vel.X < 0 then
         self.Vel.X = self.Vel.X + 0.5;
         if self.Vel.X > 0 then
         self.Vel.X = 0;
         end
      elseif self.Vel.X > 0 then
         self.Vel.X = self.Vel.X - 0.5;
         if self.Vel.X < 0 then
            self.Vel.X = 0;
         end
      end
      
      if ownController:IsState(Controller.HOLD_UP) then
         self.Vel.Y = self.Vel.Y - 0.5;
         if self.Vel.Y < -15 then
            self.Vel.Y = -15;
         end
      elseif ownController:IsState(Controller.HOLD_DOWN) then
            self.Vel.Y = self.Vel.Y + 0.5;
            if self.Vel.Y > 15 then
               self.Vel.Y = 15;
            end
      elseif self.Vel.Y < 0 then
            self.Vel.Y = self.Vel.Y + 0.5;
            if self.Vel.Y > 0 then
               self.Vel.Y = 0;
            end
      elseif self.Vel.Y > 0 then
         self.Vel.Y = self.Vel.Y - 0.5;
         if self.Vel.Y < 0 then
            self.Vel.Y = 0;
         end
      end
   
      if ownController:IsState(Controller.WEAPON_FIRE) and self.reloadTimer:IsPastSimMS(self.reloadTime) then
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X + 25, self.Pos.Y + 1);
            self.gravTester2.Vel = Vector(-100,0);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X - 25, self.Pos.Y + 1);
            self.gravTester2.Vel = Vector(100,0);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X, self.Pos.Y - 25);
            self.gravTester2.Vel = Vector(0,100);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X, self.Pos.Y + 25);
            self.gravTester2.Vel = Vector(0,-100);
            MovableMan:AddParticle(self.gravTester2);
            self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X + 25, self.Pos.Y + 1);
            self.gravTester2.Vel = Vector(-100,0);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X - 25, self.Pos.Y + 1);
            self.gravTester2.Vel = Vector(100,0);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X, self.Pos.Y - 25);
            self.gravTester2.Vel = Vector(0,100);
            MovableMan:AddParticle(self.gravTester2);
         self.gravTester2 = CreateMOPixel("3DSniper Grav Tester2");
            self.gravTester2.Pos = Vector(self.Pos.X, self.Pos.Y + 25);
            self.gravTester2.Vel = Vector(0,-100);
            MovableMan:AddParticle(self.gravTester2);
         print("CREATE: TURBOKAT - SUCCESS")
         self.reloadTimer = Timer();
      end
      
      for particle in MovableMan.Particles do
         if particle.PresetName == ("Fog of War Inverter") or particle.PresetName == ("Fog of War") then
            particle.Pos = self.Pos
         end
         if self.repartTimer:IsPastSimMS(self.repartTime) then
            if particle.PresetName == ("Fog of War Inverter") or particle.PresetName == ("Fog of War") then
               particle.Lifetime = 1
               print ("deleted")
            end
         self.Fog = CreateMOSParticle("Fog of War");
         self.Fog.Pos = Vector(self.Pos.X, self.Pos.Y);
         self.Fog.Vel = Vector(0,0);
         MovableMan:AddParticle(self.Fog);
         self.Fog2 = CreateMOSParticle("Fog of War Inverter");
         self.Fog2.Pos = Vector(self.Pos.X, self.Pos.Y);
         self.Fog2.Vel = Vector(0,0);
         MovableMan:AddParticle(self.Fog2);
         self.repartTimer = Timer();
         print ("reparted")
         end
      
         -- if self:IsPlayerControlled() == false then
            -- if particle.PresetName == ("Fog of War Inverter") or particle.PresetName == ("Fog of War") then
               -- particle.Lifetime = 0
            -- end
            -- self.Lifetime = 1
            -- self.Health = 0
         -- end
      end
         
      self.Vel.Y = self.Vel.Y - self.gravAcc
   end
end


And here it is for the gun

Code:
function Create(self)
   local curdist = 40;
   for actor in MovableMan.Actors do
      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 < curdist then
         curdist = dist;
         guy = CreateACrab("3D Sniper")
         guy.Team = actor.Team
         guy.Pos = actor.Pos
         guy.AIMode = Actor.AIMODE_SENTRY
         MovableMan:AddActor(guy)
         actor.Pos.Y = actor.Pos.Y + 999999999
      end   
   end
end


Thanks

Author:  Grif [ Thu Aug 20, 2009 2:56 pm ]
Post subject:  Re: Could you give me a quick hand?

Scripts run on an HDFirearm will not run until you drop it; when held it's considered an attachable.

Author:  MaximDude [ Thu Aug 20, 2009 4:12 pm ]
Post subject:  Re: Could you give me a quick hand?

Attach an AEmitter to the gun and attach the script to it.
Theoretically, it should work as if it is the gun, though you may need to add a line that checks what if the fire button is pressed, and then do the rest of the script.

Author:  Grif [ Thu Aug 20, 2009 11:45 pm ]
Post subject:  Re: Could you give me a quick hand?

An attached aemitter will not function for the same reason.

You have to attach an emitter that emits particles that do the required lua functions.

Author:  MaximDude [ Thu Aug 20, 2009 11:54 pm ]
Post subject:  Re: Could you give me a quick hand?

Grif wrote:
An attached aemitter will not function for the same reason.

You have to attach an emitter that emits particles that do the required lua functions.


Really?
Lua works directly on AEs, so it shouldn't do that... Though I never got to check it on a weapon.

Well, then just have it emit 120 particles per minute (or you can go with 60, though there shouldn't be much difference) and attach the script to each particle.

Author:  Grif [ Thu Aug 20, 2009 11:57 pm ]
Post subject:  Re: Could you give me a quick hand?

Grif wrote:
Scripts run on an HDFirearm AEmitters will not run until you drop it when they are attached; when held attached it's considered an attachable.

Author:  MaximDude [ Fri Aug 21, 2009 12:04 am ]
Post subject:  Re: Could you give me a quick hand?

Grif wrote:
Grif wrote:
Scripts run on an HDFirearm AEmitters will not run until you drop it when they are attached; when held attached it's considered an attachable.


Ok, ok, I understand. >________________>'
I will, though, check if I can make it work directly (Maybe i'll come up with some hacky solution). But that is unlikely to happen in the next few days. >______________>'

Author:  xerxys [ Sat Aug 22, 2009 6:34 pm ]
Post subject:  Re: Could you give me a quick hand?

Sorry, forgot I posted this. but I would still like some help


xerxys wrote:
There are two scripts. One attached to a particle fired from a gun, the other to an actor. When the particle is created it creates the actor and destroys the firer of the gun.

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