Hmm....very interesting. Well first a little amendment to the original unequip: Code: def unequip( slot, npc): i = 0 item = npc.item_worn_at(slot) if item != OBJ_HANDLE_NULL: if item.item_flags_get() & OIF_NO_DROP: item.item_flag_unset(OIF_NO_DROP) i = 1 holder = game.obj_create(1004, npc.location) holder.item_get(item) npc.item_get(item) if i: item.item_flag_set(OIF_NO_DROP) holder.destroy() that should take care of most possible errors and having chests left lying around But that doesn't solve the problem. you could just destroy the item in question like this: Code: npc.item_worn_at(3).destroy() but if you want to have it re-equipped later you would have to do something like this: Code: item = npc.item_worn_at(3) game.global_vars[10000] = item.name item.destroy() #########later............. item = game.obj_create(game.global_vars[10000], npc.location) npc.item_get(item) I actually tried this at the console with a greater temple bugbear and it worked fine. The weapon was even automatically equipped. Not sure what exactly you need this for Ted but I hope this helps. Darmagon
I tried the revised unequip script. It works, but both Furnok and Elmo (neither in the party) automatically re-equip the weapon instantly. For destroying it and recreating the weapon later, using an obj_f_npc_pad_i field might be better than a global, since it is personal to each NPC.
Actually, using it on party members never even occured to me, but that is very helpful, I can just stick it in the gate guard's thing and then the players first experience of KotB won't have to be manually unequipping their new characters they have just lovingly created and equipped. What I want it for is to run as a first heartbeat to unequip NPCs when you enter a map, so you don't have clerics, shopkeepers, merchants etc standing there with weapons drawn. I tried giving them specific slots in the mobs but that didn't work. Quite possibly, but I am talking about new mobs, with no 64-bit AI stuff set. I'll give it a go, but I am testing on a map with a couple clerics holding maces, nothing spectacular with no_drop flags or anything. Getting rid of the lines holder.item_get(item) npc.item_get(item) made the chest disappear, so it was running ok, it just seems to stop dead at that point for me when those lines are in (for some reason). But thanks for the feedback guys, I will keep testing. Errr, yes, Darmagon warned me about that Python-indent thing. My monitor is plugged in, too So has anyone tested this on a character outside the party, just an NPC standing around? [edit] O good, Blue was posting a test result as I typed
Okay, so I created a new MOB, flagged it ONF_NO_EQUIP and then gave it some clothing assigned to be worn in the armor slot. When tested, it was not wearing the clothing, nor could I make it wield the sword I gave it as well. So that is not the answer either. Looks like the destroy/create method is how we'll have to go with this. I would suggest using the obj_f_npc_pad_i_5 field for storing the weapon. I know it works, as I have used it for Burne and Otis when "reattaching" there shop inventories.
Thanks Blue, but if u create something, the mob just auto-equips it? Or are you suggesting creating it later? That may indeed have to be the way to go for recruitable NPCs, but for ordinary ones, far easier to just give them nothing and create / weild_best_all in their san_enter_combat bit. In any case I got this going from dialogue, I think it was failing from first heartbeat for me because I was using homemade mobs that didn't have the items slotted in - the first heartbeat may well fire before the mob auto-slots its equipment, and that seems to break the script when it found nothing in the slot (divide by zero error pehaps). But anyway, when I ran it through a dlg file it worked, but the mob reequipped itself a moment later. Thanks for all the effort on this guys, didn't work the way i wanted but it does give me a better understanding fo what can be done. Maybe I will add a 'sacrificial' weapon to equip at the start (a toothpick or something with a model you can't actually see) so they can satisfy the 'have something equipped' requirement and still have their gear in their inventory, to be pickpocketed etc by those so inclined.
I had a talk with Agetian, and it is indeed flag 7 in the NPC AI 64 flags that controls auto-equipping. Unfortunately, when the game creates the NPC, whether from a MOB or spawning, it automatically sets that flag to 1. Since it is a 64 bit field, we can't access it with get_int or set_int (we tried - get_int crashes the game, and set_int, while it doesn't crash or give any errors, doesn't seem to effect the auto-equipping). The san_first_heartbeat script does indeed run before NPCs auto_equip. If you run one with a SKIP_DEFAULT at the end, the NPCs will not equip at all and will just stand around naked. We found this out working on the Shop Map.
Interesting... as you can see above, I DID use skip_default when first trying, and certainly didn'ty get nekked characters; on the contrary, they were over-equipped. Food for thought Mr Blue, thanks for that.
Of course, Ted, when you were using the SKIP_DEFAULT, the script wasn't executing fully either, so it never got to that part. When a function runs into a problem, the interpreter just stops running the function. No more code is executed past the problem lines, included any line past the function call in the function that originally called it. So it never executed the SKIP_DEFAULT. More food for thought.
[Massively editted post] Curses! Thought i had this problem licked, but it was not to be. I removed the 'of_inventory' flag that ToEEWB automatically gives anything in an NPC's inventory, thinking this might stop them from equipping their gear - it did, but only because they dropped it on the ground, despite the fact that it remained parented to the NPC (I didn't see that first time round, the NPCs were standing on them!) The parenting thing still works to an extent because when killed the NPCs have their gear in their inventories, though you can't loot it because of course it is really lying on the ground (where you can pick it up). Bugger bugger bugger.
Ok lets bring some serious brain-power to this problem. Cerulean, how did you run this on an NPC in the party? Through the dialogue? If you manually unequip an NPC in the party, he will stand there unarmed. Yet Cerulean's effort showed the flags are still there to make him arm back up. THEREFORE there is something about the items themselves, or the slots they are put in when you unequip them, that stops them being reequiped. We have to emulate that 'something'.
I ran in on an NPC (and PC for that matter) in the party through the console. The something that is missing is that NPCs in the party ignore the auto-equipping flag. I think if we could check we would find that even PCs have this flag set. Why else would they be wearing armor and wielding weapons when you start a game without the Shop Map. The difference is that the game only checks this flag and executes auto-equipping for party members at the very start of the game. Once an NPC joins the party that flag is ignored (unless they join as an ai_follower). Ever dismissed a follower with loot still in his inventory, only to see him change weapons and armor as soon as you dismiss him? That's the auto-equip function kicking back in.
You defined it in co8.py then called it? I will give that a try. Stop admitting defeat If the engine can do it, we can do it.
Okay, this is going to be far from simple but it might work. I haven't actually written any code yet but I have done some investigations. The first part relies on my code above up to (and including "holder.get_item(item)" line. The next part relies on some things we can do with obj_set_int: we can change the inventory icon with "obj_f_item_inv_aid" ,we can change the unidentified description with "obj_f_item_description_unknown" , the same with the weight and the damage with the apporpriate parameters. Now why change anything? Because we are going to create a new object that is not equippable and apply the values from the weapon-not-to-be-wielded to it. The last thing we need is the name of the wntbw and a place to store that value in the new object (I think C-blue mentioned an int we can use above). Now we destroy the wntbw and give the NPC the new object. It is not a weapon and is unequippable anyway (we could use a wand or a scroll or something like that) so it can't be auto-equipped. but to the player looking at it it will look just like the weapon. Oh yeah and we destroy the chest The only thing missing is this: I need to know what script callback function gets fired when someone loots an object from a body? I hope there is one if not then this is useless. If there is a script callback function available we just have to alter the scripts attribute of the new object to point to a new file in which we define that function. All the function has to do is re-create the original weapon, give it to the triggerer and destroy the object we created. We can do the same thing in san_enter_combat (or is that san_start_combat?) to give the NPC the weapon in case of battle. Like I said, I haven't written any of the code for this, but unless something else unexpected comes up (the story of my ToEE modding life) this should work. One final note. If the NPC dies and the body is left to decay we have a problem> I don't know how to change the mesh of an object. We might have to do something in the san_dying script of the NPC to cover this..... Darmagon
I didn't understand a word of that, but thanks Darmagon, I will look into it I have a bee in my bonnet about this sort of stuff and will go to great lengths to deal with it.