A few questions.

Posted by Longbow on Wed 30 Mar 2005 11:49 PM — 77 posts, 258,760 views.

#0
Howdy yall, I'm not the best of coders(really poor) so I'm requesting that if you reply you explain your answers thoroughly please. Thanks!

1. Is is possible to skin corpses? I feel certain there is a way to do this, but I have only had Smaug for a little while.

2. Is it possible to make objects out of other objects? For example, if I had a flour obj and a waterskin obj and I wanted to type bake/cook/make bread, how would I go about turning it into a bread object? The same question applies to making clothing out of cloth.

3. Everytime I aassign myself an area and savearea in it, it erases all my work when I reboot the MUD. Why is this happening?

4. I want to make a fishing program where there is a random chance of a fish passing by(ie a message telling you that you see a fish swimming by), and when that message occurs if you type catch there will be a chance you will catch the fish, thus adding a fish obj to your inventory.

5. I want a turn-based combat system(ie, One player attacks and then the battle stops. Then the other person attacks, and so forth.), but I'm not sure about what to remove. I still have to make it so that after a period of time a NPC will attack since unlike players they have no one to type in attacks. I saw an article somewhere in this forum about it but the coding is over my head.

I may add more questions later but enough for now. If you can only answer one or two of them that's fine, I will be glad for the help.

Godbless,
Longbow
Amended on Thu 31 Mar 2005 12:00 AM by Longbow
Australia #1
1. yes, there is a skin command in smaug already, which is used by PK's to skin each other as trophies.

2. yes, there are a number of ways you can achieve this, how you would do it would depend on the outcome you want. For your baking example you would check in the baking function that the player had the objects needed to bake a cake, remove the objects from their inventory and then put a cake object in.

3. If you have aassigned an area to yourself you cannot savearea, you must use foldarea to save changes. savea only works on prototype area's, not ones that are live and in the game.

4. WHat is it with fishing, i have been asked to add fishing into my mud by another imm, read about it in a thread oon mudconnect,, was asked to code it for another mud and now we have it again. Below sudo code by me LOL.

check they entered the command and any paramiters correct
check they can use the skill/ if its a skill
check they are in the right place to fish/ cant fish in the city huh
check they have the right objects/ bait and tackle
bailout if if any of these fail
remove bait / 1 bait 1 cast
roll dice to see of there is a fish
if no fish, wait till they retrieve line then end.
if fish is there, wait till they pull  the line,
% chance of catching based on gear used and type of fish.
if no catch wait till they retrieve line then end
if caught fish, load fish object to room, end

That would cover most of what you would need to d for fishing.

5. this is way over my head, if your struggeling with some of the easy things then i would wait on this for a long time to come.

Hope i have been of some help.
#2
Ok, thanks for the help so far. A few questions though...

1. I couldn't seem to skin ANY corpse, be it a mob or a pc. I want to be able to skin mobs in particular.

2. Where would one insert his baking function(ie, which file, there are multiple ones with commands in them)?

3. Will have to try this, thanks!




Thanks again, if anybody has any more ideas or additions to the old ones please let me know.

Godbless,
Longbow
Australia #3
The skill do_skin is in skills.c, if you dont have it, here is the code for it, it doesnt need many changed to make it skin mobs.

