Total War: WARHAMMER II

Total War: WARHAMMER II

26 ratings
Execute External Lua File (Modding Tool)
   
Award
Favorite
Favorited
Unfavorite
Tags: mod, Campaign
File Size
Posted
Updated
89.684 KB
Nov 19, 2019 @ 3:29pm
Aug 12, 2021 @ 12:31pm
9 Change Notes ( view )

Subscribe to download
Execute External Lua File (Modding Tool)

In 1 collection by prop joe
Prop Joe Mods
58 items
Description
Executes a Lua script when you press F9, with the goal of assisting modders during script development. Still works and it's not outdated, not gonna bother updating it for no reason every patch.

First you need to manually create the actual file the mod will use: create a file named exec.lua inside steamapps\common\Total War WARHAMMER II

Paste this inside the file:
cm:treasury_mod(cm:get_local_faction_name(), 10000)
and if you have the mod enabled and press F9 ingame, the script will run and you will get 10000 gold.
Every time you press F9 the script gets run again and you get more gold every time you re-run the script.

The goal of this mod, however, is not cheating in gold, but allowing for faster development of scripts.
The general idea is to move all of the scripting during development into external files, outside of packs. Put the scripts into packs when you serve the mod to the users.
Once the mod gets released you can also just isolate specific functions or listeners from your mods to modify and test.

I'll try updating this introduction so you can see what I mean, more here:
https://gist.github.com/Shazbot/a49b438bef8ae2bb246334198e1ef475

Note you have to have F9 bound to "View camera bookmark 1" in the controls in the options, but it should be bound by default.

Other mods of interest to modders:
Draw Debug Logs allows you to print out Lua types onto the screen for debugging, you can also dump things into a file.
Script Debug Activator also allows you to get feedback from your scripts using out.
The Modding DevTool Console mod also allows you to run code ingame, but has some quirks due to using the ingame textbox.

You can find the scripting docs here[chadvandy.github.io].

My other guide on Lua WH2 modding.[shazbot.github.io]

Change Log:
12.08.2021.
Added exec_frontend.lua that gets executed when you press the chat button in the frontend. Note that callback doesn't work in the frontend, but you can use real_timer to delay stuff in the frontend.
This snippet will dump the UI after a 5 sec delay:
https://gist.github.com/Shazbot/edb8a3af536e35c030c1c29f46d5b800

16.08. 2020.
Added exec_first_tick.lua.lua that gets auto-executed inside a cm:add_first_tick_callback, so you can test stuff that would get run through that. Don't forget stuff you put there stays there on every campaign load.

04.02.
added support for in-battle scripts using exec_battle.lua that runs when you press F9, credits to ShadowCX for helping getting it to work

Older:
Now also supports an additional file exec2.lua that gets executed with F10.
Also, if the mod doesn't find exec.lua inside the Total War WARHAMMER II folder it will also check Total War WARHAMMER II/exec/exec.lua.
So basically you can put exec.lua and exec2.lua inside an intermediate exec folder so things are better structured. But you don't have to.
40 Comments
Lycia Pintella Apr 17, 2023 @ 1:31am 
I thought if we put our lua files under mods/script in the game folder they would be able to run (ofc they have to be under the right campaign etc right?) and I can run modded alarielle code with her filename just fine that way, but when I try to run custom stuff I get no result at all. Any ideas?
DudeChris33 May 24, 2022 @ 2:15pm 
Is this reverse compatible with other Total War games? Obviously the individual lua files you want to execute would need to be changed depending on the game but would the mod still work in them or does it reference TWW2-specific things.
madocs May 13, 2022 @ 7:40pm 
this isn't working: my lua file... any ideas?

add_bunch_of_ancies = function()
local ancies = {
"wh2_dlc10_anc_talisman_shieldstone_of_isha",
"wh2_dlc15_anc_weapon_star_lance", }
local f_obj = cm:get_faction(cm:get_local_faction_name(true))

for _, anci in ipairs(ancies) do
cm:add_ancillary_to_faction(f_obj, anci, false)
end
end

addsometraits = function()

if not mod.char_cqi then return end
local char = cm:get_character_by_cqi(mod.char_cqi)
if not char or char:is_null_interface() then return end

cm:force_add_trait(cm:char_lookup_str(char), "wh2_dlc15_trait_dragon_moon_imrik", true, 1, true)
cm:force_add_trait(cm:char_lookup_str(char), "wh2_dlc15_trait_dragon_star_imrik", true, 1, true)

end
prop joe  [author] Feb 21, 2022 @ 3:39am 
yes, whenever the workshop opens, nothing in this mod actually needs changing for WH3
JX83 Feb 16, 2022 @ 8:44pm 
You gonna make this for 3?
Azade12 Aug 12, 2021 @ 3:39pm 
i love you, pepe
prop joe  [author] Aug 12, 2021 @ 12:43pm 
Updated:
Added exec_frontend.lua that gets executed when you press the chat button in the frontend. Note that callback doesn't work in the frontend, but you can use real_timer to delay stuff in the frontend.
This will dump the UI after a 5 sec delay: https://gist.github.com/Shazbot/edb8a3af536e35c030c1c29f46d5b800
prop joe  [author] Jun 23, 2021 @ 10:44am 
Updated:
Added some error catching code that will catch errors inside callbacks and listeners, that would otherwise cause a script break. I have this in my script mods but it's now included here as well since it should be very useful just for people writing scripts as well.
prop joe  [author] Aug 16, 2020 @ 10:53am 
Added exec_first_tick.lua.lua that gets auto-executed inside a cm:add_first_tick_callback, so you can test stuff that goes in there.
Azade12 Aug 15, 2020 @ 5:40pm 
PEPE FEELZ GOOD TO DESPOIL