Skill/Timer question

Posted by DjNiVeK on Fri 27 Feb 2004 12:25 PM — 9 posts, 26,901 views.

#0
Ok, I don't know much about timers, but what I just coded in gives me 3(6) bugs, but I don't know why or how. I tried a lot already, like making different do_functions for it, but it still didn't work. It probably is something easy, but yea...I can't figure it out lol.
I'll explain the idea for the code first:
I want to make it so that skills take up some time to use and their opponent can counter it with their skills.

I get the following errors:

magic.c: In function 'spell_water_dragon_blast':
magic.c:7338: error: syntax error before "ch_ret"
magic.c:7340: error: case label not within a switch statement
magic.c:7344: error: syntax error before "ch_ret"
magic.c:7347: error: case label not within a switch statement
magic.c:7351: error: syntax error before "ch_ret"
magic.c:7354: error: case label not within a switch statement

The code of the skill:
ch_ret spell_water_dragon_blast( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;

    level	= UMAX(0, level);
    level	= UMIN(150, level);
    dam		= number_range( 1, 7 )*number_range( 50, 75 );

    act( AT_MAGIC, "You start performing seals", ch, NULL, NULL, TO_CHAR);
    act( AT_MAGIC, "$n starts performing seals", ch, NULL, NULL, TO_CHAR);
    add_timer( ch, TIMER_NONE, 1, ch_ret spell_water_dragon_blast, 1 )
    ch->alloc_ptr = str_dup( staticbuf );
   case 1:
    act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_CHAR);
    act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_ROOM);
    DISPOSE( ch->alloc_ptr );
    add_timer( ch, TIMER_NONE, 2, ch_ret spell_water_dragon_blast, 2 )
    ch->alloc_ptr = str_dup( staticbuf );
   case 2:
    act( AT_MAGIC, "You yell: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_CHAR);
    act( AT_MAGIC, "$n yells: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_ROOM);
    DISPOSE( ch->alloc_ptr );
    add_timer( ch, TIMER_NONE, 3, ch_ret spell_water_dragon_blast, 3 )
    ch->alloc_ptr = str_dup( staticbuf );
   case 3:
    act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_ROOM);
    act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_CHAR);
    DISPOSE( ch->alloc_ptr );
    if ( IS_AFFECTED( victim, AFF_SHARINGAN ) )
    {
	if( victim->pcdata->learned[sn] )
	{
	return damage( ch, victim, dam, sn );
	}
        if( victim->mana < 150 )
        {
	return damage( ch, victim, dam, sn );
	}
	victim->pcdata->learned[sn] = 20;
        victim->mana -= 150;
	act( AT_FIRE, "Your sharingan starts spinning at a fast rate!\n\r", victim, NULL, NULL, TO_CHAR);
	act( AT_YELLOW, "You just copied Water Dragon Blast!\n\r", victim, NULL, NULL, TO_CHAR );
	act( AT_FIRE, "$n's sharingan starts spinning!\n\r", victim, NULL, NULL, TO_ROOM );
	return damage( ch, victim, dam, sn );
    }

    if ( saves_spell_staff( level, victim ) )
	dam /= 2;
    return damage( ch, victim, dam, sn );
}
Amended on Fri 27 Feb 2004 12:26 PM by DjNiVeK
Canada #1
Well, there are 2 problems here. One is there is no switch statement. This is needed to interpret the case labels. You can look at any of the other timer functions to see what I mean. There is also a good tutorial on how to use them at http://www.auricmud.com/snippets/timedelayedcommand.c. That helps to explain how it works.

The other problem is the ch_ret one. I'm pretty sure that in your add_time function, you do not need the ch_ret, only spell_water_dragon_blast.

Hope that helps.
#2
Ok, I did what you just said and I can compile it now (only a couple of warnings). However, if I try to use it now, it stops after the first 'return'.
The warnings are:

magic.c:7341: warning: passing arg 4 of 'add_timer' from incompatible pointer type
magic.c:7343: warning: 'return with no value, in function returning non-void
magic.c:7347: warning: passing arg 4 of 'add_timer' from incompatible pointer type
magic.c:7349: warning: 'return with no value, in function returning non-void
magic.c:7353: warning: passing arg 4 of 'add_timer' from incompatible pointer type
magic.c:7355: warning: 'return with no value, in function returning non-void
magic.c:7330: warning: 'dam might be used uninitialized in this function

My current code:

