Loading...
  OR  Zero-K Name:    Password:   

unit_cannot_Damage_unit.lua

4 posts, 286 views
Post comment
Filter:    Player:  
sort
6 years ago

Hi.


I'm interested in making a modded game where I can multiply the damage of all units by a certain amount (including different values for different AI players or teams). Looking through the code I saw unit_cannot_damage_unit.lua in Luarules\gadgets. This file either returns zero or the damage amount after checking if unit A can damage unit B. Would this be the correct place to put my code to multiply damage?

Second question: Do Lua scripts need to be compiled for the game to read them? Where would I put the modified lua file after editing it?
+0 / -0
quote:
Do Lua scripts need to be compiled for the game to read them?

You don't need to compile Lua scripts, the engine interprets them.

quote:
Where would I put the modified lua file after editing it?

In the gadgets folder. Check out http://zero-k.info/mediawiki/index.php?title=Mod_Creation for info on what goes where and how to set up a local development copy.

quote:
Would <unit_cannot_damage_unit.lua> be the correct place to put my code to multiply damage?

That gadget is for relationships between two units (in particular Starlight and Glint) so it would probably be ideal to make a new gadget.

Damage modification is specific though because it is part of unit definitions which can be post-processed, see the `gamedata/{weapon,unit}defs_post.lua`. In particular check their contents for `damagemult` - this is an old modoption that acted as a general multiplier for most damage sources (caveats: didn't affect environmental damage and wasn't configurable per-team), it was removed because `hpmult` does the same but if you're messing around in your local copy might as well try it out.
+0 / -0
6 years ago
Thank you. That helps quite a bit.

So I installed the sample mod but it doesn't have any "Gadgets" folder. I'm assuming I copy the source code directory structure so I made \LuaRules\Gadgets under the mode name folder (LuaRules is at the same level as Units).

If that's correct then I just need to create my lua file and stick it in there, right? How does the engine know when to call the method I will write? Is there a mod 3example that creates widgets?
+0 / -0
quote:
So I installed the sample mod but it doesn't have any "Gadgets" folder. I'm assuming I copy the source code directory structure so I made \LuaRules\Gadgets under the mode name folder (LuaRules is at the same level as Units).

Yes.

quote:
If that's correct then I just need to create my lua file and stick it in there, right?

Yes.

quote:
How does the engine know when to call the method I will write?

Events. For starters look at other gadgets' code, specifically search for methods defined in `gadget:`. For example in `unit_cannot_damage_unit.lua` you can see the method is called `gadget:UnitPreDamaged` which is the event for when unit is damaged.

quote:
Is there a mod 3example that creates widgets?

I assume by "mod" you mean a client-side piece of code and by "widgets" you mean GUI panels (unfortunately, in the Spring engine world, "widget" is the term for "clientside mod" as originally they were meant for GUI panels, but have since evolved to do various other tasks, for example automating unit orders).

I don't think there are any tutorial examples for those but you can look through the widgets provided in the game repository, this contains almost the entire default ZK GUI. Check out `LuaUI/Widgets`, especially the ones with names `gui_chili_*.lua` as Chili is our framework for working with GUI panels. These are also event based, like gadgets.
+0 / -0