View unanswered posts | View active topics It is currently Mon Jun 24, 2019 11:21 pm



Reply to topic  [ 8 posts ] 
 Mine Launcher 
Author Message

Joined: Wed Aug 25, 2010 5:47 am
Posts: 5
Reply with quote
Post Mine Launcher
I've been messing around with weapons lately. Mostly because I'm taking a Java object oriented design class and I can actually understand code now.

I've made a bunch of weapons that are just downright awesome. One of the items on my to-do list though is to make a weapon that shoots mines. I have no idea where to start but I'm not advanced enough to make everything from scratch, and the code surrounding both the cluster mine bomb and grenade launcher is a bit too convoluted for my level of skill (which I will admit at this moment is the very bottom, but at least I'm on some level..).

Another problem I have with mines in general is that they don't seem to work very well. Either they don't ever go off or they go off only on your actors even though they set them. I really need to fix this because It bugs the ♥♥♥♥ out of me. At least show me how I can make mines go off no matter who steps on them. Because it seems the IFF on them is FUBAR.

And I love the hell out of minefields, that work...


Mon Jun 30, 2014 7:32 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11356
Location: Here
Reply with quote
Post Re: Mine Launcher
For a basic mine, the script usually looks something like this:

Code:
function Create(self)

   self.scanTimer = Timer();

end

function Update(self)

   if self.scanTimer:IsPastSimMS( 500 ); -- half second delay in between detection
      self.scanTimer:Reset();

      -- some method of detecting actors or appropriate targets

      if <appropriate target is detected> then

         -- gib self, or create explosion effects and then delete self

      end

   end

end


There are two main ways to do detection.

You have the basic distance check, which goes through every actor on the map and does a distance check with them. If an actor is within a specified distance, the mine explodes.

Then there are ray casts, which check pixels forming a line in some direction, which are more efficient than distance checks but have a narrower "vision."

Multiple ray casts can form a decent area check, or you can make your own pattern with the pixel checks ( SceneMan:GetMOIDPixel( x, y) ). Fermat's spiral works nicely.

Team checks should also be done during this part, so the mine ignores allied actors.



The timer and timer check is for putting a time delay in between detection runs. Depending on how costly your detection system is, you want to only run it every so milliseconds instead of every frame, unless if it's fast and simple (a single line ray cast).



Detonating the mine can be simply forcing it to gib using Lua ( self:GibThis() ) or spawning a separate explosion effect and then deleting the mine.


An example of a simple mine script that can be attached to an MO that is fired from a gun:

Code:
function Create(self)

   self.scanTimer = Timer();

end

function Update(self)

   if self.scanTimer:IsPastSimMS( 500 ); -- half second delay in between detections
      self.scanTimer:Reset();

      -- go through all actors
      for actor in MovableMan.Actors do

         -- if the actor's team is not the mine's team, and if the distance between the mine and the actor is less than 100 pixels...
         if actor.Team ~= self.Team and SceneMan:ShortestDistance( self.Pos, actor.Pos, SceneMan.SceneWrapsX).Magnitude < 100;

            -- make the mine gib itself
            self:GibThis();

         end
      end

   end

end



Since a projectile's Team value is inherited from the gun, you can have a plain unscripted HDFirearm for the mine launcher.


Mon Jun 30, 2014 10:53 pm
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: Mine Launcher
The Fermat's Spiral technique works surprisingly well, I have to admit. I was skeptical at first (in terms of performance-demanding it would be), but it worked like a charm for the flak shells and airburst grenades which can both be hammered out at a decent rate, so it should work fine for mines as well as long as you're not throwing billions of them all over the map.

Unfortunately I think the only example(s) of the script I have on hand might be triggered by terrain?


Tue Jul 01, 2014 10:09 am
Profile YIM
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11356
Location: Here
Reply with quote
Post Re: Mine Launcher
Here's one for MOs only:

Code:
function Create(self)

   self.delayTimer = Timer();

   self.delayTime = 100; -- Delay time in MS before prox sensor starts

   self.pointCount = 100; -- number of points in the spiral
   self.spiralScale = 5; -- spiral scale
   self.skipPoints = 10; -- skips the first X points

end

function Update(self)

   if self.delayTimer:IsPastSimMS(self.delayTime) then
      for i = self.skipPoints, self.pointCount - 1 do
         local radius = self.spiralScale*math.sqrt(i);
         local angle = i * 137.508;
         local checkPos = self.Pos + Vector(radius,0):DegRotate(angle);
         if SceneMan.SceneWrapsX == true then
            if checkPos.X > SceneMan.SceneWidth then
               checkPos = Vector(checkPos.X - SceneMan.SceneWidth,checkPos.Y);
            elseif checkPos.X < 0 then
               checkPos = Vector(SceneMan.SceneWidth + checkPos.X,checkPos.Y);
            end
         end

         local moCheck = SceneMan:GetMOIDPixel(checkPos.X,checkPos.Y);
         if moCheck ~= 255 then
            local actor = MovableMan:GetMOFromID( MovableMan:GetMOFromID(moCheck).RootID );
            if actor.Team ~= self.Team then
               self:GibThis();
               break;
            end
         end

      end
   end

end



The timer in this one is just to prevent it from blowing up too early.


Tue Jul 01, 2014 10:35 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post Re: Mine Launcher
A bit of a side note but does anyone know how efficient it would be to make a scenearea and check if actors are within that, versus raycasting or proximity checks?


Tue Jul 01, 2014 8:26 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11356
Location: Here
Reply with quote
Post Re: Mine Launcher
It would probably be more efficient than a distance check, but I'm not 100% sure about scene area vs GetMoidPixel, but I'd lean more towards GetMOIDPixel if you don't have a gigantic search area.


Fri Jul 04, 2014 12:48 am
Profile

Joined: Wed Aug 25, 2010 5:47 am
Posts: 5
Reply with quote
Post Re: Mine Launcher
I kinda need a little prodding more in the .ini department. ironically LUA is much easier to understand with a bit of java training.


Fri Jul 04, 2014 1:24 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 11356
Location: Here
Reply with quote
Post Re: Mine Launcher
This should help.


Code:
// This is the actual mine
AddAmmo = MOSRotating
   PresetName = Mine Launcher Mine
   Mass = 2
   RestThreshold = -1
   HitsMOs = 1
   GetsHitByMOs = 0
   ScriptPath = MyMod.rte/MyMineScript.lua
   SpriteFile = ContentFile
      FilePath = Coalition.rte/Devices/Sprites/BulletGrenadeA.bmp
   FrameCount = 1
   SpriteOffset = Vector
      X = -3
      Y = -2
   AtomGroup = AtomGroup
      AutoGenerate = 1
      Material = Material
         CopyOf = Bullet Metal
      Resolution = 2
      Depth = 0
   DeepGroup = AtomGroup
      AutoGenerate = 1
      Material = Material
         CopyOf = Bullet Metal
      Resolution = 4
      Depth = 1
   DeepCheck = 0

   // Gib effects

   AddGib = Gib
      GibParticle = MOSParticle
         CopyOf = Side Thruster Blast Ball 1
      Count = 10
      MinVelocity = 30
      MaxVelocity = 55
   AddGib = Gib
      GibParticle = MOPixel
         CopyOf = Grenade Fragment Gray
      Count = 25
      MinVelocity = 50
      MaxVelocity = 150
   AddGib = Gib
      GibParticle = MOPixel
         CopyOf = Grenade Fragment Yellow
      Count = 25
      MinVelocity = 50
      MaxVelocity = 150
   AddGib = Gib
      GibParticle = MOPixel
         CopyOf = Air Blast
      Count = 20
      MinVelocity = 50
      MaxVelocity = 150
   AddGib = Gib
      GibParticle = MOSParticle
         CopyOf = Explosion Smoke 2
      Count = 15
      Spread = 3.1
      MaxVelocity = 10
      MinVelocity = 0
      LifeVariation = 0.70
      InheritsVel = 1
   AddGib = Gib
      GibParticle = MOSParticle
         CopyOf = Explosion Smoke 2 Glow
      Count = 6
      Spread = 3.1
      MaxVelocity = 10
      MinVelocity = 0
      LifeVariation = 0.60
      InheritsVel = 1
   AddGib = Gib
      GibParticle = AEmitter
         CopyOf = Explosion Trail 1
      Count = 3
      Spread = 3.1
      MaxVelocity = 40
      MinVelocity = 20
      LifeVariation = 0.50
      InheritsVel = 1
   EffectOnGib = 1
   EffectAlwaysShows = 1
   ScreenEffect = ContentFile
      Path = Base.rte/Effects/Glows/YellowHuge.bmp
   GibSound = Sound
      Priority = 1000
      AddSample = ContentFile
         Path = Base.rte/Sounds/Explode1.wav
      AddSample = ContentFile
         Path = Base.rte/Sounds/Explode2.wav



// Round for the Mine Launcher
AddAmmo = Round
   PresetName = Round Mine Launcher
   ParticleCount = 1
   Particle = MOSRotating
      CopyOf = Mine Launcher Mine
   FireVelocity = 30
   Separation = 0



// Magazine
AddAmmo = Magazine
   PresetName = Magazine Mine Launcher

   ...

   RegularRound = Round
      CopyOf = Round Mine Launcher



// Gun
AddDevice = HDFirearm
   PresetName = Mine Launcher

   ...

   Magazine = Magazine
      CopyOf = Magazine Mine Launcher

   ...





Sat Jul 05, 2014 6:55 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 8 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.021s | 13 Queries | GZIP : Off ]