I have a script that reloads a gun (instantly) between the first few shots to enable the ability to change the magazine of the gun.
The gun works perfectly well as intended, until you let an AI try to shoot it.
The AI simply fires the first shot repeatedly at the lowest fire rate available. Is there any way to get the AI to actually do the equivalent of holding down the trigger even through reloads?
Would it be possible to attach such an AI change to a gun?
More reasonably, is there a way to change the magazine without reloading?
I've included the relevant code here for your perusal if you care to.
Code:
function Update(self) if self.Magazine ~= nil then if (self:DoneReloading()) then if (self.ammoKeep) then self.Magazine.RoundCount = self.ammoCounter; self.ammoKeep = false; end self.ReloadTime = self.storedReload; end
--there's code here that changes the fire rate as the weapon fires; I don't think it's terribly relevant to include.
SetMag(self); end end
function SetMag(self) if self ~= nil then if (self.Magazine.RoundCount <= 0 or self.Magazine.RoundCount > self.Magazine.Capacity) then -- if we need to reload self:SetNextMagazineName("Magazine Kohm 1"); -- reload and revert magazine self:Reload(); else local magSwitchName = "Magazine Kohm " .. math.min(self.shotsPerBurst, self.shotsMaxPerBurst); -- set the destination magazine based on escalating fire rate if self.Magazine == nil or (self.Magazine ~= nil and self.Magazine.PresetName ~= magSwitchName) then -- if we have a magazine that's not the destination magazine self:SetNextMagazineName(magSwitchName); -- set destination mag to next self.ReloadTime = 0; -- make sure the reload time won't be an issue self.ammoKeep = true; -- make sure we store the ammo and restore it to the original value self:Reload(); -- horse reload --self:Activate(); -- My first try to make the AI think everything was ok end end end end
Last edited by Visage on Wed Jun 10, 2015 9:26 am, edited 1 time in total.
Tue Jun 09, 2015 11:44 am
Arcalane
Joined: Sun Jan 28, 2007 10:32 pm Posts: 1609 Location: UK
Re: Forcing the AI to go full auto
You're probably better off using a dummy mag+ammo and spawning the projectiles as a function of the script itself. That way the AI should behave itself and you don't need to do weird stuff with reloading.
Tue Jun 09, 2015 1:43 pm
Visage
Joined: Fri Jul 06, 2012 7:20 am Posts: 44
Re: Forcing the AI to go full auto
Thanks.
After derping around a bit, I managed to get it to work, so I think I'll mark it as solved.
On a related note, though, how do I credit Lua stolen from vanilla content?
Wed Jun 10, 2015 9:25 am
TheLastBanana
DRL Developer
Joined: Wed Dec 13, 2006 5:27 am Posts: 3138 Location: A little south and a lot west of Moscow
Re: Forcing the AI to go full auto [SOLVED]
You could include a comment that says what file it came from. Personally I've never really cared if people steal my scripts from vanilla content, though like 95% of the Lua scripts in the game probably aren't mine anymore, so take that with a grain of salt.
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