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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  New item types

New item types

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


Pages: 1 2  3  

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Fri 17 Aug 2007 02:56 AM (UTC)

Amended on Fri 17 Aug 2007 02:59 AM (UTC) by Orik

Message
Ok, I'm putting socketed items into my mud. I've got everything done except for the socket function. In the function I'm checking to see if the item is either a blue gem, a red gem or a yellow gem. For some reason that I cannot explain it is messing up. Here's the code:



/*These if checks are to see if the item_type is working*/

  if (first_ob->item_type == ITEM_GEM_RED)
    send_to_char( "This item is a red gem!\n\r", ch );

  if (first_ob->item_type != ITEM_GEM_RED)
    send_to_char( "This item is not a red gem!\n\r", ch );

  if (second_ob->item_type == ITEM_WEAPON)
    send_to_char( "This item is a sword!\n\r", ch );

/* This is where it stops. My != if check isn't working correctly. */

  if (   first_ob->item_type != ITEM_GEM_BLUE
	  || first_ob->item_type != ITEM_GEM_RED
	  || first_ob->item_type != ITEM_GEM_YELLOW )
  {  
    send_to_char( "This item must be a gem!\n\r", ch );
    return;
  }


Here's my test. I had a gem and a sword. The gem is item_gem_red.

<1564hp 1240mv> 
< 2>socket gem sword
This item is a red gem!
This item is a sword!
This item must be a gem!

I then changed the gem to a blue gem for the second if check to see if it's working.

<1564hp 1240mv> 
< 2>oset gem type gem-blue
Build: Orik: oset gem type gem-blue

<1564hp 1240mv> 
< 2>socket gem sword
This item is not a red gem!
This item is a sword!
This item must be a gem!


Can anyone see what's going on? I've stared at this things for quite awhile and can't figure it out. Either my != is wrong or my || is wrong somehow? I'm not sure.
[Go to top] top

Posted by Gohan_TheDragonball   USA  (183 posts)  [Biography] bio
Date Reply #1 on Fri 17 Aug 2007 03:24 AM (UTC)
Message
well i would assume your last ifcheck is wrong, just to make sure, you do understand what an OR statement does in an ifcheck right? i think you meant this:


  if (   first_ob->item_type != ITEM_GEM_BLUE
	  && first_ob->item_type != ITEM_GEM_RED
	  && first_ob->item_type != ITEM_GEM_YELLOW )
  {  
    send_to_char( "This item must be a gem!\n\r", ch );
    return;
  }
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #2 on Fri 17 Aug 2007 03:29 AM (UTC)

Amended on Fri 17 Aug 2007 03:39 AM (UTC) by Orik

Message
I'm an idiot..lol. Thanks Gohan, I completely missed that one.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #3 on Fri 17 Aug 2007 05:22 AM (UTC)

Amended on Fri 17 Aug 2007 05:23 AM (UTC) by Orik

Message
Ok, now I've run into another problem. I've got my socket function working to run to the end and now I'm actually writing how to add the affects from the gem to the actual item. Here's what I have which I know isn't correct, but I needed a starting point.


/*Taken from ostat code*/
for( paf = first_ob->pIndexData->first_affect; paf; paf = paf->next )
  ch_printf_color( ch, "Adding %s by %d\n\r", affect_loc_name( paf->location ), paf->modifier );

/* taken from enchant_weapon */
  seperate_obj( second_ob );
  CREATE( paf, AFFECT_DATA, 1 );
  paf->type = -1;
  paf->duration = -1;

/* This needs to be paf->location from first_ob */
  paf->location = APPLY_HITROLL; 

/* This needs to be paf->modifier from first_ob */
  paf->modifier = level / 15; 

  xCLEAR_BITS( paf->bitvector );
  LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );

  extract_obj( first_obj );


So if a gem has 2 hitroll, when socketed, that will add 2 hitroll to the weapon/armor permanently.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #4 on Fri 17 Aug 2007 05:41 AM (UTC)

Amended on Fri 17 Aug 2007 05:42 AM (UTC) by Orik

Message
Came up with this, although still, I know it won't compile, but I'm getting closer I think:



/*Taken from ostat code*/
for( paf = first_ob->pIndexData->first_affect; paf; paf = paf->next )
{
  ch_printf_color( ch, "Adding %s by %d\n\r", affect_loc_name( paf->location ), paf->modifier );

/*I don't know how to define att in the function to find the string from affect_loc_name. I made mod an int. */
   att = affect_loc_name( paf->location );
   mod = paf->modifier;

/* taken from enchant_weapon */
  seperate_obj( second_ob );
  CREATE( paf, AFFECT_DATA, 1 );
  paf->type = -1;
  paf->duration = -1;

/* This needs to be paf->location from first_ob */
  paf->location = att; 

/* This needs to be paf->modifier from first_ob */
  paf->modifier = mod; 

  xCLEAR_BITS( paf->bitvector );
  LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}
  extract_obj( first_obj );

[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #5 on Fri 17 Aug 2007 08:01 AM (UTC)
Message
If you just want the string, you can use char* or const char*. But is a string really what you want? It looks like you're assigning it into the new effect's location, so you might want to keep it as a number.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

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

Posted by Gohan_TheDragonball   USA  (183 posts)  [Biography] bio
Date Reply #6 on Fri 17 Aug 2007 08:24 AM (UTC)

Amended on Fri 17 Aug 2007 08:25 AM (UTC) by Gohan_TheDragonball

Message
got a couple questions:

why would you have this in a for loop?
seperate_obj( second_ob );

exactly why are you doing this when paf is already valid, you really dont need to recreate the affect anyways?
CREATE( paf, AFFECT_DATA, 1 );

also you might wanna pull the affects from the obj and not the objects index. so:
for( paf = first_ob->pIndexData->first_affect; paf; paf = paf->next )
becomes
for( paf = first_ob->first_affect; paf; paf = paf->next )

if you are copying the affect into the new object, exactly why are you removing everything that DEFINES what the affect is? i understood changing the duration to -1 so its permanent, but this i really dont.
paf->type = -1;
xCLEAR_BITS( paf->bitvector );

also like i stated why are you recreating the affect, just pull it from the object since you are gonna extract it anyways and put it on the second obj.

seperate_obj( second_ob );
for( paf = first_ob->first_affect; paf; paf = paf->next )
{
  ch_printf_color( ch, "Adding %s by %d\n\r", affect_loc_name( paf->location ), paf->modifier );
  UNLINK( paf, first_ob->first_affect, first_ob->last_affect, next, prev );
  paf->duration = -1;
  LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}
extract_obj( first_obj );
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #7 on Fri 17 Aug 2007 08:54 PM (UTC)
Message
Hey Gohan, That's why I was asking on here :) I didn't really know how to do what I was wanting. Your solution worked just fine. Thanks heaps.
[Go to top] top

Posted by Gohan_TheDragonball   USA  (183 posts)  [Biography] bio
Date Reply #8 on Fri 17 Aug 2007 09:02 PM (UTC)
Message
glad it works, i just wanted to make sure i said why i was changing what i changed instead of just reposting code.
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #9 on Fri 17 Aug 2007 11:18 PM (UTC)
Message
Ok, round three :)

Now that I have my affect adding to the second object, I want to put the short description of the first object into the second object. So when I cast ID it'll say something like


object 'a sword' is a weapon, with wear location: take wield
blah blah blah
Total Sockets: Blue (0/0) Red (1/1)  Yellow (0/1)
/*Here's the part that I want*/
Socketed: (red gem) a fiery red gem


I have this part working in the identify spell and everywhere else. I need to figure out how to put the first_ob->short_descr into the second_ob. here's what I have:


snprintf(buf1, MAX_STRING_LENGTH, "%s", first_ob->short_descr);
if ( !second_ob->sdesc1 ) /* If no socket description */
  {
    STRFREE( second_ob->sdesc1 );
    second_ob->sdesc1 = STRALLOC( buf1 );
  }


So basically, I'm putting the first object short description into buf1 then putting it into second_ob->sdesc1. This compiles, but not working. Any thoughts?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Fri 17 Aug 2007 11:24 PM (UTC)
Message
First problem I see is that, if the description (second_ob->sdesc1) is NULL, then you are freeing it. Won't that crash?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #11 on Fri 17 Aug 2007 11:28 PM (UTC)

Amended on Sat 18 Aug 2007 12:12 AM (UTC) by Orik

Message
hmm...it didn't? So maybe that part isn't working? The if check.

**EDIT***
The problem was in the spell_identify. I was looking for obj-pIndexData->sdesc1 rather than obj->sdesc1.

It's working now. :)
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #12 on Sat 18 Aug 2007 02:18 PM (UTC)

Amended on Sat 18 Aug 2007 02:20 PM (UTC) by Orik

Message
Round 4: FIGHT!

heh.

Ok, so apparently this:

	separate_obj( second_ob );
	   for( paf = first_ob->pIndexData->first_affect; paf; paf = paf->next )
		{
		   ch_printf_color( ch, "&cAffects &w%s &cby &w%d.\r\n", affect_loc_name( paf->location ), paf->modifier );
		   UNLINK( paf, first_ob->pIndexData->first_affect, first_ob->pIndexData->last_affect, next, prev);
		   paf->duration = -1;
		   LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
			
		}
			snprintf(buf1, MAX_STRING_LENGTH, "%s", first_ob->short_descr);
			
			if( !second_ob->sdesc1 || second_ob->sdesc1[0] == '\0' )
			{
				STRFREE( second_ob->sdesc1 );
				second_ob->sdesc1 = STRALLOC( buf1 );
			}
			else if( !second_ob->sdesc2 || second_ob->sdesc2[0] == '\0' )
			{
				STRFREE( second_ob->sdesc2 );
				second_ob->sdesc2 = STRALLOC( buf1 );
			}
			else if( !second_ob->sdesc3 || second_ob->sdesc3[0] == '\0' )
			{
				STRFREE( second_ob->sdesc3 );
				second_ob->sdesc3 = STRALLOC( buf1 );
			}
			else if( !second_ob->sdesc4 || second_ob->sdesc4[0] == '\0' )
			{
				STRFREE( second_ob->sdesc4 );
				second_ob->sdesc4 = STRALLOC( buf1 );
			}
			else if( !second_ob->sdesc5 || second_ob->sdesc5[0] == '\0' )
			{
				STRFREE( second_ob->sdesc5 );
				second_ob->sdesc5 = STRALLOC( buf1 );
			}
			else if( !second_ob->sdesc6 || second_ob->sdesc6[0] == '\0' )
			{
				STRFREE( second_ob->sdesc6 );
				second_ob->sdesc6 = STRALLOC( buf1 );
			}

    extract_obj( first_ob );


causes the gems to mess up. Example:

I load my sword, load a red gem, a yellow gem a blue gem. Red gem is 1 dam, yellow gem is 1 dex, blue gem is 1 hit.

I socket the red gem, sword gets +1 dam
I socket yellow gem, sword gets +1 dex
I socket blue gem, sword gets +1 hit

Sword ends up with 3 extra affects like it should. I ID sword and it is affected dam by 1(extra), dex by 1(extra) hit by 1 (extra).

What the problem is my gems. Even though it is supposed to extract them once they are done(it does) the previous gem gets the effects from the next gem and the next gem. So I socketed my red gem first then the others, when I oinvoked the red gem again, it showed that it gave 1 dam, 1 dex, 1 hit, when it was supposed to only keep the 1 dam. So somehow, first_ob isn't getting rid of the the gems entirely and adding to them as well as the second_ob(my weapon). This in turns screws up the area file.

I'm not sure why it's not extracting the the obj correctly. Would there be a better way to do this? I'm sure there is and I'm probably doing it the hard way.
[Go to top] top

Posted by Isthiriel   (113 posts)  [Biography] bio
Date Reply #13 on Sat 18 Aug 2007 03:44 PM (UTC)

Amended on Sat 18 Aug 2007 08:03 PM (UTC) by Isthiriel

Message
for (paf = first_ob->pIndexData->first_affect; paf; paf = paf->next) {
  ch_printf_color( ch, "&cAffects &w%s &cby &w%d.\r\n", affect_loc_name( paf->location ), paf->modifier );
  UNLINK( paf, first_ob->pIndexData->first_affect, first_ob->pIndexData->last_affect, next, prev);
  paf->duration = -1;
  LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}

The first line assumes that paf is a member of the linked list proceeding from first_ob->pIndexData->first_affect.

The UNLINK statement invalidates that.

After the LINK statement at the end of the block, paf is a member of the list proceeding from second_ob->first_affect and the iteration step (paf = paf->next) sets paf to the next object in the second_ob->first_affect list.

To get around that you need to cache the value of paf->next:
AFFECT_DATA *paf_next; /* or whatever paf is declared as */
for (paf = first_ob->pIndexData->first_affect; paf; paf = paf_next) {
  paf_next = paf->next;
  ch_printf_color( ch, "&cAffects &w%s &cby &w%d.\r\n", affect_loc_name( paf->location ), paf->modifier );
  UNLINK( paf, first_ob->pIndexData->first_affect, first_ob->pIndexData->last_affect, next, prev);
  paf->duration = -1;
  LINK( paf, second_ob->first_affect, second_ob->last_affect, next, prev );
}



As a side note, (and it's been a while since I had to write portable C), can't the second section be rewritten as something like:
char **sdescs[6] = { &(second_ob->sdesc1), &(second_ob->sdesc2), &(second_ob->sdesc3), &(second_ob->sdesc4), &(second_ob->sdesc5), &(second_ob->sdesc6) };
short i = 0;
for (; i < 6; ++i) {
  if (*(sdescs[ i ]) == NULL || (*(sdescs[ i ]))[0] == '\0') {
    STRFREE(*(sdescs[ i ]));
    *(sdescs[ i ]) = STRALLOC( buf1 );
    break;
  }
}
[Go to top] top

Posted by Orik   USA  (182 posts)  [Biography] bio
Date Reply #14 on Sat 18 Aug 2007 04:09 PM (UTC)
Message
Thanks Isthiriel,

I think the UNLINK statement is now where I'm getting my problems from.

If I use it, it takes away the affect from the actual gem object as if it were prototyped and you rmaffect it.

If I comment it out, it adds the affects from the next gem's affect to the previous gem. So it does what I stated above and wrecks the area file.

I don't want to use

for( paf = first_ob->first_affect; paf; paf = paf->next )


because then it takes from the extra affect field and my items don't have extra affects. I want to take the perm affects and put them onto the item as extras(which it does), it's just that the gems are getting messed up in the process.

baffling..hehe.

[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.


71,387 views.

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

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at HostDash]