void do_skin( CHAR_DATA *ch, char *argument)
{
    OBJ_DATA *korps;
    OBJ_DATA *corpse;
    OBJ_DATA *obj;
    OBJ_DATA *skin;
    bool found;
    char *name;
    char buf[MAX_STRING_LENGTH];
    found = FALSE;
 
    if ( !IS_PKILL(ch) && !IS_IMMORTAL(ch) )
    {
        send_to_char( "Leave the hideous defilings to the killers!\n", ch );
        return;
    }
    if ( argument[0] == '\0' )
    { 
        send_to_char( "Whose corpse do you wish to skin?\n\r", ch );
        return;
    }
    if ( (corpse=get_obj_here(ch, argument)) == NULL )
    {
	send_to_char( "You cannot find that here.\n\r", ch );
	return;
    }
    if ( (obj=get_eq_char(ch, WEAR_WIELD)) == NULL )
    {
        send_to_char( "You have no weapon with which to perform this deed.\n\r", ch );
        return;
    }
    if ( corpse->item_type != ITEM_CORPSE_NPC )
    {
        send_to_char( "You can only skin the bodies of player characters.\n\r", ch);
        return;
    }
 /*   if ( obj->value[3] != 1
    &&   obj->value[3] != 2
    &&   obj->value[3] != 3
    &&   obj->value[3] != 11 )
    {
        send_to_char( "There is nothing you can do with this corpse.\n\r", ch );
        return;
    } */
    if ( get_obj_index( OBJ_VNUM_SKIN ) == NULL )
    {
      bug( "Vnum 23 (OBJ_VNUM_SKIN) not found for do_skin!", 0);
      return;
    }
    korps               = create_object( get_obj_index(OBJ_VNUM_CORPSE_PC), 0 );
    skin                = create_object( get_obj_index(OBJ_VNUM_SKIN), 0 );
    name                = IS_NPC(ch) ? korps->short_descr : corpse->short_descr;
    sprintf( buf, skin->short_descr, name );
    STRFREE( skin->short_descr );
    skin->short_descr = STRALLOC( buf );
    sprintf( buf, skin->description, name );
    STRFREE( skin->description );
    skin->description = STRALLOC( buf );
    act( AT_BLOOD, "$n strips the skin from $p.", ch, corpse, NULL, TO_ROOM);
    act( AT_BLOOD, "You strip the skin from $p.", ch, corpse, NULL, TO_CHAR);
  act( AT_MAGIC, "\nThe skinless corpse is dragged through the ground by a strange force...", ch, corpse, NULL, TO_CHAR);
    act( AT_MAGIC, "\nThe skinless corpse is dragged through the ground by a strange force...", ch, corpse, NULL, TO_ROOM);
    extract_obj( corpse ); 
    obj_to_char( skin, ch );
    return;
}


Dont forget to make the required entries in tables.c and mud.h, and then, when cleaned and made, cedit the command.


As for what file to put your baking command in, it is realy a matter of choice, tho, as it is a skill(if your making it a skill that a class receives) and not a command, you could put it in skills.c with all the other skills.

On the other hand, if your going to be making a lot of new skills that are all related, (baking, fishing, mining, chop_trees_down, ect) you might want to start a new C file, crafting.c where all the crafting related skills are kept. Ultimately its up to you to place the functions in a place that is easy to find them later.
Amended on Sat 02 Apr 2005 05:24 AM by Robert Powell
#4
Ugh, I wish I knew C.


I found I did have that skin bit in my file, but for some reason I still can't skin folks! Ugh....


BTW, is there a simple way to add more than one type of money?


Thanks for all the help and Godbless,
Longbow
Australia #5
Ok with the skin code this is what you want to look at and change to suit how you want it to work.

if ( !IS_PKILL(ch) && !IS_IMMORTAL(ch) )
    {
        send_to_char( "Leave the hideous defilings to the killers!\n", ch );
        return;
    }


In this section you have to be a Pkiller or an Immortal to skin

if ( corpse->item_type != ITEM_CORPSE_NPC )


Hmmm guess i changed this already so that you can skin the corpses of Mobiles instead of Players. Yours will read ITEM_CORPSE_PC.

I dont know about a simple way to add more than one type of money. There is a snippet out there that adds in Silver and Bronze. It was written by Sadiq, i think you can find it on Samsons snippet site.

I just looked through it, seems to be a lot of aditions there, i wouldnt say that it is a simple snippet to add tho.
#6
Three questions: do I need to make an object for the ITEM_CORPSE_NPC or does it figure out that item for itself?

Second question: What's the link of that Sadiq fellow's page? I might take a look at that.

Third question: I tried foldarea and it says it saved but my mob was gone! Does it have to be a prototype or something?

Thanks for all your help and Godbless!

