fight.c

Posted by Tiernan on Thu 21 Oct 2004 08:47 AM — 13 posts, 43,036 views.

#0
I'm looking for the specific string that determines when a player _dies_ so that I could get it to check to see if an item is in their inventory, if so, change something else.

If anyone could offer some code... I'm kinda new... which is an understatement. I just want to pick through the code, but I can't find this little thing. If someone could at least point me in the right direction it would be greatly appreciated.
USA #1
I believe that would be in the damage function - and I think there's even a specific function, "kill_char" or something, that is called whenever a character dies.
#2
Ok, I've looked through the fight.c and found several instances that might actually be the spot that kills the player:

ch_ret damage( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt )
{
char buf[MAX_STRING_LENGTH];
char buf1[MAX_STRING_LENGTH];
char filename[256];
sh_int dameq;
sh_int maxdam;
bool npcvict;
bool loot;
int xp_gain;
OBJ_DATA *damobj;
ch_ret retcode;
sh_int dampmod;
CHAR_DATA *gch /*, *lch */;
int init_gold, new_gold, gold_diff;
sh_int anopc = 0; /* # of (non-pkill) pc in a (ch) */
sh_int bnopc = 0; /* # of (non-pkill) pc in b (victim) */


retcode = rNONE;

if ( !ch )
{
bug( "Damage: null ch!", 0 );
return rERROR;
}
if ( !victim )
{
bug( "Damage: null victim!", 0 );
return rVICT_DIED;
}

if ( victim->position == POS_DEAD ) <-- This part in particular
return rVICT_DIED;

npcvict = IS_NPC(victim);

And at line 2287:

case POS_DEAD:
if ( dt >= 0 && dt < top_sn )
{
SKILLTYPE *skill = skill_table[dt];

if ( skill->die_char && skill->die_char[0] != '\0' )
act( AT_DEAD, skill->die_char, ch, NULL, victim, TO_CHAR );
if ( skill->die_vict && skill->die_vict[0] != '\0' )
act( AT_DEAD, skill->die_vict, ch, NULL, victim, TO_VICT );
if ( skill->die_room && skill->die_room[0] != '\0' )
act( AT_DEAD, skill->die_room, ch, NULL, victim, TO_NOTVICT );
}
act( AT_DEAD, "$n is DEAD!!", victim, 0, 0, TO_ROOM );
act( AT_DEAD, "You have been KILLED!!\n\r", victim, 0, 0, TO_CHAR );
break;

These are the only bits of code that even mention killing, or dieing. I need to know which actually does the whole deduct-experience-and-transport-to-room part... *Help!*
USA #3
Check the function raw_kill, and also search for something like "experienced penality" in fight.c
#4
/*
* Payoff for killing things.
*/
if ( victim->position == POS_DEAD )
{
group_gain( ch, victim );

if ( !npcvict )
{
sprintf( log_buf, "%s (%d) killed by %s at %d",
victim->name,
victim->level,
(IS_NPC(ch) ? ch->short_descr : ch->name),
victim->in_room->vnum );
log_string( log_buf );
to_channel( log_buf, CHANNEL_MONITOR, "Monitor", LEVEL_IMMORTAL );

Ok so this is the chunk I'm looking for... I think. This at least does the "Blah has been killed by Blah!" I can't tell what exactly the code is doing... I mean it looks like it's just checking to see if they are in POS_DEAD, then telling the world about it. I'm not sure if this is the snippet I'm looking for. I need the code that executes just before the player is moved to the new room.
USA #5
Did you look at raw_kill?
#6
Awesome! It was raw_kill, thanks for the help :) Now... just to figure out how to check the inventory, check for a specific item's vnum, to restore the player's health... hmm.. gonna take some effort... blarg
USA #7
Do a loop through the players carried items, then check for the vnum (obj->pObjectIndex->vnum), and if it matches, do ch->hit = ch->max_hit

I can't be more specific right now, because I'm in my CICSO course.
Amended on Fri 22 Oct 2004 02:46 PM by Zeno
USA #8
If you're trying to save the player from at death, you might want to look where raw_kill is called, and change it there instead. Who knows what else is called before raw_kill is called, so you need to be careful with that.
#9
Ok, but couldn't raw_kill be called in several different places? I do want to save a player from death, but only if they have an item in their inventory, shouldn't I go right to the source at raw_kill?

Does anyone know any good documentation for SMAUG, and also, what would I use to check the inventory? just ch->inventory, or is it something a little more kooky? I'm very new to coding, but I know a lot of C++, I thought this was gonna be... well.. simple.. blarg...any help would be appreciated, and for all help so far, many thanks. *bow*
USA #10
The danger to directly editing raw_kill for this is that such things as the slay command call raw_kill and your life saving items can now do very unexpected things.

As for how kooky the check is, that depends on a number of factors - is the item nodrop? is the item expected to be in a bag? will it work from within a bag if its not nodrop? Checking for items inside containers and extracting them is a bit more compicated but there are examples in the code (can't think of any offhand though :( )

#11
Ok, really the effect I wanted was the same as a Phoenix Down from Final Fantasy, although instead of dieing, you'd be reset back to full health, and the item would be used from your inventory I don't really expect the item to be in a container, and it's not nodrop. This help so far is awesome! But yeah, if anyone has any documentation, please send a link, or something...
USA #12
Quote:
I'm very new to coding, but I know a lot of C++
How does one manage that? :)

Anyway the thing is, you don't want to touch *all* instances of a player being killed - as Meerclar pointed out that could have some "interesting" side effects. Rather you seem to only want the player to not die whilst in combat - so you want to only check the combat code.

I'm pretty sure that this will work for you if you only put the check in the damage function - or wherever it is that the code calls raw_kill if a character is killed during combat.

As for the 'kookiness' of the check it's not really 'kooky' at all - it's just the way it is. :) You'll have to go through the linked list of the inventory. If the item is guaranteed to not be in a container then your problem is actually pretty easy - just loop through the inventory linked list looking for the right item. I think that's first_carrying to last_carrying.