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