Longbow
Australia #7
1. ITEM_CORPSE_NPC is defined in mud.h, the actual items vnum is a part of limbo.are, tho i cannot think of hand what the vnum is. So no you dont need to make an object for this as it is already a part of limbo.are

2. It www.afkmud.com its in the download section under sadiq's stuff, its called alternate currency system.



3. If you have a look in the area file you should find the mobile, that you created there, as long as you have created one within the vnum range of the area file.

When you make a mobile, you also have to create a reset for the mobile to make it come into the area when the area resets.

There are a number of ways to acheive this. Instaroom, Instazone, and Reset are all commands that can be used to make a reset. Read the help files on them to become more familure with them.

On another note, if your having trouble understanding the whole building process, there is an exelent website that i learned much from. I cannot think of the address offhand, but do a google for Herne's Smaug Building Guide. Its the most comprehensive builders guide that i know of.

Hope this has been some help.

Peace.
Australia Forum Administrator #8
Quote:

What is it with fishing, i have been asked to add fishing into my mud by another imm, read about it in a thread oon mudconnect,, was asked to code it for another mud and now we have it again.


Some MMORPGs have fishing (eg. World Of Warcraft), maybe the idea is spilling across to text MUDs.

It is a way of gathering food (and occasionally treasure, like a message in a bottle).
USA #9
Final Fantasy XI has fishing as well. A fairly good way to make some money, if I remember right. Lots of gear and stuff for it (some tackle that would allow you to catch 4-5 fish at once or something).
#10
It adds another thing for players to do besides killing mobs, and is, as Nick said, a source of food. Both the Muds I've played on had fishing, and that was long before the high-falootin' MMORPG craze. =)
#11
I thought I might mention I've never added a new command before. How would one learn how to add a new command such as fish/bake/sew/etc?

And I'm not sure I understand how to add fishing even after all of this. Could somebody give me an example?

Thanks and Godbless,
Longbow
Australia #12
To add a new command (SKILL??) you would follow the following, not exactly in that order, but this pretty much covers it. I will assume that its a skill (fishing) as that has a few more parts to do with GSN's that a command doesnt.

1. Write the code for fishing skill, Will leave this upto you for now, if you cannot get it to work, post what you have and i will help you from there.

2. Add entries in tables.c there are 2 massive tables, where everything is ment to be in alphabetical order. You need to add entries that are the same as below, where do_fish replace do_fixed.

if ( !str_cmp( name, "do_fixed" ))
        return do_fixed;
AND..... further down
if ( skill == do_fixed )
    return "do_fixed";


IN mud.h you have this to add.

DECLARE_DO_FUN( do_fixed	);
and for the gsn(global skill number)
extern	sh_int	gsn_fixed


Next part goes in db.c

sh_int			gsn_fixed;


Lastly we know that our coding skills are the best, and it all compiles cleanly, the mud starts up and there is no crash(Tm), we sset the command in if we are suckers for punishment, or we open skills.dat and add in somthing that looks like this,

#SKILL
Name         fish~
Type         Skill
Info         0
Flags        0
Minpos       110
Slot         550
Rounds       8
Code         do_fish
Dammsg       ~
Misschar     You are a tops fisher person.~
Minlevel     1
End

I think that just about covers it all, hope that helps some.
Amended on Sun 10 Apr 2005 06:03 AM by Robert Powell
#13
Ok, I don't understand the commands for adding the code for a new skill. I'm quite willing to try it myself but I don't know how to check if I'm in a room where you can fish or how to check the bait on my pole or your skill or anything. Could somebody give me a list of commands for writing code?

Also, does anyone know how to change the desc color in room descs? And what kind of food CAN you cook, it says you can only cook certain types of food.

Thanks for your patience, I really wish I knew some coding skills but I'm picking up a bit.



Godbless,
Longbow
Amended on Sun 10 Apr 2005 07:38 PM by Longbow
#14
Ok, I went and examined my do_skin bit, and I found that there wasn't a skill even using it, so no wonder it never worked. So I made a new skill(following the steps of Kevin London's tutorial, http://www.cs.utk.edu/~london/smaug/SMAUGDOC.html#spells)
I assigned the do_skin command to the skill, but it still says the same thing: "huh?"
HUH? WHY DOES IT SAY HUH? I killed a deer(npc) and typed skin corpse, and it says "huh?".

Here's my do_skin code:

void do_skin( CHAR_DATA *ch, char *argument)
{
OBJ_DATA *korps;
OBJ_DATA *corpse;
OBJ_DATA *obj;
OBJ_DATA *skin;
bool found;
char *name;
char buf[MAX_STRING_LENGTH];
found = FALSE;

if ( !IS_PKILL(ch) && !IS_IMMORTAL(ch) )
{
send_to_char( "Leave the hideous defilings to the killers!\n", ch );
return;
}
if ( argument[0] == '\0' )
{
send_to_char( "Whose corpse do you wish to skin?\n\r", ch );
return;
}
if ( (corpse=get_obj_here(ch, argument)) == NULL )
{
send_to_char( "You cannot find that here.\n\r", ch );
return;
}
if ( (obj=get_eq_char(ch, WEAR_WIELD)) == NULL )
{
send_to_char( "You have no weapon with which to perform this deed.\n\r", ch );
return;
}
if ( corpse->item_type != ITEM_CORPSE_NPC )
{
send_to_char( "You can only skin the bodies of player characters.\n\r", ch);
return;
}
if ( obj->value[3] != 1
&& obj->value[3] != 2
&& obj->value[3] != 3
&& obj->value[3] != 11 )
{
send_to_char( "There is nothing you can do with this corpse.\n\r", ch );
return;
}
if ( get_obj_index( OBJ_VNUM_SKIN ) == NULL )
{
bug( "Vnum 23 (OBJ_VNUM_SKIN) not found for do_skin!", 0);
return;
}
korps = create_object( get_obj_index(OBJ_VNUM_CORPSE_PC), 0 );
skin = create_object( get_obj_index(OBJ_VNUM_SKIN), 0 );
name = IS_NPC(ch) ? korps->short_descr : corpse->short_descr;
sprintf( buf, skin->short_descr, name );
STRFREE( skin->short_descr );
skin->short_descr = STRALLOC( buf );
sprintf( buf, skin->description, name );
STRFREE( skin->description );
skin->description = STRALLOC( buf );
act( AT_BLOOD, "$n strips the skin from $p.", ch, corpse, NULL, TO_ROOM);
act( AT_BLOOD, "You strip the skin from $p.", ch, corpse, NULL, TO_CHAR);
/* act( AT_MAGIC, "\nThe skinless corpse is dragged through the ground by a strange force...", ch, corpse, NULL, TO_CHAR);
act( AT_MAGIC, "\nThe skinless corpse is dragged through the ground by a strange force...", ch, corpse, NULL, TO_ROOM);
extract_obj( corpse ); */
obj_to_char( skin, ch );
return;
}


Thanks and Godbless,
Longbow
USA #15
Type: "cedit skin"
What does it display?
Australia #16
Quote:

Ok, I don't understand the commands for adding the code for a new skill. I'm quite willing to try it myself but I don't know how to check if I'm in a room where you can fish or how to check the bait on my pole or your skill or anything. Could somebody give me a list of commands for writing code?


Whenever i face these problems, i look to other sections of code that might hopefully do simular things to what i want to acheive.

1. Am i in the right type of room to fish.

What i would do is grep for a sector type and hope that something looks to do what i need. grep SECT_ *.c, what i found thats usefull is this, in magic.c in the spell plant pass.

if ( ch->in_room->sector_type == SECT_FOREST )
{
}
else
{
}

So if a Chariter is in a room with the sector type equalling forest, it would then execute the next line/few lines of code contained in the {}, else execute the code in this section {}

2. Does charicter have bait or a pole.

