How To Do An Item Check On Kill

01/23/2013 11:13 ajstyles316#1
Can anyone help with the code below to add a check on the person having a specific item equipped when they kill the monster, For instance they would only get the reward if they had a hammer equipped when they kill that monster?

Code:
            if (this.Name == "Phesant")

            {

                {

                    killer.SubClasses.StudyPoints += 100;

                    ServerBase.Kernel.SendWorldMessage(new Network.GamePackets.Message("  " + killer.Name + "Has Killed " + Owner.Name + " And Take 10000 StudyPoints!", System.Drawing.Color.Yellow, 2011), ServerBase.Kernel.GamePool.Values);

                }

            }
01/23/2013 11:17 go for it#2
trinity base ?
if (client.inventory.contains(uid,times))
{

}
and it's way better to do this.ID == mobID so you don't break point alot debugging to figure out you got a typo to figure out it's "Pheasant" and not "Phesant"
01/23/2013 11:35 ajstyles316#3
Haha yeah i had just noticed it was spelt wrong, Thanks for the advice i shall look at switching names to ID's, wouldnt: if (client.inventory.contains(uid,times)) only check if the item was in the persons inventory and not actually equipped in there hand when they killed the mob? And yes trinity based source.
01/23/2013 12:04 go for it#4
sorry i was in rush didn't read well you want to check if it's equipped
you need a bool at entinity, set this bool from
set it from public static void EquipItem(ItemUsage itemUsage, GameState client , byte[] packet)
also from public static void UnequipItem(ItemUsage usage, GameState client)

once on equip to set it to true
once on unequip to set it on false
you gona do the check at EquipItem UnequipItem with the item id you will get in the packets , you don't need to know much about the structure of packets you get on eq/ueq because it's already done in there , but it's way better to have a look at the packet handlers to understand the source

and finally you will do the check on killing monster with your bool
sorry for my poor english , feel free to pm me if you failed (gota show me what you done cuz i won't do it for you just help out)

and to avoid anyone say it's not efficient way i never said it is , it's just an example
goodluck mate

EDIT:
i've gave it a try , item id at those methods (eq,uneq) is static as it get that static id from the dynamic id throw "TryGetItem" method , so yup all you need to do is create item or get any item id from itemtype
and do the following
at entinity
Code:
        public bool IsWearingTheItem { get; set; }
at the packet handler add this
at EquipItem
Code:
if (item.ID == itemid) client.Entity.IsWearingTheItem = true;
and it's inverse at unequip

then at the monsterinfo
do the check as simple as this
Code:
             if (killer.IsWearingTheItem)
            {

            }
that's it :)
01/23/2013 15:57 ajstyles316#5
Thanks just got home n gave it a quick test, Seems to work But if you just right click another weapon in your inventory to equip it then it seems to not notice the previous weapon has been removed, but works fine when you open the char screen n take the weapon off manually. So im wondering if right clicking to equip another item is handled differently to just taking it off manually, Going to have a look in a min.
01/23/2013 16:18 go for it#6
well at the public static void EquipItem(ItemUsage itemUsage, GameState client , byte[] packet)
add check for the item position , if it's as same position as your item then set your bool to false
if you are good to go lemme know , if you need it in way of codes then tell me what your item position is or what it is so i give you the check can't debug with some break points atm cuz i've removed every npc and re-coding them in better way , will check it out once im done and shoot you pm or edit this post
goodluck
edit : should be something like this

Code:
Positions YourItemPos = GetPositionFromID(YourItemId); //this is how to get your item position


                    if (positionFromID == YourItemPos )
                    client.Entity.IsWearingTheItem = false;
01/23/2013 17:48 ajstyles316#7
I fixed it by just putting all of it in the equip code like:

Code:
if (item.ID == itemid) client.Entity.IsWearingTheItem = true;
else
client.Entity.IsWearingTheItem = false;
which seems to work fine and covers all angles, Thanks for you help :handsdown:


Works well for a little timed event, spawning a bunch of monsters at certain times of the day for a short while. Orignal idea was bopping moles on the head with a hammer for points & prizes but as we dont have moles in this game will have to find another creature worthy of bashing on the head with a hammer, lol
01/23/2013 18:27 go for it#8
goodluck mate :)