Project Zomboid

Project Zomboid

Crowbar as a Short spear
・・ 19 Aug, 2023 @ 5:39pm
Hotkey Implementation
I've implemented toggling between blunt and spear modes via a hotkey.

The code:
https://pastebin.com/Z4WT0e7H
Save as CrowbarSpearToggle.lua and put in Stabwithcrowbarbase\Media\lua\client

The keys are E (Hold Ctrl) or J (Just press) by default.
Tested with Brutal Handwork which also uses Ctrl + E, works perfectly.


Also the translation:
UI_EN = { UI_optionscreen_binding_CrowbarSpear = "Crowbar Spear Toggle", UI_optionscreen_binding_CrowbarSpear_ToggleModifier = "Modifier Key", UI_optionscreen_binding_CrowbarSpear_HoldToggle = "Change crowbar grip (if holding the modifier)", UI_optionscreen_binding_CrowbarSpear_Toggle = "Change crowbar grip (just press)", }
Save as UI_EN.txt and put it in Stabwithcrowbarbase\Media\lua\shared\Translate\EN
< >
Showing 1-11 of 11 comments
Nik  [developer] 20 Aug, 2023 @ 2:51pm 
Honestly i have not expected this. Will try it out and add it, or if you want you could Upload it and i'd link it in description if you want. I kinda wanted to add it at some point, but my lua knowledge is basicly non existent, but i hope to get to learning it at some point, non the less Thanks for your hard work. (Took me some time to respond as i don't get notifications about new discussions on my mods)
・・ 21 Aug, 2023 @ 2:04am 
Would love to see it added.

As for the lua knowledge, same😂
I just looked how the other mods or the game itself do it.
The ISCraftAction class used to perform the crafting here is not present in the official modding reference, I've found it by searching in files in ProjectZomboid\media\lua for RecipeManager.PerformMakeItem to see how to handle it properly since it didn't work by itself.
・・ 21 Aug, 2023 @ 12:04pm 
By the way, I feel like it would be better to remove Common Sense hard dependency and make it optional.

To do this, add getActivatedMods():contains("BB_CommonSense") check before calling CommonSense.AddPryingTool.

Full Commonsensecomp.lua code:
function ExtendToCommonSense() if getActivatedMods():contains("BB_CommonSense") then CommonSense.AddPryingTool("Crowbarspear.Crowbarspear") end end Events.OnGameStart.Add(ExtendToCommonSense)
Nik  [developer] 22 Aug, 2023 @ 9:08am 
Originally posted by ・・:
I've implemented toggling between blunt and spear modes via a hotkey.

The code:
https://pastebin.com/Z4WT0e7H
Save as CrowbarSpearToggle.lua and put in Stabwithcrowbarbase\Media\lua\client

The keys are E (Hold Ctrl) or J (Just press) by default.
Tested with Brutal Handwork which also uses Ctrl + E, works perfectly.


Also the translation:
UI_EN = { UI_optionscreen_binding_CrowbarSpear = "Crowbar Spear Toggle", UI_optionscreen_binding_CrowbarSpear_ToggleModifier = "Modifier Key", UI_optionscreen_binding_CrowbarSpear_HoldToggle = "Change crowbar grip (if holding the modifier)", UI_optionscreen_binding_CrowbarSpear_Toggle = "Change crowbar grip (just press)", }
Save as UI_EN.txt and put it in Stabwithcrowbarbase\Media\lua\shared\Translate\EN

While it works perfectly for base mod or other submod if properly edited if single mod is enabled, i can't figure out how to make it so if all 3 submods are enabled and make it work with each other.
・・ 22 Aug, 2023 @ 10:03am 
You mean it doesn't work with Freeman's Crowbar and Tools of The Trade crowbars?
It's hardcoded to use the base mod recipe, but you should be able to repeat the same code for the other crowbars, just change the ids.

I don't use those mods myself, but I can add compatibility if you want.
Nik  [developer] 22 Aug, 2023 @ 10:13am 
Sorry if it takes me a long time to implement a feature you've pretty much made all by yourself. I usually try to learn how the code operates and learn from it to use it in feature. I might've found a solution to my problem, but i need to test it first.
Nik  [developer] 25 Aug, 2023 @ 10:22am 
Originally posted by ・・:
You mean it doesn't work with Freeman's Crowbar and Tools of The Trade crowbars?
It's hardcoded to use the base mod recipe, but you should be able to repeat the same code for the other crowbars, just change the ids.

I don't use those mods myself, but I can add compatibility if you want.
After some trials and errors i've managed to make it work with all supported crowbar mods, both when all are enabled and when only one is. The code you provides was such a big help as it opens ways for more mod ideas. I really appreciate it and thank you for that.
・・ 25 Aug, 2023 @ 2:57pm 
Originally posted by realnik10:
After some trials and errors i've managed to make it work with all supported crowbar mods, both when all are enabled and when only one is. The code you provides was such a big help as it opens ways for more mod ideas. I really appreciate it and thank you for that.

That's very nice. I'm glad it opens new possibilities for you.

Btw my real nickname is Mercencium. (Please use it for references)
I'm almost ready to release two mods, each adding a cool little trait that can change the way you play the game! For the first one I need to rework an old system and for the other I'm waiting for the perk icon from an artist.


Also if you missed
Originally posted by ・・:
I feel like it would be better to remove Common Sense hard dependency and make it optional.

To do this, add getActivatedMods():contains("BB_CommonSense") check before calling CommonSense.AddPryingTool.

Full Commonsensecomp.lua code:
function ExtendToCommonSense() if getActivatedMods():contains("BB_CommonSense") then CommonSense.AddPryingTool("Crowbarspear.Crowbarspear") end end Events.OnGameStart.Add(ExtendToCommonSense)
The context: I didn't activate Common Sense when I was working on hotkey implementation and it always gave me an error at the start of a save.
If you still want to keep it as hard dependency, please add require=BB_CommonSense to the mod.info so that it's displayed in the game and Mod Manager could enable it automatically.
Nik  [developer] 26 Aug, 2023 @ 12:00am 
I did that and it did not cause any errors for me when i disabled CS. Is it still the cause for you after the patch?
・・ 26 Aug, 2023 @ 1:51am 
Oh I see, nice, all works fine. It's still marked as required in the workshop page though?
Last edited by ・・; 26 Aug, 2023 @ 1:53am
Nik  [developer] 26 Aug, 2023 @ 1:54am 
Originally posted by ・・:
Oh I see, nice, all works fine. It's still marked as required in the workshop page though?
Good point, changed it.
< >
Showing 1-11 of 11 comments
Per page: 1530 50