31 Mar, 2010, jurdendurden wrote in the 1st comment:
Votes: 0
I am reworking special.c to be more… intelligent. I'm trying to have my mobs cast defensive spells upon themselves but am running into issues getting this to work properly. I know that when they cast offensive spells it just calls the direct spell_function for whatever spell you're trying to cast, then passes the arguments, like this:

(*skill_table[sn].spell_fun) (sn, ch->level, ch, victim, TARGET_CHAR);


I cannot seem to get this to work properly when targetting the mob itself, instead of a player/other mob.
This is what i'm trying:

(*skill_table[sn].spell_fun) (sn, ch->level, ch, NULL, TARGET_CHAR);


Also tried:

(*skill_table[sn].spell_fun) (sn, ch->level, ch, victim, TARGET_NULL);


And:

do_function(ch, &do_cast, wiz_buff_high[i]);


With wiz_buff_high being a small char const array of spells looking like this:

const char * wiz_buff_high[] =
{
"armor",
"shield",
"fly",
"blink",
"giant strength"
"displacement",
"extension",
"stone skin"
};


Any ideas?
31 Mar, 2010, Abel wrote in the 2nd comment:
Votes: 0
I'm a little out of it, but based on my experience, something like…
(*skill_table[sn].spell_fun) (sn, ch->level, ch, ch, TARGET_CHAR);

should work?

Alternatively, it looks like you should be able to send in the
(*skill_table[sn].spell_fun) (sn, ch->level, ch, NULL, TARGET_CHAR);

If you change TARGET_CHAR to something like TARGET_SELF and then account for it in the spell handler itself.

The former case seems easier though :P
31 Mar, 2010, jurdendurden wrote in the 3rd comment:
Votes: 0
Ahh sure enough I should have realized that. Thanks :)
31 Mar, 2010, Skol wrote in the 4th comment:
Votes: 0
You could also do like:
sprintf (buf, "cast %s self", argument); // where argument is the spell name
do_function (ch, &do_mob, buf);


Just a blah off the top of my head, but do that where argument is each of the spells etc. I went back in and made my mobiles use mana, cast like players (affected by room silence, confusion, intelligence etc).
01 Apr, 2010, Erok wrote in the 5th comment:
Votes: 0
Skol said:
You could also do like:
sprintf (buf, "cast %s self", argument); // where argument is the spell name
do_function (ch, &do_mob, buf);


I think this should be the preferred approach when having your mobiles do anything special. Build up a command string just like a player and run it through the parser. Then you have one processing path for both players and mobiles, who will then be subject to the same rules of the game, with mobile actions typically being driven by scripts and/or events.
0.0/5