Making unaffect able to remove a single spell as well as all spells

Login to reply  Page: « < 1 of 1 > »
11 Jul 2010 - 22:202829
Making unaffect able to remove a single spell as well as all spells
I wanted immortals to be able to remove affects by the spell that caused them without removing all spells. To achieve this goal I have the code below:

act.wizard.c in the do_wizutil ACMD replace the case SCMD_UNAFFECT with the following:
    case SCMD_UNAFFECT:
	  half_chop(argument, arg, arg2);
	  bool find = FALSE, found = FALSE;
	  if (*arg2 && arg2 != NULL)
	     find = TRUE;
	  if (vict->affected || AFF_FLAGS(vict)) {
		while (vict->affected && found == FALSE) {
			/* Ok, we're looking for something, is this it? */
			if (find == TRUE && !strcmp(arg2, skill_name(vict->affected->type))) {
			    if (AFF_FLAGGED(vict, vict->affected->bitvector))
					REMOVE_BIT(AFF_FLAGS(vict), vict->affected->bitvector);
				affect_remove(vict, vict->affected);
				if (!vict->affected->next || !(vict->affected->next->type == vict->affected->type))
					found = TRUE;
			/* We're looking for somthing and we've cycled all the way through yet been
			unable to find it... so we need to break out of the loop */
			} else if (!vict->affected->next && find == TRUE) {
				break;
			/* Not looking for something, so remove them all */
			} else if (find == FALSE) {
				affect_remove(vict, vict->affected);
			}
		}
			if (find == FALSE) { /* Not looking, we removed all */
				AFF_FLAGS(vict) = 0;
				send_to_char(vict, "There is a brief flash of light!\r\nYou feel very different.\r\n");
				send_to_char(ch, "All spells removed.\r\n");
			} else if (found == TRUE) { /* Looking, found, removed */
				send_to_char(vict, "There is a brief flash of light!\r\nYou feel slightly different.\r\n");
				send_to_char(ch, "The spell %s has been removed.\r\n", arg2);
			} else { /* Looking, and couldn't find */
				send_to_char(ch, "%s does not seem affected by %s.\r\n", CAP(arg), arg2);
			}
      } else {
		send_to_char(ch, "Your victim does not have any affections!\r\n");
		return;
      }
      break;

And at the top of ACMD(do_wizutil) change: char arg[MAX_INPUT_LENGTH]; to char arg[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];


__________________
Owner/Coder/Head Admin
Caer Dubrin

Last edited by ralgith (11 Jul 2010 - 22:40) Reason: oops, missed a small check that caused crashes, edited to fix. 2nd edit to replace two_args with half_chop
11 Jul 2010 - 22:382830
One problem
On further testing I realized that this will not work with multi-word spell names. I need to set this up to do so.
One solution would be to use half_chop instead of two_arguments...

However, if I re-write this so that imm's can use abbreviations of spell names, I'll do it so that its like skillset.

Until then, if you use this use half_chop instead of the two_arguments, if I still can I'll edit my post to correct this.


__________________
Owner/Coder/Head Admin
Caer Dubrin
12 Jul 2010 - 01:302831
Ok, I think I got all the bugs worked out...
Sorry for all the posts, I didn't think this through all the way when I did it at first.

act.wizard.c in do_wizutil:
Replace char arg[MAX_INPUT_LENGTH]; with char arg[MAX_INPUT_LENGTH], arg2[MAX_INPUT_LENGTH];
Replace one_argument(argument, arg); with argument = one_argument(argument, arg);
    case SCMD_UNAFFECT:
	  skip_spaces(&argument);
	  bool find = FALSE, found = FALSE;
	  int qend, skill = 0;
	  if (*argument && argument != NULL) {
	     find = TRUE;
		  if (*argument != '\'') {
			send_to_char(ch, "Spell must be enclosed in: ''\r\n");
			return;
	  	}
		  for (qend = 1; argument[qend] && argument[qend] != '\''; qend++)
		    argument[qend] = LOWER(argument[qend]);
		  if (argument[qend] != '\'') {
			send_to_char(ch, "Spell must be enclosed in: ''\r\n");
			return;
		  }
		  strlcpy(arg2, (argument + 1), sizeof(arg2));		/* strcpy: OK (MAX_INPUT_LENGTH <= MAX_STRING_LENGTH) */
		  arg2[qend -1] = '{{uie-code}}';
		  skill = find_skill_num(arg2);
		  if (skill <= 0 || skill > MAX_SPELLS) {
			send_to_char(ch, "Unrecognized spell.\r\n");
			return;
		  }
		  /* Ok, we found it, and now we want to make sure we have the full spell name */
		  if (strcmp(arg2, skill_name(skill)))
			strlcpy(arg2, skill_name(skill), sizeof(arg2));
	  }

	  if (vict->affected || AFF_FLAGS(vict)) {
		while (vict->affected) {
			/* Not looking for something, so remove them all */
			if (find == FALSE) {
				affect_remove(vict, vict->affected);
			}
			/* Ok, we're looking for something, is this it? */
			else if (find == TRUE && skill == vict->affected->type) {
			    if (AFF_FLAGGED(vict, vict->affected->bitvector))
					REMOVE_BIT(AFF_FLAGS(vict), vict->affected->bitvector);
				affect_remove(vict, vict->affected);
				if (!vict->affected || !(vict->affected->next->type == vict->affected->type)) {
					found = TRUE;
					break;
				}
			/* We're looking for somthing and we've cycled all the way through yet been
			unable to find it... so we need to break out of the loop */
			}
			else if (!vict->affected->next && find == TRUE)
				break;
		}
			if (find == FALSE) { /* Not looking, we removed all */
				AFF_FLAGS(vict) = 0;
				send_to_char(vict, "There is a brief flash of light!\r\nYou feel very different.\r\n");
				send_to_char(ch, "All spells removed.\r\n");
			} else if (found == TRUE) { /* Looking, found, removed */
				send_to_char(vict, "There is a brief flash of light!\r\nYou feel slightly different.\r\n");
				send_to_char(ch, "The spell %s has been removed.\r\n", arg2);
			} else { /* Looking, and couldn't find */
				send_to_char(ch, "%s does not seem affected by %s.\r\n", GET_NAME(vict), arg2);
			}
      } else {
		send_to_char(ch, "Your victim does not have any affections!\r\n");
		return;
      }
      break;

If you have any issues using it or see any issues with the code let me know.


__________________
Owner/Coder/Head Admin
Caer Dubrin
12 Jul 2010 - 15:172833
nice
what a nice little addition. this should be stock!


12 Jul 2010 - 15:502834
nice
Quote rudeboyrave:
what a nice little addition. this should be stock!


Well, that was kind of why I posted it ;)

But its also always nice to have someone else sanity check your code, and since I'm a solo dev on this project, forums are currently my sole access to another set of eyes for "desk checking" code.


__________________
Owner/Coder/Head Admin
Caer Dubrin
Login to reply  Page: « < 1 of 1 > »