View unanswered posts | View active topics It is currently Mon Sep 23, 2019 10:46 am



Reply to topic  [ 1 post ] 
 Basic Gravity Gun fired through Lua 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post Basic Gravity Gun fired through Lua
I know there have been several of these, but not only do many of them not work anymore, they're far more complicated than I require. Pretty much I'm looking for this, mounted on a MOSRotating and firing either through lua or an emitter - when the beam is on, it pulls whatever it hits in towards the emitter (slowly, not snapping in) and when you let it go, it pushes it out gently rather than firing it out. The closest thing I can find is the mech's gravity gun in this mod, but even that is too heavy duty. I want the most basic possible way of doing it, but I'm no good at rays just yet.

EDIT: Nope, disregard, I just ripped that gun apart and reverse-engineered it.

Code:
function Create(self)
   self.LTimer = Timer();
   self.firemode = 0; -- 0 is inactive, 1 is gravitate, 2 is launch
   self.launchsound = false;
   self.canlaunchsound = true;

--------------------
----- The variables here can be changed to alter various properties of the phys cannon.
   self.launchpower = 0; -- strength of the launch. 120 is default.
   self.pickuppower = 100; -- strength of the pull. 120 is default.
   self.launchrange = 5; -- size of the area to check for objects to launch. 35 is default.
   self.pickuprange = 20; -- size of the area to check for objects to pull. 35 is default.

--------------------

   local curdist = 50;
    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 and actor:HasObject("Brainfighter") then
         self.parent = actor;
      end
    end
end

function Update(self)
   
--GRABBING THE OBJECT   
if self.firemode == 0 and self.LTimer:IsPastSimMS(5) then
   self.firemode = 1;
end

if self.firemode == 1 and MovableMan:IsActor(self.parent) then
    for particle in MovableMan.Particles do
   if particle.ClassName == "MOSRotating" or particle.ClassName == "AEmitter" then
        local paravgx = particle.Pos.X - self.Pos.X;
        local paravgy = particle.Pos.Y - self.Pos.Y;
        local dist = math.sqrt(paravgx ^ 2 + paravgy ^ 2);
        if dist < self.pickuprange then
         particle.Vel = Vector((self.Pos.X - particle.Pos.X), (self.Pos.Y - particle.Pos.Y)) / (1 + (particle.Mass / self.pickuppower));
         particle:SetWhichMOToNotHit(self.parent,0.3);
         particle.RotSpeed = 0
      end
    end
end
end

-- RELEASING THE OBJECT
if MovableMan:IsActor(self.parent) then
    if not (self.parent:GetController():IsState(Controller.WEAPON_FIRE)) then
      self.firemode = 2;
   end
end

if self.firemode == 2 and MovableMan:IsActor(self.parent) then
      for particle in MovableMan.Particles do
   if particle.ClassName == "MOSRotating" or particle.ClassName == "AEmitter" then
        local paravgx = particle.Pos.X - self.Pos.X;
        local paravgy = particle.Pos.Y - self.Pos.Y;
        local dist = math.sqrt(paravgx ^ 2 + paravgy ^ 2);
        if dist < self.launchrange then
         particle.Vel = self.Vel / (1 + (particle.Mass / self.launchpower));
         particle.RotSpeed = 0
         --self.launchsound = true;
      end
    end
end
end

--[[if self.firemode == 1 and MovableMan:IsActor(self.parent) then
      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 < self.pickuprange and actor.ID ~= self.parent.ID then
      actor.Vel = Vector((self.Pos.X - actor.Pos.X), (self.Pos.Y - actor.Pos.Y)) / (1 + (actor.Mass / self.pickuppower));
      actor:SetWhichMOToNotHit(self.parent,0.3);
      end
      end
   end]]

--[[if self.firemode == 2 and MovableMan:IsActor(self.parent) then
    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 < self.launchrange and actor.ID ~= self.parent.ID then
         actor.Vel = self.Vel / (1 + (actor.Mass / self.launchpower));
         --self.launchsound = true;
      end
   end
end]]

--[[if self.launchsound == true and self.canlaunchsound == true then
   local firesound = CreateAEmitter("Mech Gravi Gun Sound Fire","D9.rte");
   firesound.Pos = self.parent.Pos;
   MovableMan:AddParticle(firesound);
   self.launchsound = false;
   self.canlaunchsound = false;
end]]

end


The code in question - all I want it to be able to do is pick up objects, so I commented out the ability for it to pick up items and actors.


Tue Nov 27, 2012 6:19 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

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.017s | 13 Queries | GZIP : Off ]