ch_ret spell_water_dragon_blast( int sn, int level, CHAR_DATA *ch, void *vo )
{
    CHAR_DATA *victim = (CHAR_DATA *) vo;
    int dam;

    switch( ch->substate )
    	{
       default:
    	level	= UMAX(0, level);
    	level	= UMIN(150, level);
    	dam	= number_range( 1, 7 )*number_range( 50, 75 );

    	act( AT_MAGIC, "You start performing seals", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "$n starts performing seals", ch, NULL, NULL, TO_CHAR);
    	add_timer( ch, TIMER_NONE, 1, spell_water_dragon_blast, 1 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 1:
    	act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_ROOM);
    	add_timer( ch, TIMER_NONE, 2, spell_water_dragon_blast, 2 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 2:
    	act( AT_MAGIC, "You yell: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "$n yells: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_ROOM);
    	add_timer( ch, TIMER_NONE, 3, spell_water_dragon_blast, 3 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 3:
    	act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_ROOM);
    	act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_CHAR);
    	DISPOSE( ch->alloc_ptr );
    	if ( IS_AFFECTED( victim, AFF_SHARINGAN ) )
    		{
		if( victim->pcdata->learned[sn] )
			{
			return damage( ch, victim, dam, sn );
			}
        	if( victim->mana < 150 )
        		{
			return damage( ch, victim, dam, sn );
			}
		victim->pcdata->learned[sn] = 20;
        	victim->mana -= 150;
		act( AT_FIRE, "Your sharingan starts spinning at a fast rate!\n\r", victim, NULL, NULL, TO_CHAR);
		act( AT_YELLOW, "You just copied Water Dragon Blast!\n\r", victim, NULL, NULL, TO_CHAR );
		act( AT_FIRE, "$n's sharingan starts spinning!\n\r", victim, NULL, NULL, TO_ROOM );
		return damage( ch, victim, dam, sn );
	}
    }

    if ( saves_spell_staff( level, victim ) )
	dam /= 2;
    return damage( ch, victim, dam, sn );
}
Canada #3
well, I think here the best thing to do is to change it to void instead of ch_ret at the beginning, and then change all the
return damage();

to

damage();
return;
#4
Don't think that return damage will matter much (maybe only to get the dam thing gone). I'll try that void thing aswell, but not sure if it will work.
#5
Error messages which I can't figure out:
skills.c:5587: error: conflicting types for 'do_water_dragon_blast'
mud.h:4154: error: previous_declaration of 'do_water_dragon_blast'

I changed it to a do_ because it gave bugs when putting viod and spell_ together.
Canada #6
there is a declaration in mud.h for the spells prototype that you need to change. Just do a search, and make sure the one in mud.h looks like the other.
#7
Ok, I got it bugless now (except for a couple of warnings, but yea, they aren't a big problem right now). What IS a problem, is that it only does the first case, and then quits. Next to that, you can't put it as a 'spell', but it won't work with 'cast'. It would be a pain to have it as a normal skill, because there will be more skills starting with 'water' and those can't be used then.

Current code:

void do_water_dragon_blast(CHAR_DATA *ch, char *argument)
{
    CHAR_DATA *victim;
    int dam;
    int sn;
    int level;

    switch( ch->substate )
    	{
       default:
    	level	= UMAX(0, level);
    	level	= UMIN(150, level);
    	dam	= number_range( 1, 7 )*number_range( 50, 75 );

    	act( AT_MAGIC, "You start performing seals", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "$n starts performing seals", ch, NULL, NULL, TO_CHAR);
    	add_timer( ch, TIMER_DO_FUN, 1, do_water_dragon_blast, 1 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 1:
    	act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "...ox tiger bird monkey rat ox...", ch, NULL, NULL, TO_ROOM);
        DISPOSE( ch->alloc_ptr );
    	add_timer( ch, TIMER_DO_FUN, 1, do_water_dragon_blast, 2 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 2:
    	act( AT_MAGIC, "You yell: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_CHAR);
    	act( AT_MAGIC, "$n yells: '...Bird! Suiton Suiryuudan no Jutsu!'", ch, NULL, NULL, TO_ROOM);
        DISPOSE(ch->alloc_ptr );
    	add_timer( ch, TIMER_DO_FUN, 1, do_water_dragon_blast, 3 );
    	ch->alloc_ptr = str_dup( victim->name );
        return;
       case 3:
    	act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_ROOM);
    	act( AT_MAGIC, "A large dragon made completely of water rises up and charges at $N", ch, NULL, NULL, TO_CHAR);
    	DISPOSE( ch->alloc_ptr );
    	if ( IS_AFFECTED( victim, AFF_SHARINGAN ) )
    		{
		if( victim->pcdata->learned[sn] )
			{
			damage( ch, victim, dam, sn );
			return;
			}
        	if( victim->mana < 150 )
        		{
			damage( ch, victim, dam, sn );
			return;
			}
		victim->pcdata->learned[sn] = 20;
        	victim->mana -= 150;
		act( AT_FIRE, "Your sharingan starts spinning at a fast rate!\n\r", victim, NULL, NULL, TO_CHAR);
		act( AT_YELLOW, "You just copied Water Dragon Blast!\n\r", victim, NULL, NULL, TO_CHAR );
		act( AT_FIRE, "$n's sharingan starts spinning!\n\r", victim, NULL, NULL, TO_ROOM );
		damage( ch, victim, dam, sn );
		return;
	}
    }

    if ( saves_spell_staff( level, victim ) )
	dam /= 2;
	damage( ch, victim, dam, sn );
    return;
}


What happens in mud:
-------
<Health: 30000 Chakra: 27380 Stamina: 30000> <#10300> test fish
You start performing seals

<Health: 30000 Chakra: 27380 Stamina: 30000> <#10300>
...ox tiger bird monkey rat ox...
-------
After that, it just stops.

Test is because it can't be used as a spell, so I made a temporary command that executes the skill.
Canada #8
Well, as to why its not coming back after case 1, I dunno. However, if you dispose of ch->alloc_ptr, without assigning it back into victim, you are going to run into some problems. Secondly, you may not be able to make it a spell and still have this functionality, I dunno.