View unanswered posts | View active topics It is currently Fri Apr 19, 2024 8:14 pm



Reply to topic  [ 11 posts ] 
 Finding if a gun shoots, without using self:IsActivated() 
Author Message
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post Finding if a gun shoots, without using self:IsActivated()
Hello, brilliant, talented, wondrous .lua scripters of DRLFF. I seek guidance in the ways of .lua.

So, what I've got is a gun that sort of overheats, thanks to snippets of Asklar and Coops's code. In order to efficiently achieve the desired effect, I need to find when the gun (emits? creates? the particle) shoots. self.IsActivated() has failed me, as the fire command can be held down for many, many frames. If any of you could point me in the right direction I'd love to go back and tinker with the script.

EDIT: And if possible I would prefer the gun to retain it's unlimited ammo.

I have tried: (In no particular order)
- Using a 'break' (failed miserably)
- Finding if the bullet itself is created and within range (partially worked)
- Using IsActivated() (no dice)
- Giving the mag 1 round and checking if the gun reloads. (nope)

And various other methods. As you can clearly see, much of this script was made by me! I'm very proud of my horrible job.

Thanks in advance.


Last edited by Kettenkrad on Thu Oct 06, 2011 12:53 pm, edited 1 time in total.



Thu Oct 06, 2011 11:57 am
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Quote:
function_create
originalroundcount = self.roundcount
cooldowntimer = Timer()
cooldowntime = 500
overheat = 0
overheatlimit = 50

function_update
if self.roundcount < originalroundcount then <------fire checked
 overheat = overheat + originalroundcount - self.roundcount
 originalroundcount = self.roundcount
 cooldowntimer:Reset()
elseif self.roundcount < originalroundcount then <------reload
 originalroundcount = self.roundcount
end

if cooldowntimer:IsPastSimMS(cooldowntime) and overheat >= 0 then
 overheat = overheat - 1 <------cooldown
end

if overheat >= overheatlimit then
 (make the gun unable to shoot)
end


how about this


Thu Oct 06, 2011 12:41 pm
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Oh right, and the gun has infinite ammo, sorry.

Kidding, I'll give it a shot, thanks.

EDIT: I'd prefer if it retained it's unlimited ammo. Any way to get around this?


Last edited by Kettenkrad on Thu Oct 06, 2011 12:58 pm, edited 1 time in total.



Thu Oct 06, 2011 12:44 pm
Profile
User avatar

Joined: Sat Feb 26, 2011 10:29 am
Posts: 163
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Oh, and how about the self.parent:GetController():IsState(14)? Is it the same as IsActivated()?


Thu Oct 06, 2011 12:54 pm
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
From what I've seen, most likely. I'll have a look.

EDIT: Nope, same effect.


Thu Oct 06, 2011 12:59 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
You could just do complete Lua firing, instead of a hybrid between INI and Lua. That way, you'd have control over bullet spawning and you can use timers to make sure everything is synchornized nicely.

But, if you don't want to go full Lua, you could set your gun's Sharpness to 0 in INI. Then, have a script on the bullets that find the parent gun and change that sharpness when they're first created. Then you can just check the gun's sharpness if it fired a bullet or not and reset the Sharpness back to 0 after you're done doing your stuff.


Thu Oct 06, 2011 2:51 pm
Profile
User avatar

Joined: Wed May 20, 2009 3:10 pm
Posts: 366
Location: Århus, Denmark
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Look at my recoil script of the autocannon from the trapper mod, it uses the self.IsActivated(), but detects exactly when the particle is fired using timers and RateOfFire to find out when a shot is actually fired.

Here is the code stripped to its basics

Code:
function Create(self)
  self.ShootTimer = Timer()
  self.Clicked = false
end
function Update(self)
  if self:IsActivated() then
    if self.ShootTimer:IsPastSimMS(60000/self.RateOfFire) and self.Clicked then
      self.ShootTimer:Reset()
      -- add stuff here
      self.Clicked = false
    end
  else
    self.Clicked = true
  end
end


Remove the "self.Clicked" part if the gun is full automatic :)


Thu Oct 06, 2011 7:29 pm
Profile
User avatar

Joined: Mon Oct 25, 2010 5:51 am
Posts: 1198
Location: Sydney
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Thank you both, I ended up using akblabla's method, it required less work on my part :P

Works wonderfully now.


Fri Oct 07, 2011 1:52 am
Profile
User avatar

Joined: Sat Nov 03, 2007 9:44 pm
Posts: 1916
Location: Flint Hills
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()


Edit: It seems I poorly skimmed through the thread and have made a fool of myself, whoops.


Last edited by Azukki on Tue Oct 11, 2011 12:38 am, edited 1 time in total.



Tue Oct 11, 2011 12:25 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
Magazine RoundCount checking has already been suggested, but
Kettenkrad wrote:
EDIT: And if possible I would prefer the gun to retain it's unlimited ammo.


Tue Oct 11, 2011 12:35 am
Profile
User avatar

Joined: Fri May 11, 2007 4:30 pm
Posts: 1040
Location: England
Reply with quote
Post Re: Finding if a gun shoots, without using self:IsActivated()
What I ended up using in my portal gun script (edited for your own use):
Code:
   self.Parent = MovableMan:GetMOFromID(MovableMan:GetRootMOID(self.RootID));
   if MovableMan:IsActor(self.Parent) then
      self.Parent = ToActor(self.Parent);
      if (not(self.wait)) then
         if self.Parent:GetController():IsState(Controller.PRESS_PRIMARY) then
            self.fire=true;
         end
      end
   end
   if (self.wait) and (self.timer:IsPastSimMS(500)) then --change timer to match rate of fire
      self.wait=false;
   end
   if (self.fire) then
      self.timer:Reset();
      self.wait=true;
      self.fire=false;
   end


Basically there are two variables that control the shooting, self.fire and self.wait, both of them are initialized to false, so if the shoot button is pressed, self.fire is set to true and the firing code is run, then fire is set to false and wait is set to true, when wait is set the fire function cannot run until the timer has reached a threshold and it repeats. It's not the most accurate on timing but it's decent enough.

You will have to change Controller.PRESS_PRIMARY to Controller.PRIMARY_HELD or something like that, I can't remember.


Sat Oct 15, 2011 4:27 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.073s | 16 Queries | GZIP : Off ]