Welcome to the Builder Academy

Question MSDP Inventory

More
12 Dec 2017 05:33 #7234 by WhiskyTest
Replied by WhiskyTest on topic MSDP Inventory
Definitely not bumping this thread in case Ripley sees it and posts his code...
Nope.
Not me..

:o

Please Log in or Create an account to join the conversation.

More
12 Dec 2017 09:14 #7236 by Ornir
Replied by Ornir on topic MSDP Inventory
Hah! Sorry for the delay, I got wrapped up in GUI development.

So some explanation is needed - I want to be able to encode as much data in the MSDP as possible, therefore for the INVENTORY variable I am returning an MSDP_ARRAY of MSDP_TABLEs. That way, I can add more data as needed, for example a unique ID to make it easy to perform operations on single instances of an object from the GUI when you have multiple instances in your inv. Currently only NAME and LOCATION are implemented.

Note, the ONLY MSDP variable you need to set up in protocol.h is INVENTORY - The internal variables are not reportable so do not need to be defined. INVENTORY should be a STRING_READ_ONLY in protocol.h.

I have, in this function, included worn items in inventory, using the LOCATION table property to show where the item is equipped. If the item is not equipped, then the location is set to 'Inventory'.

Some of this code may need to be modified to fit your mud. You need to Flush the msdp buffer after calling this procedure if you want to send the data to the player immediately. Stripping the colors is important if you have embedded colors in your item short_description, as the colors will screw up the MSDP protocol and give really weird, hard to track errors.

Basically to use MSDP tables for this stuff, you need to remember the following:
  • MSDP_VAL: Tell the client that the stuff from now to the next MSDP_VAR or MSDP_VAL is associated with the previous MSDP_VAR. This is always the first character in the sprintf for an array because when you call MSDPSetArray it automatically adds the given variable name with an MSDP_VAR preceding it.
  • MSDP_TABLE_OPEN: This acts as the opening '{' of your table definition.
  • MSDP_VAR/VAL pairs inside the table: You can nest as much as you like. MSDP_VAL MSDP_TABLE_OPEN MSDP_VAR SHOPINV MSDP_VAL MSDP_TABLE_OPEN ... MSDP_TABLE_CLOSE MSDP_TABLE_CLOSE is totally valid and can be very useful for organizing your data! Clients might restrict nesting depth but I have never had a problem and the spec is clear that it is unlimited.

Enjoy and let me know if you find it useful or need help with something!
Code:
void update_msdp_inventory(struct char_data *ch) { char msdp_buffer[MAX_STRING_LENGTH]; obj_data *obj; int i = 0; /* Inventory */ msdp_buffer[0] = '\0'; if (ch && ch->desc) { /* --------- Comment out the following if you don't want to mix eq and worn ---------- */ for (i = 0; i < NUM_WEARS; i++) { if (GET_EQ(ch, i)) { if (CAN_SEE_OBJ(ch, GET_EQ(ch, i))) { char buf[4000]; // Buffer for building the inventory table for MSDP obj = GET_EQ(ch, i); sprintf(buf, "%c%c" "%c%s%c%s" "%c%s%c%s" "%c", (char)MSDP_VAL, (char)MSDP_TABLE_OPEN, (char)MSDP_VAR, "LOCATION", (char)MSDP_VAL, equipment_types[i], (char)MSDP_VAR, "NAME", (char)MSDP_VAL, obj->short_description, (char)MSDP_TABLE_CLOSE); strcat(msdp_buffer, buf); } } } /* ---------- End Worn Equipment ----------*/ for (obj = ch->carrying; obj; obj = obj->next_content) { if (CAN_SEE_OBJ(ch, obj)) { char buf[4000]; // Buffer for building the inventory table for MSDP sprintf(buf, "%c%c" "%c%s%c%s" "%c%s%c%s" "%c", (char)MSDP_VAL, (char)MSDP_TABLE_OPEN, (char)MSDP_VAR, "LOCATION", (char)MSDP_VAL, "Inventory", (char)MSDP_VAR, "NAME", (char)MSDP_VAL, obj->short_description, (char)MSDP_TABLE_CLOSE); strcat(msdp_buffer, buf); } } strip_colors(msdp_buffer); MSDPSetArray(ch->desc, eMSDP_INVENTORY, msdp_buffer); } }

Luminari - a Pathfinder/D&D inspired adventure!
www.luminarimud.com
luminarimud.com 4100
The following user(s) said Thank You: zusuk

Please Log in or Create an account to join the conversation.

More
12 Dec 2017 09:22 #7237 by zusuk
Replied by zusuk on topic MSDP Inventory
Wow Ripley! Looks awesome, thanks for the contribution! Can't wait to see how it looks in the GUI!

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

Please Log in or Create an account to join the conversation.

More
13 Dec 2017 21:46 #7243 by WhiskyTest
Replied by WhiskyTest on topic MSDP Inventory
Awesome Ripley thank you :)
Just trying it out now.
Had to remove strip_colours() as tbaMUD doesn't seem to have that any more.

Please Log in or Create an account to join the conversation.

More
03 Jan 2018 23:47 #7292 by Ornir
Replied by Ornir on topic MSDP Inventory
Ah, that must be Luminari specific then. If you have colors in item short descriptions MSDP will break without stripping them out.

Is this working out for you?

Luminari - a Pathfinder/D&D inspired adventure!
www.luminarimud.com
luminarimud.com 4100

Please Log in or Create an account to join the conversation.

More
03 Jan 2018 23:47 #7293 by Ornir
Replied by Ornir on topic MSDP Inventory
Ah, that must be Luminari specific then. If you have colors in item short descriptions MSDP will break without stripping them out.

Is this working out for you?

Luminari - a Pathfinder/D&D inspired adventure!
www.luminarimud.com
luminarimud.com 4100

Please Log in or Create an account to join the conversation.

Time to create page: 0.203 seconds