A fishing pole would be held, right? So we can then check to see what the player has in the WEAR_HOLD location. Lots of other things need to be held to use, so grep WEAR_HOLD *.c and there i found this example in do_scribe, to scribe you need to be holding a blanc scroll.

if ( ( scroll = get_eq_char( ch, WEAR_HOLD ) ) == NULL )
{
}

I this get_eq_char checks to see whats in WEAR_HOLD and if there is nothing (NULL) then it executes whats in the {}, if there is something in WEAR_HOLD, then scroll gets given all the data for that object(dont know if i said that right) so we can then check values of scroll to see if its that right type to do what we want.


if ( scroll->item_type == ITEM_SCROLL )


A check like this would be used to see of the oject is the right item_type.

I have assumed that you would be creating a new item type.

There is some parts to get you thinking, you will also need to work out how to remove and object from a player, to take away a lost or stolen bait, load an object into a room to give the player a fish if one is caught.

Good luck, if your still stuck, post what you have written and we can help you out further, the most important part here is having a go at it, dont worry if it doesnt work right or even compile first time, its all a part of the learning.

The good thing here is once you have the first one done, you will have a frame work to continue on to make baking and the other sumular skills with.

Peace.
Amended on Mon 11 Apr 2005 06:08 AM by Robert Powell
#17
Alright, I figgered out what my skin problem was. I had to practice the skill. :D Yes, go ahead and laugh...

Whenever I kill an animal it says:

Log: [*****] BUG: death_cry: invalid vnum. As a result I don't get a deathcry from anything. What's up with that?

Edit: ugh, now it's gone away. But I can skin the same corpse as many times as I want! I want it to die when it has been skinned once! Grrr...

Also, the whole point of the skin command for me was to make it possible to sell animal skins. Will it automatically tell the difference between the skins? Somehow I doubt that, so how do I define what kind of skin it should be so I can sell it?

Thanks for that last post Robert Powell, I'll take a try at it and see what I can come up with.


Godbless yall!

Longbow
Amended on Wed 13 Apr 2005 11:13 PM by Longbow
Australia #18
Death cry, i had a look at it, its in fight.c, here is the section of code that issues the bug.

if(!get_obj_index(vnum))
	{
		bug("death_cry: invalid vnum", 0);
		return;
	}


The part get_obj_index looks to see if the variable vnum is a valid one, if it isnt valid then you get that error. So looking deeper into the deadth_cry function you need to find out where vnum is being givin its value to see what the heck it does.

if(HAS_BODYPART(ch, cindex))
    		{
    			msg = part_messages[shift];
    			vnum = part_vnums[shift];
    			break;
    		}

Vnum equals parts_vnums which atleast means something, its the vnum of a body part that is left over when you kill a mobile. So i would say in limbo.are your missing a bodypart, as for what one i dont know. LOL
Peace.
Amended on Wed 13 Apr 2005 11:56 PM by Robert Powell
#19
Ok, I've started working on my new code file. Would somebody explain to me the &, |, and -> commands?

Australia #20
Now i think i need some of this explained to me also, but i will have a crack, & has a number of uses, the most used one that i can think of is in this situation

if ( this && that ) which should mean if this and that is true.

The pipe | if ( this || that ) is if this or that is true.

