$corpse->RemoveItem($slotID) issue
Any suggestions as to why RemoveItem() might not work on an NPC corpse? I'm trying to delete the last item the NPC was manually given after spawning and having it killed using a line such as this one:
$corpse->RemoveItem($corpse->CountItems()); I'm currently using $corpse->Delete() to keep the item in question from being retrieved, but I'd like to be able to keep the original loot generated upon spawning. NOTE: I've looked in the source and nothing is really standing out to indicate I'm way off base in my understanding of how this function should work. |
I haven't looked at the documentation for the perl function or the source, but are items enumerated from 0? If so, you might need something like
Code:
$corpse->RemoveItem($corpse->CountItems() - 1); |
yeah, sorry. i guess i forgot to mention that i've tried that as well before posting my question. :)
|
just for grins try this opcode OP_LootComplete=0x528f see if that helps
|
Quote:
UPDATE: i wrote the following test plugin to make absolutely certain the issue wasn't with the slot numbers Code:
sub DeleteAllLoot { |
Well, let's look at the code, it's pretty short and simple.
Code:
void Corpse::RemoveItem(int16 lootslot) The only place I can see is Corpse::MakeLootRequestPackets where it is assigned 0xFFFF, and then a few lines later to a sequential value. That function appears to be called when someone actually clicks on a corpse to loot it which may be later than you run your perl code. NPC::AddLootDrop seems like a logical place to assign a value to ServerLootItem_Struct::lootslot, but I didn't see anything in there that would do so. ServerLootItem_Struct has no constructor, so what ends up in there by default is probably uninitialized garbage of some sort. Short answer is I would guess that function isn't all that useful the way it is now. Maybe it should just take an index into the list of items and delete that index which is what it seems you want. Even if the code you're using is in EVENT_LOOT, I'm not sure it's possible to prevent the current item from being looted by deleting it, but that's just my guess. |
well hell, that makes PERFECT sense. now i'm not sure why the function was exposed to perl at all. i can't wrap my head around how it would be used. i'm going to go to sleep and see if i can't sort something out tomorrow. looks like the only way to do what i'm trying to do is to modify the source. i was trying to avoid that, but oh well. thanks.
|
If you are trying to delete items from the NPC when it dies during EVENT_DEATH or something like that directly on the NPC's perl script, you will need to be using $npc commands, not $corpse stuff. At that time, I don't think the $corpse entity exists yet for that NPC.
Under the NPC class, there is this quest object: Code:
RemoveItem(item_id, quantity= 0, slot= 0) Removing it from the corpse itself would probably be easier, but you would need to do it from something like player.pl or something. Since you can't really use EVENT_LOOT for that (I don't think), you may just need to send a signal to another NPC when the main NPC is killed and then have a timer that waits a second (to allow the corpse to be created) then searches all corpses and removes those items at that time. |
EVENT_DEATH is parsed after the corpse created and the npc is removed from the entity list, at the tail end of NPC::Death(). the corpse's item list would already have been populated at that point. i'm probably going to have to add a function such as $corpse->RemoveItemByID() to be able to do what i'm looking to do. i'll have the item id stored in the script for the npc that i'll need to delete from the corpse. working on a method to generate random loot for npcs on spawn (in addition to normal loot table drops) and means to delete said randomly generated loot if the kill was trivial to anyone on the npc's hate list on death. everything else is working flawlessly except for this one part. for the time being, i have the corpse poofing entirely, but i'd rather just remove the one item.
EDIT: hmmm... i guess i could always cause the item to poof after it was looted in EVENT_LOOT via player.pl, but that'd surely cause an uproar from the player base. haha. |
actually, if i moved the code that fires off EVENT_DEATH / EVENT_NPC_SLAY in the source up a bit to directly after experience and faction hits are given, and right before the corpse is created, the perl $npc methods would work perfectly. i don't see how that would really break anything with the source and it'd be a very minor change.
gah... i'm never going to get to sleep at this rate. |
Ahh, I misunderstood your reason for wanting to remove the item. If you are adding them via a script, then you have full control over if they get added or not. Why not just add the item to the corpse after it dies or at the time of death or attack or any number of possible spots instead of adding it all on spawn? That will reduce the work load on the server a bit when your zone is spawned, since it won't be doing it for all NPCs at once, just when needed.
I have a somewhat similar plugin I use that adds loot when combat is started. Basically I use it to scale loot drop rates to the size of the group that engaged the NPC. The idea is to help promote grouping by giving increased quest item drop rates and such based on the size of the group so you aren't penalized by drops as much when grouping. People should be more willing to open up group slots to others if they know it won't take them 6X as long to get the drops they need. This plugin does have a trivial loot code option if you set it. I can give an example of usage if you need. It could probably work to do what you are wanting without actually scaling the drop rates. Though, it looks like the trivial check wasn't added to the non-group sections of the plugin (as I don't use that option yet anyway), so you would need to modify it slightly. Code:
###Usage: plugin::ScaleDropToGroup(item_id, Chance[1-100], Scale[1-100]=100, Group_Only=0, Max_Chance=100, Trivial=0); Code:
###Usage: plugin::AddLoot( item_id, chance[1-100]); |
nice ideas there!
i think i'll tweak mine a bit to where the loot is added when the npc is engaged to deal with initial zone load times, scaling that chance based on character/group/raid makeup. absolutely brilliant. :) i still want to have code to remove equipment on death if anything gets added to the npc's hate list that would cause the kill to be considered trivial for the following reasons: 1) the npc will equip the item, theoretically increasing encounter difficulty (do want) 2) if every npc in game has a chance at random loot, people will seek out greens (do not want) i moved the triggers for EVENT_DEATH and EVENT_NPC_SLAY and started a compile earlier before i passed out for a few hours. i'm going to test it in a little while. this should keep me from having to iterate over the entire corpse list for a zone to find the corpse owned by the npc as well. |
All times are GMT -4. The time now is 09:08 PM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.