Welcome to the Builder Academy

Question Old patch from 1997

More
25 May 2016 09:45 #5928 by JTP
Old patch from 1997 was created by JTP
This patch dont save and/or load in tba, if someone wanna update this patch for tbamud, i will be glad.
Code:
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.

More
25 May 2016 21:09 #5929 by thomas
Replied by thomas on topic Old patch from 1997
Actually it is quite easy to save/load from ascii pfiles.

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:
Code:
if (GET_RIP_CNT(ch) != 0) fprintf(fl, "RipC: %d\n", GET_RIP_CNT(ch));
2. add these lines in load_char (so they match the existing pattern):
Code:
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.

More
25 May 2016 21:51 - 25 May 2016 22:04 #5930 by JTP
Replied by JTP on topic Old patch from 1997
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;

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
Code:
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 ?
Last edit: 25 May 2016 22:04 by JTP.

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

More
25 May 2016 22:12 - 25 May 2016 22:25 #5931 by JTP
Replied by JTP on topic Old patch from 1997
Game seems very unstable after i added above code + save and load...im crashing every few minutes with various backtrace problems, that isnt even in the files of this code.


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))
Last edit: 25 May 2016 22:25 by JTP.

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

More
25 May 2016 22:22 - 25 May 2016 22:23 #5932 by rudeboyrave
Replied by rudeboyrave on topic Old patch from 1997
i would put this

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
Code:
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.
Last edit: 25 May 2016 22:23 by rudeboyrave.

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

More
25 May 2016 22:36 - 25 May 2016 22:40 #5933 by JTP
Replied by JTP on topic Old patch from 1997
Ok game is still very unstable after entering this code, but now it saved how many times i died but not how many times i killed something. Didnt save DT either.

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
Last edit: 25 May 2016 22:40 by JTP.

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

Time to create page: 0.208 seconds