NerdanelVampire: For some time I've been wanting to implement monsters that drop something other than a normal corpse. I want to make plant monsters drop plant remains that are suitable for vegetarian characters. This isn't really supported, so I've had to get hacky. Getting SV_PLANT_CORPSE defined was a megahack in itself, but now I've run into a problem.

How can I turn an existing item into another?

This is my hook. I've checked that it gets executed, but it doesn't do enough if it does anything at all - actually since when I try to reroll such a corpse it stays a corpse, I suspect it doesn't do anything. In addition to the sval, I also need to change at least the item's name (tricky since we're talking about corpses here...), color, and description.

hook(hook.CORPSE_CREATE_POST, function(obj,mon) 
        if mon.flags[FLAG_PLANT] then
                obj.sval = SV_CORPSE_PLANT
        end
end)

There also exist a HOOK_CORPSE_CREATE_PRE, but I don't think it does what I want...?

BucketMan: I'm not sure the above hook will do what you want. Changing SVAL's for already created objects is possible, but may sometimes generate strange results. In Dragonball T I have a similar situation for mechanical creatures that need to drop mechanical bodies instead of corpses. My solution was to forbid the engine from creating corpses for these monsters and make one myself of the correct TV/SV. Try something like this:

hook(hook.DO_DROP_CORPSE,
   function(m_ptr)
      if monst.flags[FLAG_DBT_FORCE_NO_CORPSE] then
         -- note that the monst object is available from within this hook
         -- if you want it, even though you don't see it declared.
         return false
      elseif m_ptr.flags[FLAG_DBT_FORCE_NO_CORPSE] then
         -- Though most likely you won't need it, so you can check
         -- the race rather than the specific monster for the flags
         -- you care about. Create and drop your corpse here.
         return false
      end
   end
end)

Also, note that the 'monst' object is available within this hook.

NerdanelVampire: I'm going to take a look at Dragonball T then to see how corpses are created.

NerdanelVampire: Hmm, it appears that Dragonball T doesn't have the android corpses implemented yet, and normal corpse generation is in the C code, which means I have no model for [plant] corpse creation. At this point it looks like it'd probably be easier or about the same just to change the type of the corpse, which brings us back where we started.

Instead of TV_CORPSE, SV_CORPSE_CORPSE, I need to get a TV_CORPSE, SV_CORPSE_PLANT which is made based on the right creature, so that say, a "phantom lily corpse" becomes "phantom lily plant remains". But how to do it?

DarkGod: You need to change two things, the sval as you do AND the k_idx which is the id of the corresponding item in k_info (the C index, so lua's index -1). You can easily find by this way: obj.k_idx = lookup_kind(TV_FOO, SV_BAR)

NerdanelVampire: Thanks! One more thing I need to fix: how to change the color to color.OLIVE_DRAB from color.LIGHT_UMBER according what I have specified in the item files? obj doesn't have a field called color. Also the code instists on adding "a" in front of my plural form remains so I think I'll have to do something about that too.

(And by the way, I've been wondering why ToME 3 bugs get assigned and T-Engine bugs don't even get marked as new..? And is alpha18 coming soon? :))

Module Developers Discussion/Turning item into another item (last edited 2008-01-16 16:53:44 by NerdanelVampire)