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

unit_cannot_Damage_unit.lua

11 posts, 838 views
Post comment
Filter:    Player:  
sort
5 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
5 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
3 years ago
Two years later...

Everything worked fine and I really enjoyed Zero-k. Now I'm back with a new computer and a new install. I've reproduced everything as best as I can remember and with the help of this thread. My mod is working in skirmish but the changes I made do not show up in the campaign. Can anyone tell me how to get the campaign to load modified LUA files?
+0 / -0


3 years ago
The campaign runs base ZK, not mods. You can't add on a gadget to a game without making a mod. To run a mod in the campaign you would have to edit the campaign launcher in the menu. Ask around in #modding on Discord.

https://zero-k.info/mediawiki/index.php?title=Developing#Modifying_the_lobby_menu
+0 / -0

3 years ago
Doesn't the campaign run whatever is set to default in the developer lobby settings? When I was tinkering with a wild Dev branch I think those things would be in effect in campaign games.
+0 / -0
3 years ago
When implementing the GadgetHandler callins for the nuke target indicator, I locally set the stockpile time and cost of a nuke to be one second and free. This was to make it easier for testing. I forgot about this for a while.

Some time later, I played the campaign mission that takes place on Delta Seige Dry. The AI has a Trinity, and periodically tries to nuke you.

Circuit isn't quite as trigger happy a human would be, given a limitless supply of free nukes. Still, it wasn't too far off, and it made for a pretty memorable experience.



tl;dr: in an appropriately configured dev mode lobby, the campaign will happily run off your local repo in whatever state it happens to be in
+2 / -0


3 years ago
quote:
Doesn't the campaign run whatever is set to default in the developer lobby settings? When I was tinkering with a wild Dev branch I think those things would be in effect in campaign games.

Yes, but "whatever" is a singleplayer mode, not a mod. The developer singleplayer mode runs Zero-K $VERSION, which is what you get from cloning the game repository. Running a mod would require editing or creating a singleplayer mode which runs it.
+0 / -0
3 years ago
>> Doesn't the campaign run whatever is set to default in the developer lobby settings? When I was tinkering with a wild Dev branch I think those things would be in effect in campaign games.

Yes, I believe this is what I did before. I have the dev mode set but the only options in the singleplayer dropdown menu are "Generic", "Zero-K", and "Zero-k Dev". How do I create another one and point it to local lua files?
+0 / -0


3 years ago
Duplicate zkdev from here https://github.com/ZeroK-RTS/Chobby/tree/master/LuaMenu/configs/gameConfig

You may need to add a value to the dropdown option. Do this by searching the files for the name of one of the options.
+0 / -0