View unanswered posts | View active topics It is currently Thu Mar 28, 2024 6:37 pm



Reply to topic  [ 12 posts ] 
 A few small things 
Author Message

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post A few small things
I may need more help with code in the future and for things that most coders will probably see as very miniscule problems.. So that explains the title even though I currently only have 1 problem. :

Code:
function TSAGrenadeLauncherImpact(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Impact";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end

function TSAGrenadeLauncherBounce(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Bounce";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end


So I made a grenade launcher, that's shotgun-style reload. However if I use the piemenu to change ammo types, the round count doesn't reset and I can just continuously load infinite grenades (obviously kind of overpowered :) ). For the time being I've just been removing " gun:Reload();" and firing a shot off before reloading.. Although, is there a way to set the round count of the weapon to 0 JUST BEFORE the reload?


Sat Nov 17, 2012 6:08 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: A few small things
This should do what you're asking:

Code:
function TSAGrenadeLauncherImpact(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Impact";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         if self.Magazine ~= nil then
            self.Magazine.RoundCount = 0;
         end
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end

function TSAGrenadeLauncherBounce(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Bounce";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         if self.Magazine ~= nil then
            self.Magazine.RoundCount = 0;
         end
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end


Sat Nov 17, 2012 6:25 am
Profile

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things
Ironically I tried something like that.. what happens is that it doesn't even enter the reload part of the script... and on reloading, it doesn't switch the round type. It doesnt even set the roundcount to 0... so basically it does nothing >.>


Sat Nov 17, 2012 6:33 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: A few small things
Are you using the Sharpness value of your gun for anything? The issue is that the ShotgunReload.lua script has its own variable that keeps a record of the gun's supposed RoundCount. However, if you're not using Sharpness on your gun for anything, you can use that instead and both scripts can interact with that.


Sat Nov 17, 2012 7:32 am
Profile

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things
No, the sharpness value isn't being used. So what would I need to change in a copy of ShotgunReload? (& TSAGrenadeLauncherPie, the original code I posted)?

(ShotgunReloadGL.lua).



Sat Nov 17, 2012 7:48 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: A few small things
Code:
function Create(self)
   self.reloadTimer = Timer();
   self.loadedShell = false;
   self.reloadCycle = false;

   self.reloadDelay = 200;

   if self.Magazine then
      self.Sharpness = self.Magazine.RoundCount;
   else
      self.Sharpness = 0;
   end
end

function Update(self)

   if self.Magazine ~= nil then
      if self.loadedShell == false then
         self.Sharpness = self.Magazine.RoundCount;
      else
         self.loadedShell = false;
         self.Magazine.RoundCount = self.Sharpness + 1;
      end
   else
      self.reloadTimer:Reset();
      self.reloadCycle = true;
      self.loadedShell = true;
   end

   if self:IsActivated() then
      self.reloadCycle = false;
   end

   if self.reloadCycle == true and self.reloadTimer:IsPastSimMS(self.reloadDelay) and self:IsFull() == false then
      local actor = MovableMan:GetMOFromID(self.RootID);
      if MovableMan:IsActor(actor) then
         ToActor(actor):GetController():SetState(Controller.WEAPON_RELOAD,true);
      end
      self.reloadCycle = false;
   end

end

And
Code:
[code]function TSAGrenadeLauncherImpact(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Impact";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         gun.Sharpness = 0;
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end

function TSAGrenadeLauncherBounce(actor)
   local gun = ToAHuman(actor).EquippedItem;
   if gun ~= nil then
      local gun = ToHDFirearm(gun);
      local magSwitchName = "Magazine TSA GL Grenade Launcher Bounce";
      if gun.Magazine == nil or (gun.Magazine ~= nil and gun.Magazine.PresetName ~= magSwitchName) then
         gun.Sharpness = 0;
         gun:SetNextMagazineName(magSwitchName);
         gun:Reload();
      end
   end
end[/code]


Should do the trick.


Sat Nov 17, 2012 8:29 am
Profile

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things
Worked perfectly, thanks!


Sat Nov 17, 2012 8:36 am
Profile

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things
Need help with a gun's animation, modifying the muzzleoffset by 2 pixels, and showing the proper animation for which barrel fired.
Image
What it is doing.

Image
What I'd like it to do.


Is it even possible to script some LUA to move (and alternate) the muzzleoffset by 2?
How do I then tie the animation to that? Is it easiest to just have the animation restart each time, as well as the muzzleoffset?
I could use help scripting.. *clueless at programming*

Also.. is it possible to potentially flip the muzzleflash? Or would I have to use 2 separate instances? I may change the muzzleflash.. the shotgun flash on the end of it was just temporary really.


Tue Jan 01, 2013 6:23 pm
Profile
User avatar

Joined: Sun Jan 28, 2007 10:32 pm
Posts: 1609
Location: UK
Reply with quote
Post Re: A few small things
Your best bet would probably be to have the gun fire a null bullet with the same ballistic properties as the actual shells (for the AI) and spawn the actual projectile/muzzleflash/etc. in scripting. I think the Coalition Autocannon/Flak Cannon (or whichever dual-barrel BFG they have) has shots alternating between two barrels, so it should be possible.


Tue Jan 01, 2013 6:46 pm
Profile YIM

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things
The autocannon is magically doing it without lua -.-

Oh.. what.. The autocannon is actually just using a 6-frame muzzle flash, with a 2-frame shot animation (and a still), then it uses separation (and reasonable spread) to make the rounds appear to come out of the barrels at random.. It does a pretty decent job I suppose.

I don't know if that's the way I want to go on this though, I'd prefer that the bullet originate from the muzzle flash and just have the muzzleoffset alternate up and down by 2..

Please help.. I'm probably the worst programmer on the earth, otherwise I'd actually attempt this myself (which I did and failed hard.. getting error " bad argument #1 to 'mod' (number expected, got nil) ".

Basically what I'd like to do is one of two things... the first is determine how many rounds I have left, and if that number is a multiple of 2, use one muzzle offset, if not, use another.

The other idea is almost the same, but if I can't look up round count.. Check to see if a round has been loaded/shot - with a governing value (that, again, if it's a multiple of 2, use one muzzle offset), and change that value to a value that's not a multiple of 2 which will (hopefully) set it up for next time so that it triggers the other muzzle offset, and sets the governing value back to being a multiple of two.

Anyways I have no idea how to accomplish that with code.


Tue Jan 01, 2013 8:22 pm
Profile

Joined: Sun Jul 22, 2012 3:06 pm
Posts: 129
Reply with quote
Post Re: A few small things

(Quoting that because this is the problem I'm still at)

I tried to do what the autocannon does but I did some screen capture at 60fps and found that weapons only ever play anim 000 and 001. They never make it to 002..003..etc. Probably possible with lua but like I said in my last post I know nothing about programming. :P


Fri Jan 11, 2013 12:00 am
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13143
Location: Here
Reply with quote
Post Re: A few small things
The best way to do this is to animate an MO held in front of the gun rather than the sprite of the gun itself, but it'd be more trouble than it's worth in my opinion.


Wed Jan 16, 2013 3:19 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 12 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.054s | 17 Queries | GZIP : Off ]