Game varaibles defines unit weapons

Game varaibles defines unit weapons

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

Moderator: Moderators

Post Reply
User avatar
smoke_th
Posts: 140
Joined: 25 May 2010, 13:15

Game varaibles defines unit weapons

Post by smoke_th »

Hi. I have a question there. I have a little section in my modoptions.lua

{
key = "mo_holylight",
name = "Weapon change",
desc = "Blah blah blah that unit gets another weapon",
type = "bool",
def = false,
section= "ba_options",
},

What will be if make in unittype file which not tdf but lua
example: http://pastebin.com/qFkNhyKK
this.
example http://pastebin.com/swniWvj2
It will work?
UPG: or i need make in begining of file something like this

local weapontype
iif (mo_holylight[true]) then weapontype = Machine_Gun else weapontype = rocket_barrage end
?
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Game varaibles defines unit weapons

Post by zwzsg »

You have to use the \gamedata\*def*.lua

It's complicated. A big trap for instance is that UnitDefs in there don't have the fields named the same as ingame.

In KP 4.0 I used that this create new units, with new weapons. You could try to copy my \gamedata\defs.lua and \gamedata\anydefs_post.lua then try to understand and rewrite my \gamedata\anydefs_post.lua

Good luck though.
User avatar
smoke_th
Posts: 140
Joined: 25 May 2010, 13:15

Re: Game varaibles defines unit weapons

Post by smoke_th »

zwzsg wrote:You have to use the \gamedata\*def*.lua

It's complicated. A big trap for instance is that UnitDefs in there don't have the fields named the same as ingame.

In KP 4.0 I used that this create new units, with new weapons. You could try to copy my \gamedata\defs.lua and \gamedata\anydefs_post.lua then try to understand and rewrite my \gamedata\anydefs_post.lua

Good luck though.
Thank you. :o
Now about what i'm making - now - because i can't contact with Zoy shooter dev i making new version of it. I think soon will be another questions but just take a look. (Now i developing respawn system.) http://img59.imageshack.us/img59/583/screen00034.png
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: Game varaibles defines unit weapons

Post by zwzsg »

In the \gamedata\ of KP 4.0:

The file defs.lua is a modification of the default defs.lua, that instead of forcing you to seperate the modificationof features, units, and weapons, let you modify all three of them in a single file, anydefs_post.lua. You don't have to read and understand defs.lua, just now that it's not the default one, and that's it's required if you want all pre-game weapons/units/features modifications to be in a single file.

The anydefs_post.lua implements the modification I wanted for KP.

The first bit is because those files are also called by unitsync, for instance when you open a battleroom, it needs to know the list of units, but yet modoptions are not set, so calling Spring.GetModOptions()["ons"] for instance would cause an error.

The bit about the shield and ONS does that:
When the "ons" mod option is set, for all units, it replace all weapons slots that have "homebaseshieldgood", "homebaseshieldbad", "minifacshieldgood", "minifacshieldbad" by the weapon in fakeWeapon. The weapon in fakeWeapon (which I named like that because for my purpose I wanted a no weapon) is is either nil (possibly causing some weirdness in weapon orders), or the first weapon of that unit if that unit first weapon is called "BuildLaser". So it almost does what you want. Except that to get the name of the new weapon, you can't just look into the first weapon slot of the unit, you have to instead scan all weapons, independantly of any unit.

The bit about heroes create heroes from the unit listed in homf_from, that is, it copy paste the unitdef of those units, but buffing many stats in the meantime. In particular, I wanted to buff weapons. And for that, I have to create new weapons, that are copy of the original weapons except with buffed stats.

The last bit just add those new heroes units to some buildmenu, irrelevant to you.

Oh, and another trick, is that when talking about what weapons a unit sports, there are two levels: A first level is specifically tied to one unit type and contains stuff like angle of fire and target preference, and the second level is the rest of the weapon stats, this time shared amongst every unit types sporting the same weapon.
Post Reply

Return to “Lua Scripts”