Welcome to the Builder Academy

Question Load node objects from code instead of zedit

More
27 Jul 2022 17:47 #10109 by Nero
I have added fishing, mining, and wood cutting to my game. I created a 'node' that is an object from oedit that loads into the room.
For example, I have created a school of fish that loads into a water room, only when that node exists in the room can you actually cast your rod and fish.
The reason I did this was to force exploration instead of people cramming into one room to fish all day.
My question though is how do I force that object to load randomly in the water rooms on a zone reset instead of using zedit?
The reason why I don't want to use zedit is one, I will have to go through every water room in the game and edit in zedit to get the object to load which will take a lot of work and two the object only maxes at 100 which I feel my be too scarce given the size of the game. Is there an easier way to do this in code to accomplish what I want? Say, the object has a 30% chance to load in any given water room in the game when the zone(s) reset?
Code:
/*Fishing code*/ ACMD(do_castout) {   struct obj_data *obj, *pole, *next, *pool = world[IN_ROOM(ch)].contents;   int fail, pool_vnum = 307, extract;   if (!can_see_room(ch, IN_ROOM(ch))) {       send_to_char(ch, "It's too dark for you to castout here!\r\n");       return;     } /* No fishing while fighting */   if (IS_FIGHTING(ch)) {     send_to_char(ch, "You are too busy fighting to fish right now!\r\n");     return;   }   if (PLR_FLAGGED(ch, PLR_FISHING)) {     send_to_char(ch, "You are already fishing!\r\n");     return;   }   if (!(pole = GET_EQ(ch, WEAR_HOLD)) ||       (GET_OBJ_TYPE(pole) != ITEM_POLE)) {     send_to_char(ch, "You need to be holding a fishing pole first.\r\n");     return;   }   if (!ROOM_FLAGGED(IN_ROOM(ch), ROOM_SALTWATER_FISH) && !ROOM_FLAGGED(IN_ROOM(ch), ROOM_FRESHWATER_FISH)) {     send_to_char(ch, "This is not a good place to fish, you'll want to find a better spot.\r\n");     return;   } while (pool != NULL && GET_OBJ_VNUM(pool) != pool_vnum)        pool = pool->next_content;  if (!pool) {     send_to_char(ch, "This is not a good place to fish, you'll want to find a better spot that has a school of fish.\r\n");     GET_WAIT_STATE(ch) = (2 RL_SEC);     return;  }   fail = rand_number(1, 10);   if (fail <= 3) {     send_to_char(ch, "You pull your arm back and try to cast out your line, but it gets all tangled up.\r\nTry again.\r\n");     act("$n pulls $s arm back, trying to cast $s fishing line out into the water, but ends up just a bit tangled.", FALSE, ch, 0, 0, TO_ROOM);     GET_WAIT_STATE(ch) = (2 RL_SEC);     return;   }   /* Ok, now they've gone through the checks, now set them fishing */   extract = rand_number(1, 4);   if (extract == 1) {   extract_obj(pool);   }   SET_BIT_AR(PLR_FLAGS(ch), PLR_FISHING);   send_to_char(ch, "You cast your line out into the water, hoping for a bite.\r\n");   act("$n casts $s line out into the water, hoping to catch some food.", FALSE, ch, 0, 0, TO_ROOM);   return; } /* Fish on? Reelin! */ ACMD(do_reelin) {   int success, f_num, fish_num;   struct obj_data *fish;   char buf[MAX_STRING_LENGTH];   if (!PLR_FLAGGED(ch, PLR_FISHING)) {     send_to_char(ch, "You aren't even fishing!\r\n");     return;   }   if (!PLR_FLAGGED(ch, PLR_FISH_ON)) {     send_to_char(ch, "You reel in your line, but alas... nothing on the end.\r\nBetter luck next time.\r\n");     REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_FISHING);     act("$n reels $s line in, but with nothing on the end.", FALSE, ch, 0, 0, TO_ROOM);     return;   }   /* Ok, they are fishing and have a fish on */   success = rand_number(1, 10);   REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_FISHING);   REMOVE_BIT_AR(PLR_FLAGS(ch), PLR_FISH_ON);   if (success <= 6) {     send_to_char(ch, "You reel in your line, putting up a good fight, but you lose it!\r\nTry again?\r\n");     act("$n reels $s line in, fighting with whatever is on the end, but loses the catch.", FALSE, ch, 0, 0, TO_ROOM);     GET_WAIT_STATE(ch) = (2 RL_SEC);     return;   }   /* We used object vnums 300 for our fish that people could    * catch. The below numbers reflect that use. If you wish to change    * the vnums of the fish, just change the numbers below. You can    * see that we seperated the type of fish by freshwater and salt    * water.    */   if (ROOM_FLAGGED(IN_ROOM(ch), ROOM_SALTWATER_FISH)) {     fish_num = rand_number(114,116);     f_num = real_object(fish_num);     fish = read_object(f_num, REAL);     send_to_char(ch, "You reel in %s! Nice catch!\r\n", fish->short_description);     obj_to_char(fish, ch);     act("Wow! $n reels in a nice catch! Looks like $p!", FALSE, ch, fish, 0, TO_ROOM);     return;   } else   if (ROOM_FLAGGED(IN_ROOM(ch), ROOM_FRESHWATER_FISH)) {     fish_num = rand_number(300,306);     f_num = real_object(fish_num);     fish = read_object(f_num, REAL);     send_to_char(ch, "You reel in %s! Nice catch!\r\n", fish->short_description);     obj_to_char(fish, ch);     act("Wow! $n reels in a nice catch! Looks like $p!", FALSE, ch, fish, 0, TO_ROOM);     return;   } else   send_to_char(ch, "You should never see this message, please report it.\r\n");   return; }

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

