Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Skill/Timer question

Skill/Timer question

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by DjNiVeK   (48 posts)  Bio
Date Fri 27 Feb 2004 12:25 PM (UTC)

Amended on Fri 27 Feb 2004 12:26 PM (UTC) by DjNiVeK

Message
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 );
}
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #1 on Fri 27 Feb 2004 03:37 PM (UTC)
Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by DjNiVeK   (48 posts)  Bio
Date Reply #2 on Fri 27 Feb 2004 04:47 PM (UTC)
Message
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 );
}
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #3 on Fri 27 Feb 2004 07:53 PM (UTC)
Message
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;

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by DjNiVeK   (48 posts)  Bio
Date Reply #4 on Fri 27 Feb 2004 11:25 PM (UTC)
Message
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.
Top

Posted by DjNiVeK   (48 posts)  Bio
Date Reply #5 on Sat 28 Feb 2004 12:22 AM (UTC)
Message
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.
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #6 on Sat 28 Feb 2004 02:53 AM (UTC)
Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

Posted by DjNiVeK   (48 posts)  Bio
Date Reply #7 on Sat 28 Feb 2004 07:38 PM (UTC)
Message
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.
Top

Posted by Greven   Canada  (835 posts)  Bio
Date Reply #8 on Sat 28 Feb 2004 09:39 PM (UTC)
Message
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.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


23,038 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.