Custom death event using LUA?

As said, I want to get some help from creating a custom death function with .LUA file. Can someone tell me how its done?

Thanks :slight_smile:

Do you want to use LUA to make something happen when a creature dies, or do you want to add a new function to LUA? The second is kind of documented in doc/LUA_SUPPORT.md.

I’ve been reading it everytime, but nothing really happpens :frowning:
Its hard for me to understand, tbh.

Again, what you even trying to do? Depending on your goal, LUA may not even be the right solution.

I want to make a modified death function that spawns a secondary creature after death of the primary. It is similar to “THING” death function in pattern of:

tentacle dog > thing
primary > secondary

I have no idea how can I make the code into a .LUA file

Ah, okay. I thought you might be able to do this in JSON, but death spawn is hard coded to WORMS and BLOB and there’s no generic C++ function.

I don’t know LUA very well, but afaict there isn’t an “on_death” trigger.

Personally, since I’m an okay C++ programmer, I’d submit a patch to add some new optional JSON to a MONSTER, something like this:

"death_spawn": {                       // optional death spawn
    "spawn_id": "death_dog",           // mandatory spawn
    "number": [ 2, 2],                 // mandatory range of spawns, in this case 2 to 2
    "death_msg": "<number> <spawnname> crawl out of <name>'s corpse", // mandatory death message
    "only_death_msg": "The <name> splits in <number>", // optional death message if this the only death event
    "terrain": [ "DIGGABLE" ]          // optional TERRAIN flags to limit spawn points
},

and then convert WORMS and mondeath::worm() to the use the new death_spawn object. And then add your tentacle dog.

Unfortunately, despite ZhilkinSerg’s efforts, the use of LUA in CDDA is poorly documented. You might try asking him on the discord channel for advice.

I’ll try that. and thanks for that advice :smiley:

One last question… And I apologize for being an info-hungry guy.
So, “reproduction” even exist in-game? I’ve been trying it with this guide from the source code:

 //Reproduction
    if( jo.has_member( "reproduction" ) ) {
        JsonObject repro = jo.get_object( "reproduction" );
        optional( repro, was_loaded, "baby_count", baby_count, -1 );
        optional( repro, was_loaded, "baby_timer", baby_timer, -1 );
        optional( repro, was_loaded, "baby_monster", baby_monster, auto_flags_reader<mtype_id> {},
                  mtype_id::NULL_ID() );
        optional( repro, was_loaded, "baby_egg", baby_egg, auto_flags_reader<itype_id> {},
                  "null" );
        if( jo.has_member( "baby_flags" ) ) {
            baby_flags.clear();
            JsonArray baby_tags = jo.get_array( "baby_flags" );
            while( baby_tags.has_more() ) {
                baby_flags.push_back( baby_tags.next_string() );
            }
        }
        reproduces = true;
    }

I did this one:

{
 {
"reproduction": {
"baby_monster": "mon_insect_saddler_baby",
"baby_count": 1,
"baby_timer": 32 }
 }
}

Nothing really occurs, or something is not right with the .JSON code :confused:

Reproduction is a thing, but I think the baby timer is in days so you’ll have to wait a while for your baby insect. Also, you need to add the reproduction object to a specific monster. See data/json/monsters/mammal.json for the bear (mon_bear) and bear cub (mon_bear_cub).

But if you play the game and live for a couple of weeks, you’ll see baby chickens and deer fawns and puppies all over the place.

Thanks, I thought the timer is calculated as seconds :smile: