View unanswered posts | View active topics It is currently Thu Dec 26, 2024 8:49 pm



Reply to topic  [ 7 posts ] 
 Ammo refilling 
Author Message
User avatar

Joined: Mon Sep 28, 2009 2:15 am
Posts: 720
Location: A fucking desert.
Reply with quote
Post Ammo refilling
I need a script for a fully automatic weapon that will allow its ammo to refill over time. i'm not sure on the exact rates i'm going to want for this, so it'd be nice if the script was easily customizable. the weapon will be firing AEmitters.


Sat Oct 29, 2011 5:36 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Ammo refilling
Code:
function Create(self)
self.CoolTimer = Timer()
self.TimeToBeginCooling = 1000
self.FillUpTimer = Timer()
self.HowMuchTimeBetweenFills = 250
end
function Update(self)

if self.CoolTimer:IsPastSimMS(self.TimeToBeginCooling) then
    if self.FillUpTimer:IsPastSimMS(self.HowMuchTimeBetweenFills) then
     self.RoundCount = self.RoundCount + 1
     self.FillUpTimer:Reset()
    end
elseif self:IsActivated() then
    self.CoolTimer:Reset()
end


Just written it up, I'm not sure if it will work, but I can't see why it shouldn't.
Easily customizable.


Sun Oct 30, 2011 6:50 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Ammo refilling
Which is the origin of semi-colons?
What's their use?


Sun Oct 30, 2011 7:26 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: Ammo refilling
I shall not, I always knew my fate;
Damn semi colons.


Sun Oct 30, 2011 8:14 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Ammo refilling
Zoink.

Edit: Fixed some stuffs.
Code:
function Create(self)

   self.maxAmmo = 0;
   self.ammoCounter = 0;

   if self.Magazine ~= nil then
      self.maxAmmo = 1 + self.Magazine.RoundCount;
      self.ammoCounter = self.maxAmmo;
   end

   self.fireTimer = Timer();
   self.rechargeTimer = Timer();

   self.fireDelay = 100; -- delay between shots (MS)
   self.rechargeDelay = 200;

   self.fireVel = 50;
   self.fireSpread = 5; -- Degrees!
   self.fireSpreadSharp = 10;

end

function Update(self)

   if self:IsActivated() then
      if self.ammoCounter > 1 then
         if self.fireTimer:IsPastSimMS(self.fireDelay) then
            self.fireTimer:Reset();
            self.rechargeTimer:Reset();
            self.ammoCounter = self.ammoCounter - 1;

            if self.HFlipped == false then
               self.negativeNum = 1;
            else
               self.negativeNum = -1;
            end

            local actor = MovableMan:GetMOFromID(self.RootID);

            if MovableMan:IsActor(actor) and ToActor(actor):GetController():IsState(Controller.AIM_SHARP) then
               local projectile = CreateAEmitter("Round name");
               projectile.Pos = self.MuzzlePos;
               projectile.Vel = self.Vel + Vector(self.fireVel*self.negativeNum,0):RadRotate(self.RotAngle):DegRotate((self.fireSpread/(-2))+(math.random()*self.fireSpreadSharp));
               MovableMan:AddParticle(projectile);
            else
               local projectile = CreateAEmitter("Round name");
               projectile.Pos = self.MuzzlePos;
               projectile.Vel = self.Vel + Vector(self.fireVel*self.negativeNum,0):RadRotate(self.RotAngle):DegRotate((self.fireSpread/(-2))+(math.random()*self.fireSpread));
               MovableMan:AddParticle(projectile);
            end

         end
      else
         self:Reload();
      end
   else
      if self.ammoCounter < self.maxAmmo and self.rechargeTimer:IsPastSimMS(self.rechargeDelay) then
         self.rechargeTimer:Reset();
         self.ammoCounter = self.ammoCounter + 1;
      end
   end

   if self.Magazine ~= nil then
      self.Magazine.RoundCount = self.ammoCounter;
   end

end


Sun Oct 30, 2011 8:54 pm
Profile
User avatar

Joined: Mon Nov 14, 2011 8:58 pm
Posts: 92
Reply with quote
Post Re: Ammo refilling
Asklar wrote:
I shall not, I always knew my fate;
Damn semi colons.


it's good practice if you transition to C++/Java

that being said I am guilty of not using semicolons in lualand


Sun Nov 20, 2011 1:33 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post Re: Ammo refilling
Lets have a look at what PIL says about semicolons before jumping to conclusions:
Programming in Lua wrote:
Each piece of code that Lua executes, such as a file or a single line in interactive mode, is a chunk. More specifically, a chunk is simply a sequence of statements.

A semicolon may optionally follow any statement. Usually, I use semicolons only to separate two or more statements written in the same line, but this is just a convention. Line breaks play no role in Lua's syntax; for instance, the following four chunks are all valid and equivalent:
Code:
    a = 1
    b = a*2
   
    a = 1;
    b = a*2;
   
    a = 1 ; b = a*2
   
    a = 1   b = a*2    -- ugly, but valid

i.e ending a line with a semicolon is redundant.


Sun Nov 20, 2011 11:14 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 7 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.195s | 17 Queries | GZIP : Off ]