I was recently looking around in the json files, when I decided I’d like to add some new items, which in turn led me to wanting to create new iuse functions for a mod, without having to do any compiling or anything of that sort. Is there a way I can add a file to the mod’s folder that loads the new function? If it helps, I’d just like to copy the manhack’s script, so I could add a craftable item to spawn custom robots. I’m not a coder, so I’m don’t know what I could add, if anything, to make this work. Sorry in advance if something is unclear. Any help would be appreciated.
If you’re adding new gear, you’re going to need to write up the iuse in C++ and compile it. The RC car mod has its iuses in main, and the items in modpack.
I may just end up compiling it, then, and thank you for the reply.
You can create lua iuse’s, though there’s not much documentation on that currently. I also don’t think there’s a lua API to spawn stuff yet(I probably should fix that…).
Is there some sort of template I could get for the lua iuse, even if it is limited to not being able to spawn things?
The slow/fast zombie mods use lua to manipulate monster stats. I don’t recall if there’s a lua iuse anywhere, look through the mods folder for files with .lua extensions.
I’ve already taken a look through the mods, and I’ve used a lot of the available files for what I already have, but it seems the fast/slow zombies mods are the only ones that have .lua files.
I’ll see about writing an iuse example soon™.
Okay, done. You’ll have to wait for the PR to land though, and then you’ll need to use latest experimental.
Thanks for all of the help and replies so quickly, I’ll be sure to get this as soon as I can.
Now that I’ve done some more experimenting, I’d like to ask something more: How would I go about adding more of these entries? I’ve successfully implemented a new iuse, but don’t understand anything about lua, and was wondering if I could do this with the addition of more files or should I modify the file I’m currently using?
You can just copy the whole file contents into the same file, and modify the name of the lua function and the name of the IUSE in the second instance.
Thank you for the help and quick response. I still have two questions, though. How do I make the spawned monsters friendly, or at least non-hostile, and after the item is used it remains in the inventory, but I’d like it to delete itself.
Call monster:make_friendly() after creating the monster.
Hm, strange that the item isn’t consumed. return 1 should tell the caller of the IUSE that one charge of the item should be used, but I may have misunderstood.
[quote=“CIB, post:14, topic:6811”]Call monster:make_friendly() after creating the monster.
Hm, strange that the item isn’t consumed. return 1 should tell the caller of the IUSE that one charge of the item should be used, but I may have misunderstood.[/quote]
Quickhit, haven’t looked at the specific code in question: returning 1 can be misinterpreted as returning “true”; we had a weird bug with that a few days ago elsewhere in the code. No idea if that’s the problem here, but throwing it out.
I’ve added the line that makes the new spawned monsters friendly, but this effect expires not too long after I’ve used the tool, creating the monster. I’m not exactly sure if the effect wears off after a period of time, or when line of sight is broken, but I don’t know what causes it, and I don’t know how I could fix it.
Try monster.friendly = -1, then.
Setting monster friendly to -1 worked perfectly, thank you.