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

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

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

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

Post 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?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

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

Post by lurker »

Are you adding to or replacing the stock weapondefs_post code? It has such nice features as: -- auto detect ota weapontypes
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

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

Post 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 :)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

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

Post by FLOZi »

You should read the S44 SVn log yuri, I had already fixed the exact same issue in S44. :P
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

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

Post 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 :)
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

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

Post 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.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6241
Joined: 29 Apr 2005, 01:14

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

Post 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.
User avatar
yuritch
Spring 1944 Developer
Posts: 1018
Joined: 11 Oct 2005, 07:18

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

Post 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).
Post Reply

Return to “Lua Scripts”