I looked around the forums and couldn't find any on the topic but maybe i just didn't see it. When a player dies it moves there items to the corpse right, inv, and everything they are wearing... now what I want it to do is not to take woren items just items you were holding... how would I do this?
Corpse making
Posted by Metsuro on Thu 06 Jul 2006 04:08 AM — 35 posts, 109,103 views.
In make_corpse (I think), just have an ifcheck if the item is being worn, then put the item into the corpse.
I was looking at like th dbsc source and found this.
but in dbsc they only use inv like I want... however trying to use the obj->wear_loc != -1 only seems to create a problem where the item is removed from you, and is just deleted or lost somewhere.
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if (!IS_NPC(ch) && obj->wear_loc != -1)
continue;
obj_from_char( obj );
if( obj->item_type == ITEM_DRAGONBALL )
{
obj_to_room(obj,ch->in_room);
continue;
}
if ( (!IS_NPC(ch) && IS_OBJ_STAT( obj, ITEM_INVENTORY ))
|| IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
extract_obj( obj );
else
obj_to_obj( obj, corpse );
}but in dbsc they only use inv like I want... however trying to use the obj->wear_loc != -1 only seems to create a problem where the item is removed from you, and is just deleted or lost somewhere.
But I cant really figure out how to even try, because looking around to me it seems wear_loc is always -1.. and the check still removes its from the player so I am at a loss
You'll need to make sure you're doing obj_to_char or obj_to_obj.
but if you look at the example given it does both obj_from_char and obj_to_obj already. so the problem is finding out if its worn or in the inventory.
I really cant figure this out... *sigh*
Could you explain the problem again, in more detail? It's just lost "somewhere"?
alright adding the if check in the example still seems to remove your eq, the only difference is that it doesn't put it in the corpse.
Could you post the code you have so that we know exactly what we're working with? You're probably calling obj_from_obj and removing the object from the corpse, then leaving the function with the if-check before putting the object somewhere.
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
obj_from_char( obj );
if ( (!IS_NPC(ch) && IS_OBJ_STAT( obj, ITEM_INVENTORY )) || IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
extract_obj( obj );
else
obj_to_obj( obj, corpse );
}
the only change I could find is
if (!IS_NPC(ch) && obj->wear_loc != -1)
continue;
but I could just be wrong in the whole thing
How did you make that change? Did you add lines? Remove lines? Where? Please try hard to be specific when talking about code and the like, little details are critical.
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if (!IS_NPC(ch) && obj->wear_loc != -1)
continue;
obj_from_char( obj );
if ( (!IS_NPC(ch) && IS_OBJ_STAT( obj, ITEM_INVENTORY )) || IS_OBJ_STAT( obj, ITEM_DEATHROT ) )
extract_obj( obj );
else
obj_to_obj( obj, corpse );
}
this is how it looked when I tested it. I tried to make it like the dbsc copy. Placing it where it was there as well.
The continue is probably skipping over doing anything to the obj. Move the continue down, so the ifcheck moves the obj to the corpse and then does a continue.
Why would I want that? I want the obj to stay on the players and not takken off to begin with? I only want it to remove items from the inventory. Doing what you suggested will remove all things from the player and they will just be gone.
I didn't say remove the ifcheck. I'm saying do this:
Unless I still don't understand what you mean.
if (!IS_NPC(ch) && obj->wear_loc != -1)
{
obj_from_char( obj );
continue;
}Unless I still don't understand what you mean.
From what I can tell that still removes the obj from the player and then "loses" it not going to the corpse or the player...
Sorry, I meant obj_from_obj. I did say to the corpse. Make sure obj_from_char is already done.
you actually need to modify the code in two different places, both in the make_corpses() function and in the extract_char() function, as smaug code does the following:
player killed->make corpse->extract character
so anything you let the character keep instead of going to the corpse will instead be purged all together. what you need to do is open up handler.c and modify the extract_char() function.
I am not exactly sure how this function used to look, but this is how you will want it to look. Just make sure you're modifying the section under the fPull ifcheck.
player killed->make corpse->extract character
so anything you let the character keep instead of going to the corpse will instead be purged all together. what you need to do is open up handler.c and modify the extract_char() function.
if ( !fPull )
{
location = NULL;
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if ( obj->wear_loc != -1 )
continue;
obj_from_char( obj );
extract_obj( obj );
}
I am not exactly sure how this function used to look, but this is how you will want it to look. Just make sure you're modifying the section under the fPull ifcheck.
Well this is one step closer.
and
this is what I have now it does still lose everything the player was wearing... now at least the inventory is moved to the corpse.
if( !fPull )
{
location = NULL;
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if ( obj->wear_loc != -1 )
continue;
obj_from_char( obj );
extract_obj( obj );
}
if( !IS_NPC( ch ) && ch->pcdata->clan )
location = get_room_index( ch->pcdata->clan->recall );
if( !location )
location = get_room_index( ROOM_VNUM_ALTAR );
if( !location )
location = get_room_index( 1 );
char_to_room( ch, location );
and
for( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if (!IS_NPC(ch) && obj->wear_loc != -1)
continue;
obj_from_char( obj );
if( IS_OBJ_STAT( obj, ITEM_INVENTORY ) || IS_OBJ_STAT( obj, ITEM_DEATHROT$
extract_obj( obj );
else
obj_to_obj( obj, corpse );
}
this is what I have now it does still lose everything the player was wearing... now at least the inventory is moved to the corpse.
xREMOVE_BIT( ch->act, ACT_MOUNTED );
while( ( obj = ch->last_carrying ) != NULL )
extract_obj( obj );
char_from_room( ch );
well I finally noticed that this was right above the if check for !fPull, so I commented out just the while thing and it seems to work properly
umm no, you do not want to comment that out, move it below the ifcheck, you don't want all those objects remaining when a player quits, they need to be extracted
Doesn't your suggestion of adding...
doesn't it do what the while does already? so what would be the point of adding it once more? and as of right now I havn't seen any problem with duplicated eq, or even lose of eq after dying or quitting? so many I am just missing something, or that your suggestion already does this for me?
for ( obj = ch->first_carrying; obj; obj = obj_next )
{
obj_next = obj->next_content;
if ( obj->wear_loc != -1 )
continue;
obj_from_char( obj );
extract_obj( obj );
}doesn't it do what the while does already? so what would be the point of adding it once more? and as of right now I havn't seen any problem with duplicated eq, or even lose of eq after dying or quitting? so many I am just missing something, or that your suggestion already does this for me?
no that would only extract the objects when a player dies, however when a player quits fPull is true, so that portion would not be run, and its not really an issue of players getting items duplicated, its more the item remain in memory, take a look at your MEMORY command to see how many actual items are loaded in the game, if you do not extract the objects from memory when a player quits, that amount will grow and grow. though truthfully i know not what that would do in the short term, but if your mud is stable and doesn't crash all too often a problem might arise.
It would really mess up item counts, since the object would basically be floating in space, not in any room, inventory, container, etc. Rare items based on item-count would be affected, for example.
having this in causes everything a player is wearing to be removed, And then only places the inventory in the corpse, but removes all eq worn, removing this however doesn't do it. So either i'm missing something far off or what.
well I just changed extract_char, to the new_extract_char from dbsc copies, adding a bool death at the end, and then adding an if check before the while.
I think you need to slow down a bit and learn what these functions are actually doing, how, and why. I have the impression that you're making changes almost randomly, throwing in lines and seeing what happens. That will only cause trouble further down the line. Take the time to learn a bit before charging ahead, and you will get much more out of the exercise.
the changes I made I understand what its doing. Its tacking on an extra arguement, so that you can declare if you died or not. now, in the other copy they use
#define extract_char( ch, fPull ) new_extract_char( ch, fPull, FALSE)
which will return the bool death, false right, every time extract_char is called. however when new_extract_char is called with the last being TRUE then...
only work on logout, and not on death. Which then stops the memory problem right? but doesn't remove the eq on death correct? Sometimes I seem random sometimes I dont, it usually depends on how tired I am... heh... sorry.
#define extract_char( ch, fPull ) new_extract_char( ch, fPull, FALSE)
which will return the bool death, false right, every time extract_char is called. however when new_extract_char is called with the last being TRUE then...
if( !death )
{
while( ( obj = ch->last_carrying ) != NULL )
extract_obj( obj );
}only work on logout, and not on death. Which then stops the memory problem right? but doesn't remove the eq on death correct? Sometimes I seem random sometimes I dont, it usually depends on how tired I am... heh... sorry.
It's basically impossible for us to say what is going to happen when we don't know what exactly has been changed and we see bits of code here and there. I mean, sure, for the code you posted, it looks like if the variable death is false, every one of the character's objects will be extracted. Whether or not this actually does what you want it to do in the greater scheme of things is a good question. It depends on when 'death' is set to true or false, and what you have changed in other places of the code.
the only change to extract_char is that it is now new_extract_char, with the bool for it. then the one if check if its death or not. everything else calls extract_char which then calls new_extrac with false for death, however in fight.c
which is the only call that should tell extract that death is true.
set_char_color( AT_DIEMSG, victim );
if( victim->pcdata->mdeaths + victim->pcdata->pdeaths < 3 )
do_help( victim, "new_death" );
else
do_help( victim, "_DIEMSG_" );
new_extract_char( victim, FALSE, TRUE );
if( !victim )
{
bug( "%s: oops! extract_char destroyed pc char", __FUNCTION__ );
return;
}which is the only call that should tell extract that death is true.
Well, it's still very hard to say if it would work because we can only partially see the code, so . . . when you run the code, does it do what you expect?
If you want to see if you have leaks, you can run a tool like valgrind, if you have it available on your system.
By the way, did you put in that
If you want to see if you have leaks, you can run a tool like valgrind, if you have it available on your system.
By the way, did you put in that
if (!victim) check in fight.c?
No i didn't, it was already there. The only thing I dont really know if its working correctly or not is this loaded objs business. In memory i have
IdxObjs: 88 Objs: 39(21)
Me being the only one on this confuses me some what. so theres 21 objects in the world but 39 ob those objs are worn or in another object? or is it 21 in the world that arn't worn or in something, and 39 that are worn and in something?
IdxObjs: 88 Objs: 39(21)
Me being the only one on this confuses me some what. so theres 21 objects in the world but 39 ob those objs are worn or in another object? or is it 21 in the world that arn't worn or in something, and 39 that are worn and in something?
It might be 39 logical objs, but 21 object structure instances. Recall that objects can be grouped together ("stacked").
One thing you can try is just create corpses several times and see if that number goes up incorrectly or varies in some unexpected way. If it does, then you have a problem.
One thing you can try is just create corpses several times and see if that number goes up incorrectly or varies in some unexpected way. If it does, then you have a problem.
Objs: 48(29)
this is what happened after one of my players logged on an killed one of the mobs about 5 times. first number went up 5 from the blood she created, then 4 for the items she wearing? but if so that only accounts for the 48 and not the 29?
this is what happened after one of my players logged on an killed one of the mobs about 5 times. first number went up 5 from the blood she created, then 4 for the items she wearing? but if so that only accounts for the 48 and not the 29?