Welcome to the Builder Academy

Question Objects from corpses

More
04 May 2018 04:23 - 04 May 2018 04:33 #8032 by JTP
Objects from corpses was created by JTP
Hmm ok atm it seems that when a corpse vanish, Then what ever objects was in it, is dropped on the Ground.

Result is messy rooms.

How Could it be made so that corpse and objects is purged, when the corpse vanish ?
Last edit: 04 May 2018 04:33 by JTP.

Please Log in or Create an account to join the conversation.

More
04 May 2018 11:42 - 04 May 2018 11:46 #8033 by lacrc
Replied by lacrc on topic Objects from corpses
Corpse timers are checked in limits.c in the point_update() function that is called every tick. More specifically here:
github.com/tbamud/tbamud/blob/master/src/limits.c#L419

You can make it so that items are not dropped on the ground and extracted by changing the code that is called when the corpse timer expires, it starts in this line:
github.com/tbamud/tbamud/blob/master/src/limits.c#L425

In the end you would have something like this:
Code:
if (!GET_OBJ_TIMER(j)) { if (j->carried_by) act("$p decays in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR); else if ((IN_ROOM(j) != NOWHERE) && (world[IN_ROOM(j)].people)) { act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_ROOM); act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_CHAR); } /* removed code that drops items on the ground from here the extract_obj(j) below will purge the corpse j with all objects inside */ extract_obj(j); }
Which would also make 2 variables (*jj and *next_thing2) unused so go ahead and remove their declarations from point_update().

I tested it (with just one corpse) and it worked. Hope it helps!
Last edit: 04 May 2018 11:46 by lacrc.

Please Log in or Create an account to join the conversation.

More
04 May 2018 12:14 - 04 May 2018 12:15 #8034 by JTP
Replied by JTP on topic Objects from corpses
So what If the char is carrying the corpse when it decays. What happends to the objects Then ?

Just came to think about player corpses, they would be mad If the objects is lost haha
Last edit: 04 May 2018 12:15 by JTP.

Please Log in or Create an account to join the conversation.

More
04 May 2018 12:49 - 04 May 2018 13:01 #8035 by lacrc
Replied by lacrc on topic Objects from corpses
Oh well I didn't consider that haha, in the example above they would be lost.
In that case, I think you can get away with a minor change extracting the item instead of dropping it on the room, but in the cases where the corpse is being carried or are inside a container no changes are made.
The code would be like this (it's a one line change from stock TBA code):
Code:
if (!GET_OBJ_TIMER(j)) { if (j->carried_by) act("$p decays in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR); else if ((IN_ROOM(j) != NOWHERE) && (world[IN_ROOM(j)].people)) { act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_ROOM); act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_CHAR); } for (jj = j->contains; jj; jj = next_thing2) { next_thing2 = jj->next_content; /* Next in inventory */ obj_from_obj(jj); if (j->in_obj) obj_to_obj(jj, j->in_obj); else if (j->carried_by) obj_to_room(jj, IN_ROOM(j->carried_by)); else if (IN_ROOM(j) != NOWHERE) extract_obj(jj); /* simply extract the obj <--- Change is here */ else core_dump(); } extract_obj(j); } }

But that would still make non-carried PC corpses (ie. a player died and didn't make their way back to their corpse in time) to lose their items when their corpse's timers expired.

A solution to that would be to somehow identify the corpses as being NPC or PC corpses, but that requires more changes in code and I'm not sure if it's worth or optimal though.

I would go about it like this, in fight.c look for the function make_corpse() and change this section as follows:
Code:
SET_BIT_AR(GET_OBJ_WEAR(corpse), ITEM_WEAR_TAKE); SET_BIT_AR(GET_OBJ_EXTRA(corpse), ITEM_NODONATE); GET_OBJ_VAL(corpse, 0) = 0; /* You can't store stuff in a corpse */ - GET_OBJ_VAL(corpse, 3) = 1; /* corpse identifier */ GET_OBJ_WEIGHT(corpse) = GET_WEIGHT(ch) + IS_CARRYING_W(ch); GET_OBJ_RENT(corpse) = 100000; - if (IS_NPC(ch)) + if (IS_NPC(ch)) { GET_OBJ_TIMER(corpse) = CONFIG_MAX_NPC_CORPSE_TIME; + GET_OBJ_VAL(corpse, 3) = 1; /* NPC corpse identifier */ - else + } else { GET_OBJ_TIMER(corpse) = CONFIG_MAX_PC_CORPSE_TIME; + GET_OBJ_VAL(corpse, 3) = 2; /* PC corpse identifier */ + }
That way NPC corpses will be identified with Value 3 = 1 and PC corpses would be Value 3 = 2.
(It says 3 in there but it's the 4th value, the count starts from 0, remember that! lol)

Then in the point_update() function in limits.c you check for this value to know if an object should be dropped on the ground or left in the corpse to be thrown away:
Code:
if (!GET_OBJ_TIMER(j)) { if (j->carried_by) act("$p decays in your hands.", FALSE, j->carried_by, j, 0, TO_CHAR); else if ((IN_ROOM(j) != NOWHERE) && (world[IN_ROOM(j)].people)) { act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_ROOM); act("A quivering horde of maggots consumes $p.", TRUE, world[IN_ROOM(j)].people, j, 0, TO_CHAR); } for (jj = j->contains; jj; jj = next_thing2) { next_thing2 = jj->next_content; /* Next in inventory */ obj_from_obj(jj); if (j->in_obj) obj_to_obj(jj, j->in_obj); else if (j->carried_by) obj_to_room(jj, IN_ROOM(j->carried_by)); else if (IN_ROOM(j) != NOWHERE) if (GET_OBJ_VAL(j, 3) == 2) /* PC corpse, drop objects in the room */ obj_to_room(jj, IN_ROOM(j)); else /* NPC corpse, extract obj */ extract_obj(jj); else core_dump(); } extract_obj(j); }
I won't be able to test those now so beware lol.
Last edit: 04 May 2018 13:01 by lacrc.

Please Log in or Create an account to join the conversation.

More
04 May 2018 15:23 #8036 by Sascha
Replied by Sascha on topic Objects from corpses
This sparked two additional thoughts from me.

1) Is there a way to set it so that PC corpses can't be taken/carried by players?

2) Has anyone made a snippet that moves the inventory of a PC's corpse to a location, such as a donation room, when it decays?

Will you stand against the coming Storm? After the Breaking: STORMRIDERS MUD - atbmud.dune.net port 4000

Please Log in or Create an account to join the conversation.

Time to create page: 0.205 seconds