-> now i dont realy know how to explain this, but has to do with referencing parts of structures(with pointers??, im not realy up on pointer theory.

CHAR_DATA *ch; declares a pointer ch that points to the CHAR_DATA structure in mud.h, so you can then reference part of the structure, ch->name, would give you the name element from the structure.

Im sure someone else could explain that way better than i have.
#21
Heres a link that should prove useful later on.
http://immu.arthmoor.com/functions.htm
#22
Ok, I've got a bit going now. Now how does one add a new obj_type? I want to add several new ones.

Also, I'm trying to change the various combat messages, such as "MOB scratches you" but I can't seem to find the right file to edit. Which would it be please?


Godbless,
Longbow

Amended on Thu 14 Apr 2005 11:38 PM by Longbow
Australia #23
Grep for stuff you know, ITEM_SHOVEL and shovel, scratches you.

Make grep your friend and you will never be lost, well not very lost anyway, heh.

The reason for ITEM_SHOVEL and shovel, (it could be any item type you can think of) is because in some of the lists you need to add to it is ITEM_ and in others its just the name. Take a look you will see, after adding it in all the places you can find, if something doesnt work then post again, so you can be shown what you missed.

Peace.
#24
Ok, I put in a new skill that I got from some snippet place for "charge", and I followed all the steps exactly, but when I try to compile it gives me about a bazillion errors in mud.h saying stuff has been called before or something or other. It's about every line in mud.h I think that calls an error. What's up with that and how do I fix it?

Also, what do you do to an object to make it cookable?

And more critically, how do you set a player's Pkill flag on and off? I want to allow folks to kill each other right off the bat, none of this level 5 baloney. :)

Thanks and Godbless,
Longbow
Amended on Sat 16 Apr 2005 08:00 PM by Longbow
Australia #25
Can you post a few lines of the errors your getting, that will help in working out whats going on.

For the pkill stuff, being pk PK is just means you have the PCFLAG_DEADLY flag set on them, if you want that set on everyone, the best place to set it would be in comm.c in the nanny function, just look for where the auto's(auto exits i think in stock) are set and put it there.

For cooking, look in skills.c in the function do_cook.
#26
K, I'll post some lines of that later, I don't have time now.

More critical at the moment is the fact that shopkeepers won't buy anything. I followed the guide on Herne's Smaug Page but we still can't get the shops to say anything other then, "Looks uninterested in the item". What could be wrong? We set the shop buy1, 2 and 3 values, and it is open.


Thanks,
Longbow
Australia #27
Does the object have any value, a cost, if the object is worth 0 then a shopkeep will not be interested in it.

if ( ( cost = get_cost( ch, keeper, obj, FALSE ) ) <= 0 )
    {
	act( AT_ACTION, "$n looks uninterested in $p.", keeper, obj, ch, TO_VICT );
	return;
    }

Like i have said a few times befor, most times you can work out whats going on, by grepping your source for either the error, or responce your being given. The code above is in shop.c.
#28
Ok, I'm not sure how to call a dice sequence to check for success. This would also apply to my fishing code, but at the moment it has to do with chopping wood. My current code is as follows:

void do_chop (CHAR_DATA *ch, char *argument)
{
if (ch->in_room->sector_type == SECT_FOREST)
{
if ( ( shovel = get_eq_char(ch, WEAR_HOLD) ) == NULL)
{
send_to_char( "You don't have an axe! \n\r", ch );
}
if (shovel->item_type ==ITEM_SHOVEL)
{
act(AT_ACTION, "$n chops at the trees with their axe.", NULL, NULL, TO_ROOM);

}
}
}

I'd appreciate help with the dice, and any comments on the code would be nice. Thanks for all the help! I feel I might actually be learning something from all this. :)

Godbless,
Longbow
#29
Howdy folks, I'm back. Was on a trip for the last 10 days. Anybody have a comment on my code?
USA #30
Make sure you use the code tags so it's easier to read. You need a return in parts where you want the code to stop, say after the "You do not have an axe".

The random number check is used much through the code. It's called rand_num or something of the sort.
#31
Ok, what do you mean by code tags? And what does the rand_num have to do with it? I'm still pretty new to coding, though I've learned a lot.



Thanks and Godbless,
Longbow
USA #32
Code tags, on the forums: [ code ] (no spaces)
See: http://www.gammon.com.au/forum/bbforumcode.php

Well you said dice sequence. What do you mean by that?
Amended on Mon 02 May 2005 06:00 PM by Zeno
#33
Ahhhh, now I understand. I want a dice sequence such as if it equals 1 something happens, and 2 then something else happens(or the same, it could be a range), etc.


Thanks
USA #34
How do you want the dice to be based? Random?
#35
Yes, random please. I intend to use it to determine if a skill is successful by if the dice is such and such then such and such happens.
Australia #36
Here are a few bits of information you might need, number_range is what you want to use to determine a number value between 2 numbers. learn_from_failure and learn_from_sucess are 2 other functions you might like to use. Grep them out to see how to use them, Your on the right track so far.
USA #37
Ah yes, that's what its called. So you can do something like this. Declare a variable (lets call it rand). Then do something like this:
rand = number_range( 1, 3 )

Then do a case:
switch(rand)
case 1:
  do_stuff_here
  break;
case 2:
  do_more_here
  break;

And so on.
Amended on Tue 03 May 2005 12:44 AM by Zeno
USA #38
Ahh my favorite Haha.. I am very ... protestant... against certainty in a mud world.. I've got number_range cases everywhere.


And yes.. that's perfect.. but you might want to add a default: case there just incase something very weird happens that causes "rand" to become corrupted/changed
A default in a switch will be used any time nothing else matches.

default:
//something generic happens
break;
#39
Ok, unrelated problem but still critical enough for me to post it here:

I noticed Smaug 1.4a has the trip code in skills.c but I have been unable to add it. I tried and I keep getting these errors on make:

skills.c:3063: error: conflicting types for 'do_trip'
mud.h:4088: error: previous declaration of 'do_trip'

I changed the variable from void trip to void do_trip when I set it in mud.h and db.c and tables.c. What would cause this problem?


Thanks and Godbless,
Longbow
USA #40
Well the trip function is for mobs to use. What you want to do is create a new function, do_trip for the trip skill, that has checks etc and calls the trip function.
#41
So the only thing I need to do is add a new line in skills.c called void do_trip and paste the code for trip under it?

Thanks and Godbless,
Longbow
USA #42
No, don't copy it. Just add a few checks (with skill percent etc, like the other skills) and then call the function.
#43
Ok, suddenly I cannot see action descs and the like(ie, if something happens in the room a blank black line appears) and it is messing up my MUD. I first noticed it after I put in the bank code located at AFKmud's homepage(www.afkmud.com) and it is driving me up the wall. What might cause this? I'd rather not go back and delete the bank code(took a lot of time to put in) but rather I'd like to just fix the problem. Any ideas?

Thanks and Godbless,
Longbow
Australia #44
Sounds to me liek the mobile has the secritive flag set on it, i remember running about for hours trying to workout why then hell my shops wouldnt work, and it ws because of the secritive flag being set on a couple in the area i was working in.
#45
Ok, I got that fixed. Thanks. Now another question. I'm trying to extend the time it takes to get hungry, as it is really getting on my nerves with the continuous feeding process. However I cannot seem to find out which variable to change. I grepped hunger_mod but it doesn't seem to be the right one. Which variable would it be?

More critically, I keep getting a segmentation fault(core dumped) message that crashes the mud. It always seems to come after wildlands.are is reset but it resets that area at other times without problem. Why is this?


Thanks and Godbless,
Longbow
Amended on Thu 12 May 2005 08:50 PM by Longbow
Australia #46
It all happens in a function called gain_condition, as for a suitable way to modify it im at a loss without reading throught it and all the places it is called.
#47
Ok thanks. Now about the segmentation fault(core dumped) error. I've narrowed it down to an area file, but what in it would cause it?


Thanks

Godbless,
Longbow
USA #48
Have you tried gdb? It helps a lot.
#49
I'm sorry, I don't know what that is.


Longbow
USA #50
Right at the top of the Smaug coding page there's a guide.

http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=3653
Australia #51
Like grep to find things you need to make GDB your friend, gdb will help you in most cases pinpoint where a problem is occuring.

Nicks tutorial is fantastic but when i first read it i was overwelmed by the amount of detail he gave and was in some ways lost in all the details.

There are 2 main ways you can use it, by having it analize a core file, or by running the program within gdb while debuging, this is my preference while working on my local machine because for some unknown reason i donot make core files localy.

cd into your area directory,
run gdb
type file ../src/smaug (or the path to your executable)
type run

You now have smaug running in gdb, login to the mud and cause it to crash.

Go back into gdb,

Type bt (backtrace will show you the last bunch of functions called befor the crash)

frame <number> will take you to function you think caused the crash.

then you can type LIST to see the section of code.

Print <variable name> will show you what the variable contains.


Hope this helps you some.

Peace.

#52
Ok thanks guys. It appears to be fixed. Now I went to put in the slice skill(it came with Smaug) and everytime I try to slice something it says:
"Can not find mob for value[2] of corpse, do_slice".
Now how would one fix that? I know that it needs to be set to a value of two, but how do I do that? Newbish question I know, but I'm getting there. :)

Thanks for all your help and Godbless,
Longbow

USA #53
In the code? Then something like this:
obj->value[2] = whatever;

Or use oset to set it in the mud. I assume it is using v2 to lookup a mob vnum.
#54
I think you're right, but I don't understand as to whether I need to oset just the corpse or every mob or what? What needs its value2 set?

Longbow
Australia #55
From my quick read of do_slice, v2 is used to determine a food value for the mob corpse in question, beacuse if slice is successfull you end up with vnum 24 and i think thats a chunk of meat.

Now if you look through the code you will see that V2 never gets used at all within the function, but V3 does.

ALso if you kill something and ostat the corpse object you will find that V2 is set on the object but not in the index object and its checking the index value.

Index Values : 0 0 0 1 0 0.
Object Values: 0 0 6 1 0 0.

I would just remove the whole V2 check as its there for no reason that i can tell, and posibly change the values in v3 as 75 seems a little high when i got a value of 1 for the biggest mob in my game.

#56
I've tried deleting it but when I make it says it may be called anyway or something like that. Running the game and trying to slice the corpse results in a crash by a segmentation fault. What would one to do delete that function, or what could I change the command to so that it does something useless but thinks it's doing something?

Thanks and Godbless,
Longbow
#57
Sorry guys, I'm kinda boggled. What should I do since I can't delete the line of code? It's still calling from somewhere so it crashes when I run it. What could I set that command to so it will never be called?

Thanks, Godbless,
Longbow
Australia #58
There are some other changes that need to be made in order to make it work right. It uses pMobindex->blaa its trying to set values on a mobile when it should be setting them on an object, corpse->blaa, the other change is slice->value3 = this makes the food item poison so delete it and set values for v0 (food value) and v1 (condition).

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;
  }


  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] = 25;
