Page 1 of 1

weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 02 Nov 2008, 20:45
by yuritch
I have this in my weapondefs_post.lua (minus comments):

Code: Select all

local modOptions
if (Spring.GetModOptions) then
  modOptions = Spring.GetModOptions()
end
-- Range Multiplier
if (modOptions and modOptions.weapon_range_mult) then
  local totalWeapons
  totalWeapons = 0
  local rangeCoeff
  rangeCoeff = modOptions.weapon_range_mult
  Spring.Echo("Starting weapon range multiplying, coefficient: "..rangeCoeff)
  for name in pairs(WeaponDefs) do
    local curRange = WeaponDefs[name].range
    if (curRange) then
      WeaponDefs[name].range = curRange * rangeCoeff
      totalWeapons = totalWeapons + 1
    end
  end
  Spring.Echo("Done with the ranges, "..totalWeapons.." weapons processed.")
end
This multiplies all the weapon ranges in the mod by a set factor (configurable via mod options as weapon_range_mult). Or at least it did that in 0.76. Now (0.77b5) it just breaks weapons in strange ways. For example, all the beamlasers just refuse to fire (they remain in 'Aiming' state indefinitely and cannot be fired even while using FPS mode), and most other weapons become ballistic (those that originally weren't, like missiles). I'm sure the problem is somewhere in that piece of lua, as if I remove that file from the mod, all is fine (but the ranges are not changeable anymore of course). So, does anyone have an idea what is wrong here?

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 02 Nov 2008, 21:21
by lurker
Are you adding to or replacing the stock weapondefs_post code? It has such nice features as: -- auto detect ota weapontypes

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 02 Nov 2008, 22:27
by yuritch
Hmm. Yes, looks like I replaced it. Haven't noticed there's a stock weapondefs_post.lua in springcontent... Ok, I'll redo my script to use the stock file content first and my function after that. Thanks.
Tested, and now it works. Until the stock file changes again that is :)

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 03 Nov 2008, 01:04
by FLOZi
You should read the S44 SVn log yuri, I had already fixed the exact same issue in S44. :P

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 03 Nov 2008, 07:59
by yuritch
Well, at least this forced me (while looking for a cause of this problem) to look through all the weapon files and remove lots of unused tags from there. So it had some good side effect, too :)

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 03 Nov 2008, 17:24
by Pxtl
yuritch wrote:Hmm. Yes, looks like I replaced it. Haven't noticed there's a stock weapondefs_post.lua in springcontent... Ok, I'll redo my script to use the stock file content first and my function after that. Thanks.
Tested, and now it works. Until the stock file changes again that is :)
How do you do that? I've been putting off updating Hardcore Annihilation, but HC uses a unidefs_post, so it probably will have a similar issue.

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 03 Nov 2008, 18:28
by FLOZi
Or not. Some OTA-tag weapon parsing code was moved from the engine to the default weapondefs_post.lua, hence the need to include that code if still using those OTA tags. AFAIK nothing has been done along the same lines with unitdefs.

Re: weapondefs_post.lua that works in 0.76, but not in 0.77b5

Posted: 04 Nov 2008, 07:29
by yuritch
Pxtl wrote:How do you do that? I've been putting off updating Hardcore Annihilation, but HC uses a unidefs_post, so it probably will have a similar issue.
It's very simple. You just copy the stock file into your mod and append your script to it so that stock lua runs first, then your code. I'm not sure if there is any need to do that with unitdefs_post however, but there may be in some future version (there wasn't a need for a weapondefs_post in previous release).