Welcome to the Builder Academy

Question Item Durability

More
16 May 2013 05:18 #2308 by Vatiken
Replied by Vatiken on topic Item Durability
Both those ideas are awful, being complete wastes of time and prone to errors. I know this for a fact because they were ideas I had also come up with and utilized a long long long time ago when I first started coding.

If you go into db.c and go into the parse_object() function you will see that the problem of adding to the world files has occured in the past and has been properly dealt with in the stock tba code.

ADDING NEW DATA
In the following snippet t[3] & t[4] were added after the fact for OBJ_LEVEL() and OBJ_TIMER(). It checks for 5 arguments but has conditions for if it only finds 3 or 4. If this occurs, it just sets them both to 0. Using this method you won't have any issues with old world files mixing with new ones, and most importantly, no manual editing.
Code:
if (!get_line(obj_f, line)) { log("SYSERR: Expecting third numeric line of %s, but file ended!", buf2); exit(1); } if ((retval = sscanf(line, "%d %d %d %d %d", t, t + 1, t + 2, t + 3, t + 4)) != 5) { if (retval == 3) { t[3] = 0; t[4] = 0; } else if (retval == 4) t[4] = 0; else { log("SYSERR: Format error in third numeric line (expecting 5 args, got %d), %s", retval, buf2); exit(1); } } GET_OBJ_WEIGHT(obj_proto + i) = t[0]; GET_OBJ_COST(obj_proto + i) = t[1]; GET_OBJ_RENT(obj_proto + i) = t[2]; GET_OBJ_LEVEL(obj_proto + i) = t[3]; GET_OBJ_TIMER(obj_proto + i) = t[4];

SAVING MODIFIED FILES
The following snippet shows how when converting a older file, the code automatically puts the newly converted object file into the MUD's save list so you can save all the files at once from within the game.
Code:
} else if (((retval == 4) || (retval == 3)) && (bitwarning == FALSE)) { if (retval == 3) t[3] = 0; else if (retval == 4) t[3] = asciiflag_conv_aff(f3); log("Converting object #%d to 128bits..", nr); GET_OBJ_EXTRA(obj_proto + i)[0] = asciiflag_conv(f1); ... GET_OBJ_PERM(obj_proto + i)[3] = 0; if(bitsavetodisk) { add_to_save_list(zone_table[real_zone_by_thing(nr)].number, 1); converting = TRUE; } log(" done."); } else if (retval == 13) {

tbaMUD developer/programmer

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

More
16 May 2013 06:26 #2309 by Papaya Pete
Replied by Papaya Pete on topic Item Durability
Hmmm I see what you mean, that looks like a very easy way to do some converting!

Well, I've been doing a little more testing... and I've run across another problem. So far, I've gotten those new values added in and saved. They seem to load properly and everything, and I've even got some code in to do damage to weapons as they're used in combat. However, if a character saves and quits with a broken weapon (0 condition) and logs back in... the weapon is once again back to it's original starting point when first loaded (in this case, 100 out of 100).

On another note... the game crashes when walking into another room at seemingly random times. Looking through the crash log, I can't seem to find any error messages... I'll keep hunting. I have the feeling this item condition thing is a bit more than I can handle!

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

More
16 May 2013 15:43 #2320 by Papaya Pete
Replied by Papaya Pete on topic Item Durability
Ah found out what the problem was.

The conditions of objects that were on the players were not being saved properly. Or, they were, but I didn't add in the code to consider durability. So made the necessary additions to objsave_save_obj_record function in objsave.c, and it looks like it's working the way it should be. Also, the crashes have stopped.

So I've gotten the wear and tear for weapons part down in the hit() function in fight.c. Hmmm. So the next step is randomly determining which location is struck, check to see if something is worn there, and then roll some dice to see if it's damage from the blow. The only thing that I don't know how to do is check the victim's location for gear...

Let's see if I can figure that out. Though pointers are always appreciated. :)

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

More
16 May 2013 16:00 #2321 by Vatiken
Replied by Vatiken on topic Item Durability
You most likely have a condition while loading objects that sets any object with 0 current durability back to the max. An easy way to help diagnose this would be to create an object with 0 current durability and manually load it into the game. If it stays at 0, then the issue is most likely in the parse_object() function.

tbaMUD developer/programmer
The following user(s) said Thank You: Papaya Pete

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

More
16 May 2013 16:14 #2322 by Papaya Pete
Replied by Papaya Pete on topic Item Durability
Yeah I wasn't even saving any of the condition info into the player's plrobj file, that was the source of the problem. Got it fixed now, and also took a look at what you posted earlier....

If you go into db.c and go into the parse_object() function you will see that the problem of adding to the world files has occured in the past and has been properly dealt with in the stock tba code.


Taking a look at it, I finally understood what was going on after getting a night of sleep. I stored the condition data on the second line instead of the third, so I made those same retval checks on the second line of data that were done on the third (taking into account there aren't the same number of values). Threw in the stock zones and everything, and it all loads perfectly fine! Thank you very much for pointing that out. :)

Now to figure out how to see what a victim is wearing.

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

More
16 May 2013 18:16 #2324 by Papaya Pete
Replied by Papaya Pete on topic Item Durability
Ok, I figured out how to do a hit-location check and see if the victim of the blow has armor on a specified location. If it does, then damage is applied to that item's durability. The only thing I have to add in is a check to see whether or not the item is unbreakable, in which case it won't deal any damage.

The next step is displaying the item's condition in the short desc, when you see it in a room, in your inventory, equipment, and so on. Example: a sword (excellent)

After that, it's setting up shops to be able to repair items with damaged conditions. That should be it.

That crash out of the blue still happens. I was in combat and the mud crashed in the middle of it, without any error message to syslog. I'll have to figure out how to use the gdb in order to find out what's going on.

Anyways, hope you guys don't feel like I'm just filling up space here, I just want to give little updates to let people know how far along I am. :)

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

Time to create page: 0.214 seconds