[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  fight.c
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

fight.c

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by Tiernan   (6 posts)  [Biography] bio
Date Thu 21 Oct 2004 08:47 AM (UTC)  quote  ]
Message
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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #1 on Thu 21 Oct 2004 09:33 AM (UTC)  quote  ]
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Tiernan   (6 posts)  [Biography] bio
Date Reply #2 on Thu 21 Oct 2004 01:26 PM (UTC)  quote  ]
Message
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!*
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio   Moderator
Date Reply #3 on Thu 21 Oct 2004 04:54 PM (UTC)  quote  ]
Message
Check the function raw_kill, and also search for something like "experienced penality" in fight.c

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Tiernan   (6 posts)  [Biography] bio
Date Reply #4 on Thu 21 Oct 2004 06:58 PM (UTC)  quote  ]
Message
/*
* 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.
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #5 on Thu 21 Oct 2004 07:25 PM (UTC)  quote  ]
Message
Did you look at raw_kill?

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Tiernan   (6 posts)  [Biography] bio
Date Reply #6 on Fri 22 Oct 2004 12:04 PM (UTC)  quote  ]
Message
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
[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio   Moderator
Date Reply #7 on Fri 22 Oct 2004 01:59 PM (UTC)  quote  ]

Amended on Fri 22 Oct 2004 02:46 PM (UTC) by Zeno

Message
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.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #8 on Fri 22 Oct 2004 08:16 PM (UTC)  quote  ]
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Tiernan   (6 posts)  [Biography] bio
Date Reply #9 on Sat 23 Oct 2004 12:08 AM (UTC)  quote  ]
Message
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*
[Go to top] top

Posted by Meerclar   USA  (569 posts)  [Biography] bio
Date Reply #10 on Sat 23 Oct 2004 05:12 AM (UTC)  quote  ]
Message
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 :( )


Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Tiernan   (6 posts)  [Biography] bio
Date Reply #11 on Sat 23 Oct 2004 07:53 AM (UTC)  quote  ]
Message
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...
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Reply #12 on Mon 25 Oct 2004 08:27 PM (UTC)  quote  ]
Message
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.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


3,503 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]