Re: [code][long]wpn.w.spell.patch and obuild.06

From: Sammy (Samedi@cris.com)
Date: 01/21/97


On Tue, 21 Jan 1997, Ghost Shaidan wrote:

- I have put in this...
-     for(j=0;j < MAX_SPELL_AFFECT; j++){
-      if (obj_proto[i].spell_affect[j].spelltype > 0) {
-        fprintf(new_file, "S\n%i %i %i\n",
- obj_proto[i].spell_affect[j].spelltype,obj_proto[i].spell_affect[j].level,
- obj_proto[i].spell_affect[j].percentage);
-      }
-     }
- 
- in the objs_to_file function, and this:
- 
-     for(i-0;i < MAX_SPELL_AFFECT; i++){
*** hmmmm ^^^  Is this a typo, or actual code? ***
-       dest->spell_affect[i].spelltype  =
src->spell_affect[i].spelltype;
-       dest->spell_affect[i].level      = src->spell_affect[i].level;
-       dest->spell_affect[i].percentage = src->spell_affect[i].percentage;
-     }
- 
- in the copy_object function..
- 
- and still nothing, I fully admit to being in over my head here, but i am
- trying...i cant seem to think of even a way to test what i am doing wrong? 
- any ideas or tips? or references (besides Sammy's generosity?)

Check the comment above in your code.  If that's your code, that i-0 would
probably be the culprit.  I looked at some code I wrote a long time ago to
put weapon spells in the olc, and your code is identical to mine in
objs_to_file and copy_object.  Here's what I've got for oset:

  case 67:
    if (GET_OBJ_TYPE(OBJ_NEW(ch)) != ITEM_WEAPON) {
      send_to_char("You can only set autocasting spells on weapons!\r\n", ch);
      return;
    }
    if(!*val_arg) {
      send_to_char("Usage   :  oset spell '<spell>' <level> <%>\r\n", ch);
      send_to_char("Use this to set a weapon's autocast spell.\r\n", ch);
      send_to_char("Use oset spell '<spell>' 0 to remove a spell.\r\n", ch);
      send_to_char("Example :  oset spell 'fireball' 20 10\r\n", ch);
      return;
    }
    
    s = strtok(val_arg, "'");

    if(s == NULL) {
      send_to_char("Use ' to enclose the spell name please.\r\n", ch);
      return;
    }
    ex = strtok(NULL, "'");

    spell = find_skill_num(s);

    if(spell < 1 || spell > MAX_SPELLS) {
      send_to_char("Can't find that spell.\r\n", ch);
      return;
    }

    if(!ex) {
      send_to_char("Usage   :  oset spell '<spell>' <level> <%>\r\n", ch);
      send_to_char("Use this to set a weapon's autocast spell.\r\n", ch);
      send_to_char("Use oset spell '<spell>' 0 to remove a spell.\r\n", ch);
      send_to_char("Example :  oset spell 'fireball' 20 10\r\n", ch);
      return;
    }

    t1 = atoi(ex);
    half_chop(ex, field, val_arg);
    t2 = MIN(100, MAX(1, atoi(val_arg)));

    for(i = i; i < MAX_SPELL_AFFECT; i++) {
      if(OBJ_NEW(ch)->spell_affect[i].spelltype == spell) {
	if(t1 == 0) {
	  OBJ_NEW(ch)->spell_affect[i].spelltype = 0;
	  send_to_char("Spell removed.\r\n", ch);
	  return;
	}
	OBJ_NEW(ch)->spell_affect[i].spelltype = spell;
	OBJ_NEW(ch)->spell_affect[i].level = t1;
	OBJ_NEW(ch)->spell_affect[i].percentage = t2;
	send_to_char("Spell changed.\r\n", ch);
	return;
      }
      if(OBJ_NEW(ch)->spell_affect[i].spelltype == 0)
	if(minaff == -1) minaff = i;
    }

    if(minaff == -1) {
      send_to_char("No free spell slots on this object.\r\n", ch);
      return;
    }

    OBJ_NEW(ch)->spell_affect[minaff].spelltype = spell;
    OBJ_NEW(ch)->spell_affect[minaff].level = t1;
    OBJ_NEW(ch)->spell_affect[minaff].percentage = t2;
    SET_BIT(OBJ_NEW(ch)->obj_flags.extra_flags, ITEM_MAGIC);
    send_to_char("Spell added.\r\n", ch);

    return;

If you take out the check for weapons, you can drop it right in with a
single keyword instead of one for each value.  It also checks to make sure
the spell is valid and has the capability to remove spells from an object
:)

Sam

+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST