14 Oct, 2013, Grieffels wrote in the 1st comment:
Votes: 0
I'm curious as to why this doesn't work. I have it seeing if the character is carrying an item that is COPPERORE, if they are it extracts it. However, I do see that im not defining obj in extract obj to be ITEM_COPPERORE. How would I go about this? I know I can do obj = whatever, but im lost on how to really set that up. I tried using get_obj_index(COPPER_ORE), which I have COPPER_ORE defined for vnum 1000, and that doesnt work correctly.

for ( obj = ch->carrying; obj != NULL; obj = obj->next_content )
{
if ( obj->item_type == ITEM_COPPERORE )
obj_from_char(obj);
extract_obj(obj);
break;
}
14 Oct, 2013, Zeno wrote in the 2nd comment:
Votes: 0
I uh hope you're not running that code. You're missing some brackets and that'll extract every single item the player is carrying. Also your break confuses me.
15 Oct, 2013, Grieffels wrote in the 3rd comment:
Votes: 0
Sorry I am not on your level of programming. I am in the learning phase of this all. Also, it doesn't extract every object the player has, it doesn't extract any right now. The MUD also just has me working on it with no players. I'm just asking WHY it isn't working.
15 Oct, 2013, Grieffels wrote in the 4th comment:
Votes: 0
It's basically like this piece of code:
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if ( obj->item_type == ITEM_COPPERVEIN )
{
obj_from_room(obj);
}
break;
}


if ( obj == NULL )
{
send_to_char( "There is no exposed copper vein to mine.",ch );
return;
}
If there is one there, I need it to remove it, if it's not, it'll print out this. It works only if that is the only thing in the room. If there is more, it doesn't work..I know that's because of the == ITEM_COPPERVEIN. I'm just a little stumped on this so if anyone could lend a hand.
15 Oct, 2013, Zeno wrote in the 5th comment:
Votes: 0
Are you expecting to extract all Copper Ore, or just the first one?
15 Oct, 2013, Sharmair wrote in the 6th comment:
Votes: 0
Grieffels said:
… Also, it doesn't extract every object the player has, it doesn't extract any right now. …

Are you sure? The code you have (edited for indentation):
for(obj = ch->carrying; obj != NULL; obj = obj->next_content){
if(obj->item_type == ITEM_COPPERORE)
obj_from_char(obj);
extract_obj(obj);
break;
}

Should (assuming things still work as in stock ROM with base utility functions) extract the first object the character has then stop. if that
first object is of type ITEM_COPPERORE it will be explicitly removed from the character, if not the extract_obj() will detect it is still on a
character and call obj_from_char(). In either case it will be extracted and then hit the break and end the loop. If this is not happening, then
this code is not being run. You have not really described where this code is, or the conditions it gets here.
Anyway, you may have meant:
for(obj = ch->carrying; obj != NULL; obj = obj->next_content){
if(obj->item_type == ITEM_COPPERORE){
obj_from_char(obj);
extract_obj(obj);
break;
}
}

In this case only the first if any ITEM_COPPERORE will be removed. I should also point out, in this case you are ending the
loop after finding the first ore, if you wanted to continue the loop, you would have to save the next_content pointer of the
object as it has been cleared in the obj_from_char() call.
15 Oct, 2013, Sharmair wrote in the 7th comment:
Votes: 0
Grieffels said:
It's basically like this piece of code:
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if ( obj->item_type == ITEM_COPPERVEIN )
{
obj_from_room(obj);
}
break;
}


if ( obj == NULL )
{
send_to_char( "There is no exposed copper vein to mine.",ch );
return;
}
If there is one there, I need it to remove it, if it's not, it'll print out this. It works only if that is the only thing in the room. If there is more, it doesn't work..I know that's because of the == ITEM_COPPERVEIN. I'm just a little stumped on this so if anyone could lend a hand.

This code also has a loop that is really not a loop as it will stop after the first object (it actually should work if there are more then one thing
in the room as long as the first is the copper). Like the last, you probably want the break in the if block. Also, at the end of this code, obj is
still in the global object list but not anywhere, make sure you extract it or put it someplace before you end with it. You have not really described
what you want to do here, so I am not sure what you intend to do with it, but do something.
15 Oct, 2013, Grieffels wrote in the 8th comment:
Votes: 0
Thanks for the assistance. Basically, I want it to do the following and I will list examples.
mine copper
If there is a copper vein in the room, it will extract it and begin to mine. Which the rest
works correctly within the code, just this one part isnt working.Right now, it will only
extract if it's the first item in the room.

smelt copper
Checks if you have the obj, takes it away from you and begins to smelt. This piece won't even
extract if you only have the bar, it does work past this piece of code though.

So for what i'm wanting, it should check all the objects but only remove one at a time, if the command
is used multiple times, it will then check for another, again, another. But with using smelt copper
or mine copper, it will just do the checks for it of the entire room, remove ONE and stop.
Smelt will remove ONE from you also, but neither of these should have to be the only or first
object in the room or are carrying. If you need anymore information just let me know.
Here are the pieces of code.
Mining:
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if ( obj->item_type == ITEM_COPPERVEIN )
{
obj_from_room(obj);
}
break;
}


if ( obj == NULL )
{
send_to_char( "There is no exposed copper vein to mine.",ch );
return;
}

Smelting:
for(obj = ch->carrying; obj != NULL; obj = obj->next_content)
{
if(obj->item_type == ITEM_COPPERORE)
{
obj_from_char(obj);
extract_obj(obj);
break;
}
}


Again, thanks everyone for assisting me on this.

ADDED LATER: Well, it seems these work now. It was just that last } that I didn't have correctly, it works fine.
smelting:
for(obj = ch->carrying; obj != NULL; obj = obj->next_content){
if(obj->item_type == ITEM_COPPERORE)
{
obj_from_char(obj);
extract_obj(obj);
break;
}
}
mining:
for ( obj = ch->in_room->contents; obj; obj = obj->next_content )
{
if(obj->item_type == ITEM_COPPERVEIN)
{
extract_obj(obj);
break;
}
}

Thanks everyone for the help.
0.0/8