[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  A few questions.

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: A few questions.
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  3  4  5  6  

Posted by David Haley   USA  (3,881 posts)  [Biography] bio   Moderator
Date Sun 26 Jun 2005 08:40 PM (UTC)  quote  ]
Message
Or, you could just do:
if ( result == 1 )
  // found something
else
  // found nothing
The point of the case statement is really to save you from having to write out lots of if/else if/else if/... if you're just using two alternatives you may as well just use if/else. The compiler should be smart enough to not generate a jump table with a two-branch case statement but it doesn't hurt to help it out.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Meerclar   USA  (554 posts)  [Biography] bio
Date Sun 26 Jun 2005 08:53 AM (UTC)  quote  ]

Amended on Sun 26 Jun 2005 09:01 AM (UTC) by Meerclar

Message
For lots cleaner code, you can do

case 1
found stuff message
case default
didnt find stuff message

Tends to be easier to read when you have all but 1 result with the same message. There's also the built in safety net of not crashing with a default if you somehow get a result not specified in your case struct.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Sat 25 Jun 2005 02:50 PM (UTC)  quote  ]
Message
Ok, Teacher, I've got my homework here. *Grins like a schoolboy*:

 void do_mine (CHAR_DATA *ch,)
 {
	char arg[MAX_INPUT_LENGTH]
	
 if ( ( shovel = get_eq_char(ch, WEAR_HOLD) ) == NULL)
 	{
	send_to_char( "You don't have anything to mine with! \n\r", ch);
	return;
	}
 if (ch->item_type ==ITEM_SHOVEL)
 	{
	act(AT_ACTION, "%n mines furiously. \n\r", ch, NULL, TO_ROOM);
	return;	
 if ( xIS_SET(ch->in_room->room_flags, ROOM_ORE) )
 	{
  switch( range = number_range( 1, 6 ) )
 	case 1:
	mine                = create_object( get_obj_index(OBJ_VNUM_ORE), 0 );
	obj_to_char(mine, ch);
    send_to_char("You mined a chunk of ore! \n\r", ch);
	break;
	case 2:
	send_to_char("You failed to mine anything useful. \n\r", ch);
	break;
	case 3:
	send_to_char("You failed to mine anything useful. \n\r", ch);
	break;
    case 4:
    send_to_char("You failed to mine anything useful. \n\r", ch);
	break;
    case 5:
	send_to_char("You failed to mine anything useful. \n\r", ch);
	break;
	case 6:
	send_to_char("You failed to mine anything useful. \n\r", ch);
	break;
	}
  }	

[Go to top] top

Posted by Robert Powell   Australia  (349 posts)  [Biography] bio
Date Mon 13 Jun 2005 11:52 AM (UTC)  quote  ]

Amended on Mon 13 Jun 2005 12:04 PM (UTC) by Robert Powell

Message
Whats problems are you getting??

Firstly there are no variables defined, your missing a some important code that should be under void do_mining(CHAR_DATA *ch) I dont think the char *argument is needed as your not accepting any imput from the char in this function.


 if (shovel->item_type ==ITEM_SHOVEL)
{
act(AT_ACTION, "%n mines furiously. \n\r", ch, NULL, TO_ROOM);
return; 


This should be (in sudo code)

if ch->wield != ITEM_SHOVEL
send ( you cannot mine without a shovel or a miners pick )
return.

I'm guessing that this next part needs to know which room and who is in it.

 if ( IS_SET(pRoomIndex->room_flags, ROOM_ORE) )
rand = number_range( 1, 6 )
switch(rand)


should look something like this. of cource use your own room_flag and variables

if (xIS_SET(ch->in_room->room_flags,ROOM_MINE))
    {
      switch(range = number_range( 1, 6 ))


Ok in this part, you have a sucessfull mine, you have created an object, but what you going to do with it, there is a set missing in there. The ore object needs to either be loaded into the pc's inv or into the room, or some other option.

 case 1:
mine = create_object( get_obj_index(OBJ_VNUM_ORE), 0 );
send_to_char("You mined a chunk of ore! \n\r", ch);
break;

Keep plugging away at this, your very close to having a working function there, Then i will bombard you with a few other things to take into concideration. HEH, like wait states or even better a substate, so if they use another command while mining they stop mining all together.

EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Mon 13 Jun 2005 12:25 AM (UTC)  quote  ]
Message
Ok folks, this is some code I'd like help with. It is the first piece I've come near completing on my own! Praise the Lord and pass the help! Now it gives me a number of errors when compiling, along the lines of "case label not within a switch statement" and BV32 not undeclared"(which is the ORE flag) and so on. Could yall help me fix my bugs por favor?
Gracias!

/* This is my mining code. I hope it works! --Longbow */

void do_mine (CHAR_DATA *ch, char *argument)
{
if ( ( shovel = get_eq_char(ch, WEAR_HOLD) ) == NULL)
{
send_to_char( "You don't have anything to mine with! \n\r", ch);
return;
}
if (shovel->item_type ==ITEM_SHOVEL)
{
act(AT_ACTION, "%n mines furiously. \n\r", ch, NULL, TO_ROOM);
return;
if ( IS_SET(pRoomIndex->room_flags, ROOM_ORE) )
rand = number_range( 1, 6 )
switch(rand)
case 1:
mine = create_object( get_obj_index(OBJ_VNUM_ORE), 0 );
send_to_char("You mined a chunk of ore! \n\r", ch);
break;
case 2:
send_to_char("You failed to mine anything useful. \n\r", ch);
break;
case 3:
send_to_char("You failed to mine anything useful. \n\r", ch);
break;
case 4:
send_to_char("You failed to mine anything useful. \n\r", ch);
break;
case 5:
send_to_char("You failed to mine anything useful. \n\r", ch);
break;
case 6:
send_to_char("You failed to mine anything useful. \n\r", ch);
break;
}



Godbless,
Longbow
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Wed 01 Jun 2005 10:38 PM (UTC)  quote  ]
Message
I've been trying to change how long each hour in a day is. Time is traveling waaaaay to fast so I want to slow it down. Now I've found the code for time in db.c around line 515, but I don't know how to read what does what. I can play around and see but I'd like to know what it might affect if I make hours longer? And can I make the hours longer by increasing the big number in line 519?
Also, there is a bit of code that seems to deal with weather that is commented out below the time code. Is this unfinished or buggy code and if not can I uncommment it and what will it do? :)

