Welcome to the Builder Academy

Question Fishing Code questions

More
23 May 2022 01:35 - 23 May 2022 02:36 #10065 by Nero
Fishing Code questions was created by Nero
I was able to successfully add fishing to my game using the snippet found here - www.circlemud.org/pub/CircleMUD/contrib/.../players/fishing.txt

How do I take this code a step further and only allow castout command to work if there is a 'school of fish' object that is randomly generated within the room that has the fishing flag on it?

I don't want players to be able to just cram into the nearest fishing flagged to town and just sit there fishing all day. I want to force exploration meaning they have to roam around the ocean or rivers looking for the school of fish object to fish from. I want this school of fish object to randomly generate or self destruct in random rooms every few ticks.

Hopefully that makes sense.

Thanks!

Code:
ACMD(do_castout) {   struct obj_data *pole;   int fail;   if (!can_see_room(ch, IN_ROOM(ch))) {       send_to_char(ch, "It's too dark for you to castout here!\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;   }   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);     return;   }   /* Ok, now they've gone through the checks, now set them fishing */   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; } 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);     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; }
Last edit: 23 May 2022 02:36 by Nero.

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

More
24 May 2022 19:43 #10066 by thomas
Replied by thomas on topic Fishing Code questions
Ok, what you're trying to do with the "pools" is actually rather simple:
Code:
+ obj_vnum pool_vnum = 12345; + struct room_data* pool = world[IN_ROOM(ch)].contents; ... 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 with a pool\r\n"); + 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); return; } /* Ok, now they've gone through the checks, now set them fishing */ + extract_obj(pool); SET_BIT_AR(PLR_FLAGS(ch), PLR_FISHING);
And then make an object with relevant vnum and set up zone reloading to make sure they pop up on zone reset.

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

More
24 May 2022 19:44 #10067 by thomas
Replied by thomas on topic Fishing Code questions
Also, I'd consider adding a WAIT_STATE to the player when they miss or try without a pool in the room. This makes it possible for others to get it and prevents spamming.

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

More
25 May 2022 03:13 - 25 May 2022 03:59 #10068 by Nero
Replied by Nero on topic Fishing Code questions
So it looked like that worked after a few adjustments. It successfully blocks castout unless the pool object is in the room. But how do I get it to where these objects randomly spawn in rooms labeled fishing? I am assuming I have to go through all the rooms in the game that are flagged sector water and just do a zedit to load the object in the room and have just a maximum amount that loads in the game to create the randomization on zone resets?

Thanks!

Code:
ACMD(do_castout) {   struct obj_data *obj, *pole, *next, *pool = world[IN_ROOM(ch)].contents;   int fail, pool_vnum = 1021;   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");     return;     GET_WAIT_STATE(ch) = (2 RL_SEC);  }   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) = (5 RL_SEC);     return;   }   /* Ok, now they've gone through the checks, now set them fishing */   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; }
Last edit: 25 May 2022 03:59 by Nero.

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

More
26 May 2022 22:32 #10069 by thomas
Replied by thomas on topic Fishing Code questions
Yes, I'd use a less than 100% chance of spawning, to make it somewhat random which rooms get it.

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

More
26 May 2022 23:19 #10070 by Nero
Replied by Nero on topic Fishing Code questions
Thank you very much I have exactly what I was looking for thanks for your help! I decided to add a roll for when the object extracts to create a random affect on that as well to give them multiple chances of trying to fish from the same pool before it deletes.

Final code if anyone else is interested:
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; }
The following user(s) said Thank You: thomas

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

Time to create page: 1.157 seconds