slice->value[0] = 13;
  obj_to_char(slice, ch);
  
  learn_from_success(ch, gsn_slice);
  return;
}


There is one other thing you might want to do and thats remove the corpse after the meat has been sliced, otherwise you could slice meat for all eternity.
Amended on Tue 17 May 2005 12:51 AM by Robert Powell
USA #59
I'm confused about this part:


  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] = 25;
slice->value[0] = 13;
  obj_to_char(slice, ch);



Why is slice->value[0] being set to 25 and then to 13? Why not just do one or the other? Is there a typo here?
Amended on Wed 18 May 2005 01:28 AM by Gatewaysysop2
Australia #60
Sorry its a typo, the second one should be slice->value[1] = 13;

v1 being for condition. ))
Amended on Wed 18 May 2005 09:32 AM by Robert Powell
#61
Ok, now I want to make it so when you skin certain animals you get a differant pelt object(this is so you can sell the pelts and get differant values for them) but I need to know how to call the various pelts. Could I set a value on each one and if that value is such and such then such and such an object is loaded?
Also, could I make it so the various objects can be sliced a certain amount of times off the corpse(1 meat object for rabbit, 2 for deer, etc.)?

Thanks and Godbless,
Longbow
Australia #62
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
#63
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
Australia #64
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.
#65
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
Australia #66
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;
   }


#67
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
#68
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
USA #69
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.

#70
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
#71
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
#72
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
Australia #73
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.
Amended on Mon 13 Jun 2005 12:04 PM by Robert Powell
#74
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;
	}
  }	

USA #75
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.
Amended on Sun 26 Jun 2005 09:01 AM by Meerclar
USA #76
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.