More
27 Jul 2022 18:10 #10110 by zusuk
Would you also want those nodes to reset/respawn in-game on a timer or as they are farmed? Or just load once per boot/copyover? There is a version of this on LuminariMUD ( github.com/LuminariMUD/Luminari-Source ), but I don't have the code in front of me :)

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

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

More
28 Jul 2022 04:41 #10112 by Nero
I think either would work for me as long as I don't have to go to every room and zedit. I will take a look at this thanks!

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

More
01 Sep 2022 20:24 #10139 by Nero
Well I may need more help on this here is the code I have added to act.item.c
Code:
/* this is called in db.c on boot-up    harvesting nodes are placed by this function randomly(?)    throughout the world  */ void reset_harvesting_rooms(void) {   int cnt = 0;   int num_rooms = 0;   int nodes_allowed = 0;   int deploy;   struct obj_data *mining = NULL, *woodcutting = NULL, *fishing = NULL;   for (cnt = 0; cnt <= top_of_world; cnt++)   {     if (world[cnt].sector_type == SECT_CITY)       continue;     if (world[cnt].sector_type == SECT_INSIDE)       continue;     if (world[cnt].sector_type == SECT_FIELD)       continue;     if (world[cnt].sector_type == SECT_FLYING)       continue;     if (world[cnt].sector_type == SECT_UNDERWATER)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_ONE)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_TWO)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_THREE)       continue;     if (world[cnt].sector_type == SECT_SNOW)       continue;     if (world[cnt].sector_type == SECT_DESERT)       continue;     if (world[cnt].sector_type == SECT_LUNAR)       continue;     num_rooms++;   }   nodes_allowed = num_rooms / 2;   if (mining_nodes >= (nodes_allowed * 2) && woodcutting_nodes >= nodes_allowed &&       fishing_nodes >= nodes_allowed)     return;   for (cnt = 0; cnt < top_of_world; cnt++)   {     if (world[cnt].sector_type == SECT_CITY)       continue;     if (world[cnt].sector_type == SECT_INSIDE)       continue;     if (world[cnt].sector_type == SECT_FIELD)       continue;     if (world[cnt].sector_type == SECT_FLYING)       continue;     if (world[cnt].sector_type == SECT_UNDERWATER)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_ONE)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_TWO)       continue;     if (world[cnt].sector_type == SECT_EXTRAPLANAR_THREE)       continue;     if (world[cnt].sector_type == SECT_SNOW)       continue;     if (world[cnt].sector_type == SECT_DESERT)       continue;     if (world[cnt].sector_type == SECT_LUNAR)       continue;     deploy = rand_number (1, 33);     if (deploy == 1);     {       mining = read_object(396, REAL);       woodcutting = read_object(370, REAL);       fishing = read_object(307, REAL);       if (!mining)         continue;         if (mining_nodes >= nodes_allowed && world[cnt].sector_type == SECT_MOUNTAIN)         {           obj_to_room(mining, cnt);           extract_obj(mining);           continue;         }         else           mining_nodes++;         break;         if (woodcutting_nodes >= nodes_allowed && world[cnt].sector_type == SECT_FOREST)         {           obj_to_room(woodcutting, cnt);           extract_obj(woodcutting);           continue;         }         else           woodcutting_nodes++;         if (fishing_nodes >= nodes_allowed && world[cnt].sector_type == SECT_WATER_SWIM || world[cnt].sector_type == SECT_WATER_NOSWIM)         {           obj_to_room(fishing, cnt);           extract_obj(fishing);           continue;         }         else           fishing_nodes++;         break;     }   } }

