全面战争:战锤2

全面战争:战锤2

26 个评价
Execute External Lua File (Modding Tool)
   
奖励
收藏
已收藏
取消收藏
标签: mod, Campaign
文件大小
发表于
更新日期
89.684 KB
2019 年 11 月 19 日 下午 3:29
2021 年 8 月 12 日 下午 12:31
9 项改动说明 ( 查看 )

订阅以下载
Execute External Lua File (Modding Tool)

在 prop joe 的 1 个合集中
Prop Joe Mods
58 件物品
描述
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 条留言
Lycia Pintella 2023 年 4 月 17 日 上午 1:31 
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 2022 年 5 月 24 日 下午 2:15 
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 2022 年 5 月 13 日 下午 7:40 
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  [作者] 2022 年 2 月 21 日 上午 3:39 
yes, whenever the workshop opens, nothing in this mod actually needs changing for WH3
JX83 2022 年 2 月 16 日 下午 8:44 
You gonna make this for 3?
Azade12 2021 年 8 月 12 日 下午 3:39 
i love you, pepe
prop joe  [作者] 2021 年 8 月 12 日 下午 12:43 
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  [作者] 2021 年 6 月 23 日 上午 10:44 
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  [作者] 2020 年 8 月 16 日 上午 10:53 
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 2020 年 8 月 15 日 下午 5:40 
PEPE FEELZ GOOD TO DESPOIL