Welcome to the Builder Academy

Question How do I add a new option to char_data in structs.h file?

More
11 Sep 2020 18:46 - 11 Sep 2020 18:55 #9726 by cry1004
I'm sorry that it seems the only one me keeps asking questions.

When playing games, there are times when you want to start in a specific area as the world grows.
I want to create a new object in a specific room, and when I order it to register, the game starts in that room when I login.

At this time, if the registration cancellation command is entered, the location of the starting room is initialized to mortal_start_room and immort_start_room according to the user's level.

The following is the code I made, but it doesn't run because many places are wrong. It seems to be because I lack basic knowledge of programming.

I added it to the end of the struct char_data in the structs.h file.
Code:
struct char_data *start_room;

I didn't think I should add it to the reset_char function in the db.c file. Or it seems to be initialized with mortal_start_room and immort_start_room according to the user's level.

In the do_stat_character function of the act.wizard.c file, I can get the room name and show it.
This could be solved by knowing how to define and load a new value in char_data.

I think should initialize the starting room for void init_char(struct char_data *ch) function as well.
Code:
set_startroom(ch, r_mortal_start_room);
Again, this is a mess of code.

If the starting room is set in enter_player_game of the interpreter.c file, the character is connected to the room, and if it is not set, I can login to the room according to the level of the character.
ex) mortal_start_room and immort_start_room


I made the utils.h file to get the character's starting room, but it seems to be wrong.
Code:
#define GET_STARTROOM(ch) (ch->start_room)

I made a function that initializes the starting room in the limits.c file.
Of course it wasn't made right.
Code:
void set_startroom(struct char_data *ch, room_vnum rvnum) { zone_rnum zrnum = real_zone_by_thing(rvnum); room_rnum rrnum = real_room(rvnum); if (GET_STARTROOM(ch) != NULL) free(GET_STARTROOM(ch)); if (zrnum == NOWHERE || rrnum == NOWHERE) GET_STARTROOM(ch) = r_mortal_start_room; }


Is it correct to make the following when specifying the following in char_data?
Code:
struct char_data *start_room;
start_room is not an int type, it contains the room number.

I want to save and load the location of the starting room just like loading the user's level in utils.h.
Code:
#define GET_LEVEL(ch) ((ch)->player.level)


In my opinion, it doesn't seem to be called and used as below. Are there any documents that can help you learn this?
Code:
#define GET_STARTROOM(ch) (ch->start_room)

The article I wrote was using Google Translator. What I want to say may have been mistranslated into English.
Last edit: 11 Sep 2020 18:55 by cry1004.

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

More
11 Sep 2020 23:15 - 11 Sep 2020 23:16 #9728 by Vatiken
I apologize for both my lack of understanding in what your asking and my rust with the codebase but..
.
This will create a pointer to an applicable char_data structure which I don't believe is what you want.
Code:
struct char_data *start_room;

Would be what you are looking for if you want to store a room's rnum in the char file
Code:
room_rnum start_room;

I'm not quite sure what you are trying to achieve though.
  • The starting mortal/immortal room can be changed through the config file or cedit.
  • There is already an rnum stored in "player_special_data_saved" for load_room

tbaMUD developer/programmer
Last edit: 11 Sep 2020 23:16 by Vatiken.
The following user(s) said Thank You: cry1004

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

More
11 Sep 2020 23:46 - 12 Sep 2020 09:49 #9730 by cry1004
Thank you for the reply.
I know the starting room can be edited in cedit.

My question is wrong.

I did not save the number of the current room with the character in LOADROOM through do_save, but hoped that the defense of LOADROOM would be saved only on certain objects.

I think we can modify the sauce a little. Thank you.
Last edit: 12 Sep 2020 09:49 by cry1004.

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

More
12 Sep 2020 23:15 #9734 by thomas
This kind of data typically is added to struct player_special_data_saved, not directly to char_data, since mobs don't have start rooms :)

You are well on your way to making it work, by the way; you just need to add your new field to the saving and loading code for players.

And don't be discouraged by being the "only one who asks questions". We need questions on the board to keep it alive, and you're the newest developer here. Of course you'll be asking more questions.

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

Time to create page: 0.197 seconds