Welcome to the Builder Academy

Question case spell hickup - whats wrong ?

More
15 Oct 2017 11:15 - 15 Oct 2017 11:42 #6997 by JTP
I made this spell, the code compiles, spell works when there is an ITEM_TREE in the room.

BUT

When there is no tree, i some times only get an Okay. when cast. Other times i get the correct send_to_char.

So whats up, would be good to get the send_to_char every time there is no tree.
Code:
/* Every spell that does an affect comes through here.  This determines the  * effect, whether it is added or replacement, whether it is legal or not, etc.  * affect_join(vict, aff, add_dur, avg_dur, add_mod, avg_mod) */ #define MAX_SPELL_AFFECTS 5     /* change if more needed */ void mag_affects(int level, struct char_data *ch, struct char_data *victim,                       int spellnum, int savetype) {   struct affected_type af[MAX_SPELL_AFFECTS];   bool accum_affect = FALSE, accum_duration = FALSE;   const char *to_vict = NULL, *to_room = NULL;   int i, j;   if (victim == NULL || ch == NULL)     return;   for (i = 0; i < MAX_SPELL_AFFECTS; i++) {     new_affect(&(af[i]));     af[i].spell = spellnum;   }   switch (spellnum) {   case SPELL_TREE_TRAVEL: { struct obj_data *tree; for (tree = world[ch->in_room].contents; tree; tree = tree->next_content) {   if (GET_OBJ_TYPE(tree) != ITEM_TREE) {     send_to_char(ch, "But there is no tree around to travel from.\r\n");     return;     }     af[0].duration = 24;     SET_BIT_AR(af[0].bitvector, AFF_TREE_TRAVEL);     accum_duration = FALSE;     to_vict = "You feel one with the trees!";  } }     break; } /* end of cases */
Last edit: 15 Oct 2017 11:42 by JTP.

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

More
15 Oct 2017 12:20 #6999 by zusuk
Hey Jan!

Sorry I have not been able to help you figure this out... I am not quite sure how to make it an affection spell... would need to know -exactly- what you want your spell to do, then check all the appropriate places in the code to really figure out what is going on.

For fun, and maybe it can help out, I threw our version of 'transport via plants' spells on the snippets though...

tbamud.com/forum/8-snippets/4259-transpo...vel-druid-spell-idea

Good luck,
Zusuk

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

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

More
15 Oct 2017 12:29 #7000 by zusuk
I am just guessing, but based on what you posted, I would adjust it this way:
Code:
switch (spellnum) { case SPELL_TREE_TRAVEL: struct obj_data *tree = NULL; bool found_tree = FALSE; for (tree = world[ch->in_room].contents; tree; tree = tree->next_content) { if (GET_OBJ_TYPE(tree) == ITEM_TREE) { /* found a tree! */ found_tree = TRUE; af[0].duration = 24; SET_BIT_AR(af[0].bitvector, AFF_TREE_TRAVEL); accum_duration = FALSE; to_vict = "You feel one with the trees!"; break; /* we are "breaking" out of the loop */ } } /* end tree search */ if (found_tree == FALSE) { /* did not find any trees! */ send_to_char(ch, "But there is no tree around to travel from.\r\n"); } /* finish case */ break; } } /* end of cases */

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

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

More
15 Oct 2017 14:41 #7002 by zusuk
if (GET_OBJ_TYPE(tree) != ITEM_TREE) {

should be

if (GET_OBJ_TYPE(tree) == ITEM_TREE) {

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

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

More
15 Oct 2017 14:42 #7003 by JTP
Seems to make it work better.
BUT

Now when the spell is already in affect, i get this when trying to cast again:
Okay.
But there is no tree around to travel from.
Nothing seems to happen.

The right way should be:
Okay.
Nothing seems to happen.

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

More
15 Oct 2017 14:51 #7004 by zusuk
with the code i posted, the only way that is possible is if the tree disappeared between casting (i.e. there is no tree now)

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

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

Time to create page: 0.273 seconds