- Posts: 937
- Thank you received: 17
Old patch from 1997
- JTP
- Topic Author
- Offline
- Platinum Member
-
This is how I went about implementing death/kill/deathtrap
counters for player characters. It's meaningless in terms of characters
having view of the underlying engine, yet still satisfies their hunger for
numbers in do_score. Shame to let all that extra space in the playerfile
go to waste :)
I also have a 'victories in the arena' counter, but left it out
considering my arena being scratch code. Should be simple enough to add.
jacobin@bellatlantic.net if you have any problems.
-Jac
A ButterMud Production - Telnet://betterbox.net:4000
Edit the follow spares in structs.h (player specials)
__structs.h__
int spells_to_learn; /* How many can you learn yet this level*/
int rip_cnt;
int kill_cnt;
int dt_cnt;;
int spare10;
__
Add the following macros to utils.h
__utils.h__
#define GET_RIP_CNT(ch) ((ch)->player_specials->saved.rip_cnt)
#define GET_KILL_CNT(ch) ((ch)->player_specials->saved.kill_cnt)
#define GET_DT_CNT(ch) ((ch)->player_specials->saved.dt_cnt)
__
Add the following right before die(victim) is called.
__fight.c__
if (!IS_NPC(victim))
GET_RIP_CNT(victim) += 1;
if (!IS_NPC(ch))
GET_KILL_CNT(ch) += 1;
__
Add the following right before the character is extracted when walking
into a deathtrap.
__act.movement.c__
GET_DT_CNT(ch) += 1;
__
Report it within do_score
__do.score__
sprintf(buf, "%sYou have died %d times and killed %d opponents.\r\n",
buf, GET_RIP_CNT(ch), GET_KILL_CNT(ch));
sprintf(buf, "%sYou have walked into a deathtrap %d times.\r\n",
buf, GET_DT_CNT(ch));
__
Now for the nosey wizards in stat_char
__act.wizard.c__
sprintf(buf, "Rip: [%d], Kills: [%d], DeaathTraps:
[%d]\r\n",GET_RIP_CNT(k), GET_KILL_CNT(k), GET_DT_CNT(k));
send_to_char(buf, ch);
__
Reboot!
Please Log in or Create an account to join the conversation.
- thomas
-
- Offline
- Administrator
-
- Posts: 792
- Thank you received: 153
Have a look here: github.com/tbamud/tbamud/blob/2f12752373...4/src/players.c#L239
All values are treated the same in load_char:
1. first, they are set to some predefined value (think of it as "zero", even if it sometimes is something else)
2. then, depending on the first letter, then the full code in the file, the values are set.
The same goes for save_char(), here: github.com/tbamud/tbamud/blob/2f12752373...4/src/players.c#L503
Every value is written, one at a time, with a code to help read it again.
So, to make it save and load:
1. add a line for each value to save_char, like this:
if (GET_RIP_CNT(ch) != 0) fprintf(fl, "RipC: %d\n", GET_RIP_CNT(ch));
GET_RIP_CNT(ch) = 0;
..
..
case 'R':
if (!strcmp(tag, "Room")) GET_LOADROOM(ch) = atoi(line);
+ else if (!strcmp(tag, "RipC")) GET_RIP_CNT(ch) = atoi(line);
break;
Repeat for the other three values.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
__fight.c__
if (!IS_NPC(victim))
GET_RIP_CNT(victim) += 1;
if (!IS_NPC(ch))
GET_KILL_CNT(ch) += 1;
added this in fight.c just before die(victim, ch); that it seems to be called in tbamud, but its located two Places in fight.c ?
tryed to kill a mob...counter didnt add 1. tryed dying counter didnt add 1 :(
So im still at 0 and 0
i then tryed walking into a DT, that added +1. But when i quit and came back it was back to 0
This is what i added to save:
load_char
GET_RIP_CNT(ch) = 0;
GET_KILL_CNT(ch) = 0;
GET_DT_CNT(ch) = 0;
case 'K':
if (!strcmp(tag, "KillC")) GET_KILL_CNT(ch) = atoi(line);
break;
in case D
else if (!strcmp(tag, "DtC")) GET_DT_CNT(ch) = atoi(line);
in case R
else if(!strcmp(tag, "RipC")) GET_RIP_CNT(ch) = atoi(line);
save_char:
if (GET_RIP_CNT(ch) != 0) fprintf(fl, "RipC: %d\n", GET_RIP_CNT(ch));
if (GET_KILL_CNT(ch) != 0) fprintf(fl, "KillC: %d\n", GET_KILL_CNT(ch));
if (GET_DT_CNT(ch) != 0) fprintf(fl, "DtC: %d\n", GET_DT_CNT(ch));
So why isnt it adding +1 to kill and rip.
And why isnt it saving and loading right, what am i missing ?
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Program terminated with signal 11, Segmentation fault.
#0 0x080b97dd in valid_dg_target (ch=0x9482070, bitvector=1) at dg_misc.c:279
279 else if (ch->desc && (STATE(ch->desc) != CON_PLAYING))
Program terminated with signal 11, Segmentation fault.
#0 0x0032986b in strlen () from /lib/libc.so.6
(gdb)
Program terminated with signal 11, Segmentation fault.
#0 0x080b8126 in sub_write (arg=0xbfe4985f "\tG\tmKarzon Kul\tn knocks out of your hands!\tn", ch=0xa1f8ee0, find_invis=1 '\001',
targets=<value optimized out>) at dg_comm.c:180
180 if (IS_SET(targets, TO_CHAR) && SENDOK(ch))
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
GET_RIP_CNT(ch) = 0;
GET_KILL_CNT(ch) = 0;
GET_DT_CNT(ch) = 0;
in class.c void do_start
this is where new players are set up.
also i would put the counter ticks
if (!IS_NPC(victim))
GET_RIP_CNT(victim) += 1;
if (!IS_NPC(ch))
GET_KILL_CNT(ch) += 1;
in void die in fight.c
void die(struct char_data * ch, struct char_data * killer)
{
gain_exp(ch, -(GET_EXP(ch) / 2));
if (!IS_NPC(ch)) {
GET_RIP_CNT(ch) = GET_RIP_CNT(ch) + 1;
REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_KILLER);
REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_THIEF);
}
raw_kill(ch, killer);
if (!IS_NPC(killer))
GET_KILL_CNT(killer) = GET_KILL_CNT(killer) + 1;
}
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Annoying that is crashes every few minutes just because of something like this.
Program terminated with signal 11, Segmentation fault.
#0 0x0032986b in strlen () from /lib/libc.so.6
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
but yes i still crash
Core was generated by `bin/circle -q 6969'.
Program terminated with signal 11, Segmentation fault.
#0 0x0032986b in strlen () from /lib/libc.so.6
got this Again, it comes out of the blue...i dont even enter a DT.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Program terminated with signal 11, Segmentation fault.
#0 0x080b980d in valid_dg_target (ch=0xa921268, bitvector=1) at dg_misc.c:279
279 else if (ch->desc && (STATE(ch->desc) != CON_PLAYING))
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Sucks that it now saves all 3 and it crashes like hell. The mud has just run for 4 days with no problems, and now all this over this Little snippet :)
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
structs.h
after: int spells_to_learn;
int rip_cnt;
int kill_cnt;
int dt_cnt;
__
utils.h
#define GET_RIP_CNT(ch) ((ch)->player_specials->saved.rip_cnt)
#define GET_KILL_CNT(ch) ((ch)->player_specials->saved.kill_cnt)
#define GET_DT_CNT(ch) ((ch)->player_specials->saved.dt_cnt)
__
players.c
load_char
GET_RIP_CNT(ch) = 0;
GET_KILL_CNT(ch) = 0;
GET_DT_CNT(ch) = 0;
case 'K':
if (!strcmp(tag, "KilC")) GET_KILL_CNT(ch) = atoi(line);
break;
in case D
else if (!strcmp(tag, "DtC ")) GET_DT_CNT(ch) = atoi(line);
in case R
else if(!strcmp(tag, "RipC")) GET_RIP_CNT(ch) = atoi(line);
save_char:
if (GET_RIP_CNT(ch) != 0) fprintf(fl, "RipC: %d\n", GET_RIP_CNT(ch));
if (GET_KILL_CNT(ch) != 0) fprintf(fl, "KilC: %d\n", GET_KILL_CNT(ch));
if (GET_DT_CNT(ch) != 0) fprintf(fl, "DtC : %d\n", GET_DT_CNT(ch));
__
Add the following right before the character is extracted when walking
into a deathtrap.
act.movement.c
GET_DT_CNT(ch) += 1;
__
fight.c
void die(struct char_data * ch, struct char_data * killer)
{
gain_exp(ch, -(GET_EXP(ch) / 2));
if (!IS_NPC(ch)) {
GET_RIP_CNT(ch) = GET_RIP_CNT(ch) + 1;
REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_KILLER);
REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_THIEF);
}
raw_kill(ch, killer);
if (!IS_NPC(killer))
GET_KILL_CNT(killer) = GET_KILL_CNT(killer) + 1;
}
__
class.c
GET_RIP_CNT(ch) = 0;
GET_KILL_CNT(ch) = 0;
GET_DT_CNT(ch) = 0;
__
do.score
send_to_char(ch, "You have died %d times, killed %d opponents and walked into a deathtrap %d times.\r\n", GET_RIP_CNT(ch), GET_KILL_CNT(ch), GET_DT_CNT(ch));
__
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
GET_RIP_CNT(ch) = 0;
GET_KILL_CNT(ch) = 0;
GET_DT_CNT(ch) = 0;
this should not be in load_char, put only in do_start because it is resetting every login maybe?
if added to do_start it would only be set to 0 when a char is made.
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.
- JTP
- Topic Author
- Offline
- Platinum Member
-
- Posts: 937
- Thank you received: 17
Please Log in or Create an account to join the conversation.
- rudeboyrave
-
- Offline
- Premium Member
-
CyberASSAULT
www.cyberassault.org
cyberassault.org 11111
A post-apocalyptic, sci-fi MUD.
Please Log in or Create an account to join the conversation.