Thanks for helping me out!
Godbless,
Longbow
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Wed 01 Jun 2005 12:02 AM (UTC)  quote  ]
Message
Anybody got an idea about my code, in particular for my slice code? I want to get this fixed pretty soon and I think I'm almost there.

Thanks, Godbless,
Longbow
[Go to top] top

Posted by Gatewaysysop2   USA  (142 posts)  [Biography] bio
Date Sat 28 May 2005 06:15 PM (UTC)  quote  ]
Message
The AT_SKILL versus AT_MAGIC thing is only for coloration purposes. AT_MAGIC is dark blue I think, AT_SKILL I believe is bright green. Has no effect beyond that.


"The world of men is dreaming, it has gone mad in its sleep, and a snake is strangling it, but it can't wake up." -D.H. Lawrence
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Sat 28 May 2005 06:13 PM (UTC)  quote  ]
Message
This is my do_slice code:

void do_slice( CHAR_DATA *ch, char *argument )
{
OBJ_DATA *corpse;
OBJ_DATA *obj;
OBJ_DATA *slice;
bool found;
char buf[MAX_STRING_LENGTH];
char buf1[MAX_STRING_LENGTH];
found = FALSE;

if ( !IS_NPC(ch) && !IS_IMMORTAL(ch)
&& ch->level < skill_table[gsn_slice]->skill_level[ch->class] )
{
send_to_char("You are not learned in this skill.\n\r", ch );
return;
}

if ( argument[0] == '\0' )
{
send_to_char("From what do you wish to slice meat?\n\r", ch);
return;
}

int meat_counter;

meat_counter ++;

if meat_counter == 5;
{
extract_obj( corpse );
return;
}

if ( ( obj = get_eq_char( ch, WEAR_WIELD ) ) == NULL
|| ( obj->value[3] != 1 && obj->value[3] != 2 && obj->value[3] != 3
&& obj->value[3] != 11) )
{
send_to_char( "You need to wield a sharp weapon.\n\r", ch);
return;
}

if ( (corpse = get_obj_here( ch, argument )) == NULL)
{
send_to_char("You can't find that here.\n\r", ch);
return;
}

if (corpse->item_type != ITEM_CORPSE_NPC )
{
send_to_char("That is not a suitable source of meat.\n\r", ch);
return;
}
if ( get_obj_index(OBJ_VNUM_SLICE) == NULL )
{
bug("Vnum 24 not found for do_slice!", 0);
return;
}

if ( !can_use_skill(ch, number_percent(), gsn_slice ) && !IS_IMMORTAL(ch))
{
send_to_char("You fail to slice the meat properly.\n\r", ch);
learn_from_failure(ch, gsn_slice); /* Just in case they die :> */
if ( number_percent() + (get_curr_dex(ch) - 13) < 10)
{
act(AT_BLOOD, "You cut yourself!", ch, NULL, NULL, TO_CHAR);
damage(ch, ch, ch->level, gsn_slice);
}
return;
}

slice = create_object( get_obj_index(OBJ_VNUM_SLICE), 0 );

sprintf(buf, "meat fresh slice %s", corpse->name);
STRFREE(slice->name);
slice->name = STRALLOC(buf);

sprintf(buf, "a slice of raw meat from %s", corpse->short_descr);
STRFREE(slice->short_descr);
slice->short_descr = STRALLOC(buf);

sprintf(buf1, "A slice of raw meat from %s lies on the ground.", corpse->short_descr);
STRFREE(slice->description);
slice->description = STRALLOC(buf1);

act( AT_BLOOD, "$n cuts a slice of meat from $p.", ch, corpse, NULL, TO_ROOM);
act( AT_BLOOD, "You cut a slice of meat from $p.", ch, corpse, NULL, TO_CHAR);
slice->value[0] = 13;
obj_to_char(slice, ch);

learn_from_success(ch, gsn_slice);
return;
}