Added this to DB.C
Code:
 if (!no_specials) {     log("Loading shops.");     boot_zone(DB_BOOT_SHP);     log("Loading quests.");     boot_zone(DB_BOOT_QST);    log("Placing Harvesting Nodes");     for (x = 0; x < NUM_HARVEST_NODE_RESETS; x++)       reset_harvesting_rooms();   }
 

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

More
01 Sep 2022 20:25 #10140 by Nero
The game boots up but It doesn't seem to be adding any of the nodes to the game on bootup or zone reset. Not sure what I am missing here.

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

More
01 Sep 2022 21:12 #10141 by thomas
A quick glance tells me that you are adding the objects, then immediately extracting them again. This doesn't feel right to me.

I suggest focusing on the sectors you actually want to work with.
I also suggest altering the logic a little in the last part:
Code:
for (cnt = 0; cnt <= top_of_world; cnt++) { if (world[cnt].sector_type == SECT_WATER_SWIM || world[cnt].sector_type == SECT_WATER_NOSWIM || world[cnt].sector_type == SECT_FOREST || world[cnt].sector_type == SECT_MOUNTAIN) num_rooms++; } nodes_allowed = num_rooms / 2; for (cnt = 0; cnt < top_of_world; cnt++) { if (mining_nodes <= nodes_allowed && world[cnt].sector_type == SECT_MOUNTAIN && rand_number(1, 33) == 1) { mining = read_object(397, VIRTUAL); if (mining) { obj_to_room(mining, cnt); mining_nodes++; } } if (woodcutting_nodes <= nodes_allowed && world[cnt].sector_type == SECT_FOREST && rand_number(1, 33) == 1) { woodcutting = read_object(397, VIRTUAL); if (woodcutting ) { obj_to_room(woodcutting , cnt); woodcutting_nodes ++; } } if (fishing_nodes <= nodes_allowed && (world[cnt].sector_type == SECT_WATER_SWIM || world[cnt].sector_type == SECT_WATER_NOSWIM) && rand_number(1, 33) == 1) { fishing = read_object(398, VIRTUAL); if (fishing) { obj_to_room(fishing, cnt); fishing_nodes ++; } } }
read_object(x, VIRTUAL) because you're using vnums here..

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

Time to create page: 0.379 seconds