Welcome to the Builder Academy

Question Spec Proc on Object/not firing question (new to coding)

More
09 Jun 2016 11:18 - 09 Jun 2016 20:49 #5985 by Barnes
Hello. I'm new to coding. I've been tinkering with the tba code for a month or two and tried my hand at assigning a spec proc to an object the pre trigger/old style way. As far as I know, I have it assigned everywhere correctly and the code compiles for me no warnings. I left out the if (cmd) return FALSE while testing, so that I can see the proc actually works. However, the proc ONLY works when any command is entered, not randomly like the mob specs I've written do. Here is my code, be gentle! Thanks for any feedback.

Also, in order for the object to be the actual caster of a spell, would a secondary procedure for spells need to be written, or is there a way to accomplish this with existing code?
Code:
SPECIAL(spectral) { struct obj_data *find_obj_by_vnum(int vnum); struct obj_data *obj; struct char_data *vict = FIGHTING(ch); int is_wearing = FALSE; if (GET_POS(ch) != POS_FIGHTING) { return FALSE; } obj = ch->equipment[WEAR_NECK_1]; if (obj){ if (obj_index[obj->item_number].vnum == 34707){ is_wearing = TRUE; } } if (! is_wearing) return FALSE; if (ch->in_room != vict->in_room) { if (FIGHTING(ch) && FIGHTING(ch) == vict) stop_fighting(ch); return FALSE; } while (GET_POS(ch) == POS_FIGHTING) { switch (rand_number(0, 5)) { case 0: act("\r\n\t[f330]$p begins pulsing and vibrating!!!\tn\r\n",TRUE,ch,obj,0,TO_CHAR); act("\r\n$p begins pulsing and vibrating!!!!!\r\n",TRUE,ch,obj,0,TO_ROOM); cast_spell(ch, vict, NULL, SPELL_FIREBALL); return TRUE; default: return FALSE;} } return FALSE; }
Last edit: 09 Jun 2016 20:49 by Barnes. Reason: to wrap the code

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

More
09 Jun 2016 19:55 #5986 by thomas
how is this assigned? (and wrap your code in [ code ] tags, please :)

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

More
09 Jun 2016 20:08 #5988 by Barnes
Ok figure out how to wrap the code.
Code:
SPECIAL(spectral);
Code:
ASSIGNOBJ(34707, spectral);
Code:
{"Spectral", spectral },

is this what you're asking?

thanks for responding.

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

More
09 Jun 2016 20:48 - 09 Jun 2016 20:49 #5991 by thomas
specprocs are triggered from interpreter.c before the command is actually executed.
This means that the user needs to input something to trigger it.

I see two ways to get what you're doing to work - either switch to using a dg trigger (see examples in existing world files) or make certain types of specprocs fire when in battle.

If you look in interpreter.c ( github.com/tbamud/tbamud/blob/master/src/interpreter.c#L982 ) you can see how the specials are called.

If you were to add something similar to fight.c ( github.com/tbamud/tbamud/blob/master/src/fight.c#L950 ), you could trigger the spec_proc each round:
Code:
if (MOB_FLAGGED(ch, MOB_SPEC) && GET_MOB_SPEC(ch) && !MOB_FLAGGED(ch, MOB_NOTDEADYET)) { char actbuf[MAX_INPUT_LENGTH] = ""; (GET_MOB_SPEC(ch)) (ch, ch, 0, actbuf); } /* special in equipment list? */ + for (j = 0; j < NUM_WEARS; j++) { + if (GET_EQ(ch, j) && GET_OBJ_SPEC(GET_EQ(ch, j)) != NULL && !MOB_FLAGGED(ch, MOB_NOTDEADYET)) { + char actbuf[MAX_INPUT_LENGTH] = ""; + (GET_OBJ_SPEC(GET_EQ(ch, j))) (ch, GET_EQ(ch, j), NULL, actbuf) + } + } }

Note that you'll have to do some sanity checking in your spec proc - are we still fighting? Are we in the same room as the target? Was there no "cmd" given (so we know this is triggered this way)?
Last edit: 09 Jun 2016 20:49 by thomas.
The following user(s) said Thank You: Barnes

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

More
09 Jun 2016 20:54 #5992 by Barnes
Thank you so much.

I was assuming that spec procs on objects like this worked/fired randomly through a pulse system.

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

More
11 Jun 2016 05:15 #6000 by Barnes
Thanks again to Thomas, got the procs firing normally.

After reading through the spell casting procedures, I was wondering if there was a way to make the object
tied to the spec proc be the actual caster of the spell or skill instead of when the object proc fires, making
the pc call the spell?

thanks,
Ben

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

Time to create page: 0.251 seconds