I'm getting a parse error before "meat counter" and I don't quite know how one goes about adding an increment to the counter, but other then that it's good. :)

Thanks and Godbless.

Longbow
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Sat 28 May 2005 05:48 PM (UTC)  quote  ]
Message
This is the code for spell_detect_poison, which I transferred to be a skill. I only changed the AT_MAGIC to AT_SKILL.

ch_ret spell_detect_poison( int sn, int level, CHAR_DATA *ch, void *vo )
{
OBJ_DATA *obj = (OBJ_DATA *) vo;

set_char_color( AT_SKILL, ch);
if ( obj->item_type == ITEM_DRINK_CON || obj->item_type == ITEM_FOOD
|| obj->item_type == ITEM_COOK)
{
if ( obj->item_type == ITEM_COOK && obj->value[2] == 0 )
send_to_char( "It looks undercooked.\n\r", ch );
else if ( obj->value[3] != 0 )
send_to_char( "You smell poisonous fumes.\n\r", ch );
else
send_to_char( "It looks very delicious.\n\r", ch );
}
else
{
send_to_char( "It doesn't look poisoned.\n\r", ch );
}

return rNONE;
}

Now I have never transferred a spell to a skill before, so what would I need to do to make this work? When I get ingame and try the skill it just brings up a blank line, but my proficiency goes up.

Thanks and Godbless,
Longbow
[Go to top] top

Posted by Robert Powell   Australia  (349 posts)  [Biography] bio
Date Thu 26 May 2005 06:16 AM (UTC)  quote  ]
Message
A simple counter would be a variable that you increment every time a particular action has taken place, then you can use an if statement to see if come condition is true to do something else.

int meat_counter;

 meat_counter ++;

 if meat_counter == 5;
   {
     extract_obj( corpse );
     return;
   }



EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Wed 25 May 2005 11:18 PM (UTC)  quote  ]
Message
How would one add a counter and a percent?

Also, I'm trying to transfer spells to skills. I transferred detect poison but and I don't get any errors compiling except it says the obj may not be called. The data starts with

OBJ_DATA *obj;

When I type the commmand ingame it says nothing, just adds a blank line.


Thanks and Godbless!
Longbow
[Go to top] top

Posted by Robert Powell   Australia  (349 posts)  [Biography] bio
Date Wed 25 May 2005 12:47 AM (UTC)  quote  ]
Message
Just remove the corpse object from the room once they have sliced off the meat. If you want them to slice more than 1 meat from a corpse befor the object is removes, just ad in a counter and increment it everytime the meat is sliced from a coprse, when it reaches the max they can slice, remove the corpse object from the room.

Peace.

EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
[Go to top] top

Posted by Longbow   (102 posts)  [Biography] bio
Date Tue 24 May 2005 04:46 PM (UTC)  quote  ]
Message
Ok that looks really helpful so I'll give it a try. But what about setting how many meat objects can be sliced off of the obj?

Thanks and Godbless,
Longbow
[Go to top] top

Posted by Robert Powell   Australia  (349 posts)  [Biography] bio
Date Mon 23 May 2005 11:21 PM (UTC)  quote  ]
Message
Take a look at the existing skin code in skills.c. This code is used by Deadlies to skin there pk oponent and keep as a trophy.

With some simple modification it will skin the corpse of NPC instead of PC.

Now to make it give different skins for different mobs, the way the code works it already will name each skin the name of the mobile/corpse name, so you dont realy need to have lots of different skin objects. So the simplest way would be to apply the cost value either randomly so each skin has a different value.

{
range = number_range(1, 2)
  if range == 1
     skin->cost == ch->level * 4;
  if range == 2
     skin->cost == ch->level * 8;
}


Another way would be to look at the name of the corpse object, and if it contains a key word then apply a value based on that.

Now im not sure on propper syntax here as i have never realy used strstr, but this might work

if (strstr(corpse->name, "deer"))
 {
    skin->cost = 500;
 }
else if (strstr(corpse->name, "rabbit"))
 {
    skin->cost = 100;
 }
else
    skin->cost = 50; 



Hope that is some help and not more confusion, if you get stuck post again and we will see what we can do.

Peace

EldhaMUD Game Developments
The_Fury: Lead Developer, Head Coder
http://fury.eldhamud2.org
[Go to top] 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.


19,917 views.

This is page 1, subject is 6 pages long: 1 2  3  4  5  6  [Next page]

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]