• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] [Trinity] Buffer Item Crash Server on Destroying item

Status
Not open for further replies.

Synth

Exalted Member
Hello Emudevs,as title say i have make a buffer item and is crashing the server when he destroy the item. I add destroy options cz i'm using buycount on the item also i don't get buffed as i write the auras on script.

That is the script:
Buffer - C++ - Pastebin

That is the SQL Query:
Code:
-- V.I.P. Buff Stone
INSERT INTO `item_template` (`entry`, `class`, `subclass`, `SoundOverrideSubclass`, `name`, `displayid`, `Quality`, `Flags`, `FlagsExtra`, `BuyCount`, `BuyPrice`, `SellPrice`, `InventoryType`, `AllowableClass`, `AllowableRace`, `ItemLevel`, `RequiredLevel`, `RequiredSkill`, `RequiredSkillRank`, `requiredspell`, `requiredhonorrank`, `RequiredCityRank`, `RequiredReputationFaction`, `RequiredReputationRank`, `maxcount`, `stackable`, `ContainerSlots`, `StatsCount`, `stat_type1`, `stat_value1`, `stat_type2`, `stat_value2`, `stat_type3`, `stat_value3`, `stat_type4`, `stat_value4`, `stat_type5`, `stat_value5`, `stat_type6`, `stat_value6`, `stat_type7`, `stat_value7`, `stat_type8`, `stat_value8`, `stat_type9`, `stat_value9`, `stat_type10`, `stat_value10`, `ScalingStatDistribution`, `ScalingStatValue`, `dmg_min1`, `dmg_max1`, `dmg_type1`, `dmg_min2`, `dmg_max2`, `dmg_type2`, `armor`, `holy_res`, `fire_res`, `nature_res`, `frost_res`, `shadow_res`, `arcane_res`, `delay`, `ammo_type`, `RangedModRange`, `spellid_1`, `spelltrigger_1`, `spellcharges_1`, `spellppmRate_1`, `spellcooldown_1`, `spellcategory_1`, `spellcategorycooldown_1`, `spellid_2`, `spelltrigger_2`, `spellcharges_2`, `spellppmRate_2`, `spellcooldown_2`, `spellcategory_2`, `spellcategorycooldown_2`, `spellid_3`, `spelltrigger_3`, `spellcharges_3`, `spellppmRate_3`, `spellcooldown_3`, `spellcategory_3`, `spellcategorycooldown_3`, `spellid_4`, `spelltrigger_4`, `spellcharges_4`, `spellppmRate_4`, `spellcooldown_4`, `spellcategory_4`, `spellcategorycooldown_4`, `spellid_5`, `spelltrigger_5`, `spellcharges_5`, `spellppmRate_5`, `spellcooldown_5`, `spellcategory_5`, `spellcategorycooldown_5`, `bonding`, `description`, `PageText`, `LanguageID`, `PageMaterial`, `startquest`, `lockid`, `Material`, `sheath`, `RandomProperty`, `RandomSuffix`, `block`, `itemset`, `MaxDurability`, `area`, `Map`, `BagFamily`, `TotemCategory`, `socketColor_1`, `socketContent_1`, `socketColor_2`, `socketContent_2`, `socketColor_3`, `socketContent_3`, `socketBonus`, `GemProperties`, `RequiredDisenchantSkill`, `ArmorDamageModifier`, `duration`, `ItemLimitCategory`, `HolidayId`, `ScriptName`, `DisenchantID`, `FoodType`, `minMoneyLoot`, `maxMoneyLoot`, `flagsCustom`, `WDBVerified`) VALUES (100004, 15, 0, -1, 'V.I.P. Buff Stone', 50216, 4, 1, 0, 100, 0, 0, 0, -1, -1, 290, 80, 0, 0, 0, 0, 0, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18282, 0, 0, 0, 8000, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 1, 'Click on me to get some nice buffs for you and your group!', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 'Buffer_VIP', 0, 0, 0, 0, 0, 1);

NOTE:I'm using return false cz if i set it to true i will get visual bug highlights on action bar.

Can someone re-updated for me please ?

Thank you!
Best regards,
Synth !
 
Last edited:

callmephil

Respected Member
You should Add the fonction you want to the "spell" and after use the spell by sql in the sql item.
Check in spell_item.cpp
[Update]
Nevermind Forget It will not work for things you are asking.
 
Last edited:

Synth

Exalted Member
You should Add the fonction you want to the "spell" and after use the spell by sql in the sql item.
Check in spell_item.cpp
[Update]
Nevermind Forget It will not work for things you are asking.
Lol ?
It can be worked i see many servers have it...
 

Rochet2

Moderator / Eluna Dev
The for loops spam the message to the player and also remove tokens too much.
The return on the loop also screws the point of the loop.

You should be able to delete the used item. Why remove item by entry and count?
player->DestroyItemCount(item, itemCount, true);

Loop for group ;
Code:
 for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next())
        {
            Player* member = itr->GetSource();

            if (!member || !member->GetSession())
                continue;

// do stuff


Not sure what crashes, but i think it's the group loop or your use of destroy item count.
Check your use of return false and true.
 

Synth

Exalted Member
The for loops spam the message to the player and also remove tokens too much.
The return on the loop also screws the point of the loop.

You should be able to delete the used item. Why remove item by entry and count?
player->DestroyItemCount(item, itemCount, true);

Loop for group ;
Code:
 for (GroupReference* itr = group->GetFirstMember(); itr; itr = itr->next())
        {
            Player* member = itr->GetSource();

            if (!member || !member->GetSession())
                continue;

// do stuff


Not sure what crashes, but i think it's the group loop or your use of destroy item count.
Check your use of return false and true.
If i'm not on raid group so just alone without any invites,it crash the server and if i'm on raid group it JUST buff me 1 buff and don't crash the server,i want to fix it for not crash and also for give me whole buffs ids i included on the script.
I re-change something on script as you said about destroy.
 

Tommy

Founder
If i'm not on raid group so just alone without any invites,it crash the server and if i'm on raid group it JUST buff me 1 buff and don't crash the server,i want to fix it for not crash and also for give me whole buffs ids i included on the script.
I re-change something on script as you said about destroy.

Because as Rochet mentioned, what's inside of the for loop is causing the crash. You're trying to check/delete the item as many times as it loops through, which is incorrectly done. Also, the notification should be on the outside of the for loop, not on the inside considering it will spam until the loop ends.

I don't see why you have 'return false' in the loop seeing that once the loop ends it will stop everything.

Depending on the amount of people in a group, that loop is going to be quite a kicker once a player uses it. Now, instead of checking to see if the item exists and deleting it the hard way, you can use the 'item' variable for this. You also don't need two deletion of item code anyway, considering either way it is going to be called, so I put it on the bottom. I deleted all of the header files you were including except for 'Group.h'. You don't need all of those headers because they are being referenced already, only headers you need to include are the ones you need, like Group.h for example.

I removed your 'Unit::FindPlayer' when you can use 'sObjectAccessor->FindPlayer'. I'm sure they somewhat resemble each other, but I find it best to use 'sObjectAccessor' in most cases.

Code:
#include "Group.h"

uint32 auras[] = { 48074, 47440, 53307, 132, 48170, 23737, 48470, 43002, 26393, 48162 };
uint32 ITEM_ID = 100004;

class Buffer_VIP : public ItemScript
{
public:
    Buffer_VIP() : ItemScript("Buffer_VIP") { }

    bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/)
    {
        if (player->IsInFlight())
        {
            player->GetSession()->SendNotification("You cannot use this in Flight!");
            return true;
        }

        if(player->IsInCombat())
        {
            player->GetSession()->SendNotification("You can't use this buff while in combat!");
            return false;
        }

        if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
        {
            player->GetSession()->SendNotification("You cannot use this, you are dead!");
            return true;
        }

        if (Group* playerGroup = player->GetGroup())
        {
            if (playerGroup->isRaidGroup())
            {
                Player* member;
                const Group::MemberSlotList members = playerGroup->GetMemberSlots();
                for (Group::member_citerator itr = members.begin(); itr != members.end(); ++itr)
                {
                    member = sObjectAccessor->FindPlayer(itr->guid);
                    for(int i = 0; i < 10; i++)
                        member->AddAura(auras[i], member);
                }
                player->GetSession()->SendNotification("|cffff0000You have been buffed yourself and your group!");
            }
        }
        else
        {
            for(int i = 0; i < 10; i++)
                player->AddAura(auras[i], player);
            player->GetSession()->SendNotification("|cffff0000You have been buffed!");
        }
        if(player->HasItemCount(item->GetEntry(), 1))
            player->DestroyItemCount(item->GetEntry(), 1, true);
        return false;
    }
};

void AddSC_Buffer_VIP()
{
    new Buffer_VIP;
}
 

Synth

Exalted Member
Because as Rochet mentioned, what's inside of the for loop is causing the crash. You're trying to check/delete the item as many times as it loops through, which is incorrectly done. Also, the notification should be on the outside of the for loop, not on the inside considering it will spam until the loop ends.

I don't see why you have 'return false' in the loop seeing that once the loop ends it will stop everything.

Depending on the amount of people in a group, that loop is going to be quite a kicker once a player uses it. Now, instead of checking to see if the item exists and deleting it the hard way, you can use the 'item' variable for this. You also don't need two deletion of item code anyway, considering either way it is going to be called, so I put it on the bottom. I deleted all of the header files you were including except for 'Group.h'. You don't need all of those headers because they are being referenced already, only headers you need to include are the ones you need, like Group.h for example.

I removed your 'Unit::FindPlayer' when you can use 'sObjectAccessor->FindPlayer'. I'm sure they somewhat resemble each other, but I find it best to use 'sObjectAccessor' in most cases.
I replaced your one it still crash when i'm alone,and don't cast on me the buffs...
 

Tommy

Founder
qa54.png


It worked for me, but when I used it again, it crashed the server. I removed the code that was deleting the item and it doesn't crash anymore. I spammed use the item 10 times and it still didn't crash it. I believe the item will automatically delete itself after you use it. If it doesn't have the "DESTROY_ITEM" flag, it deletes itself, so really there is no need for the deletion code.

Code:
#include "Group.h"

uint32 auras[] = { 48074, 47440, 53307, 132, 48170, 23737, 48470, 43002, 26393, 48162 };

class Buffer_VIP : public ItemScript
{
public:
    Buffer_VIP() : ItemScript("Buffer_VIP") { }

    bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/)
    {
        if (player->IsInFlight())
        {
            player->GetSession()->SendNotification("You cannot use this in Flight!");
            return true;
        }

        if(player->IsInCombat())
        {
            player->GetSession()->SendNotification("You can't use this buff while in combat!");
            return false;
        }

        if (player->HasStealthAura() || player->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_FEIGN_DEATH) || player->isDead())
        {
            player->GetSession()->SendNotification("You cannot use this, you are dead!");
            return true;
        }

        if (Group* playerGroup = player->GetGroup())
        {
            if (playerGroup->isRaidGroup())
            {
                Player* member;
                const Group::MemberSlotList members = playerGroup->GetMemberSlots();
                for (Group::member_citerator itr = members.begin(); itr != members.end(); ++itr)
                {
                    member = sObjectAccessor->FindPlayer(itr->guid);
                    for(int i = 0; i < 10; i++)
                        member->AddAura(auras[i], member);
                }
                player->GetSession()->SendNotification("|cffff0000You have been buffed yourself and your group!");
            }
        }
        else
        {
            for(int i = 0; i < 10; i++)
                player->AddAura(auras[i], player);
            player->GetSession()->SendNotification("|cffff0000You have been buffed!");
        }
        return false;
    }
};

void AddSC_Buffer_VIP()
{
    new Buffer_VIP;
}
 

Synth

Exalted Member
qa54.png


It worked for me, but when I used it again, it crashed the server. I removed the code that was deleting the item and it doesn't crash anymore. I spammed use the item 10 times and it still didn't crash it. I believe the item will automatically delete itself after you use it. If it doesn't have the "DESTROY_ITEM" flag, it deletes itself, so really there is no need for the deletion code.
Now its not crashing but the last problem is when the buycount done i still can use it example when i have x2 Buff item and i use it it destroy automactly and i get 1 but when i try to use it again it don't destroy it i still can use it so its not 0 or removed from my bags.
 

Synth

Exalted Member
Show item sql.
use negative charges?
There you go:
Code:
-- V.I.P. Buff Stone
INSERT INTO `item_template` (`entry`, `class`, `subclass`, `SoundOverrideSubclass`, `name`, `displayid`, `Quality`, `Flags`, `FlagsExtra`, `BuyCount`, `BuyPrice`, `SellPrice`, `InventoryType`, `AllowableClass`, `AllowableRace`, `ItemLevel`, `RequiredLevel`, `RequiredSkill`, `RequiredSkillRank`, `requiredspell`, `requiredhonorrank`, `RequiredCityRank`, `RequiredReputationFaction`, `RequiredReputationRank`, `maxcount`, `stackable`, `ContainerSlots`, `StatsCount`, `stat_type1`, `stat_value1`, `stat_type2`, `stat_value2`, `stat_type3`, `stat_value3`, `stat_type4`, `stat_value4`, `stat_type5`, `stat_value5`, `stat_type6`, `stat_value6`, `stat_type7`, `stat_value7`, `stat_type8`, `stat_value8`, `stat_type9`, `stat_value9`, `stat_type10`, `stat_value10`, `ScalingStatDistribution`, `ScalingStatValue`, `dmg_min1`, `dmg_max1`, `dmg_type1`, `dmg_min2`, `dmg_max2`, `dmg_type2`, `armor`, `holy_res`, `fire_res`, `nature_res`, `frost_res`, `shadow_res`, `arcane_res`, `delay`, `ammo_type`, `RangedModRange`, `spellid_1`, `spelltrigger_1`, `spellcharges_1`, `spellppmRate_1`, `spellcooldown_1`, `spellcategory_1`, `spellcategorycooldown_1`, `spellid_2`, `spelltrigger_2`, `spellcharges_2`, `spellppmRate_2`, `spellcooldown_2`, `spellcategory_2`, `spellcategorycooldown_2`, `spellid_3`, `spelltrigger_3`, `spellcharges_3`, `spellppmRate_3`, `spellcooldown_3`, `spellcategory_3`, `spellcategorycooldown_3`, `spellid_4`, `spelltrigger_4`, `spellcharges_4`, `spellppmRate_4`, `spellcooldown_4`, `spellcategory_4`, `spellcategorycooldown_4`, `spellid_5`, `spelltrigger_5`, `spellcharges_5`, `spellppmRate_5`, `spellcooldown_5`, `spellcategory_5`, `spellcategorycooldown_5`, `bonding`, `description`, `PageText`, `LanguageID`, `PageMaterial`, `startquest`, `lockid`, `Material`, `sheath`, `RandomProperty`, `RandomSuffix`, `block`, `itemset`, `MaxDurability`, `area`, `Map`, `BagFamily`, `TotemCategory`, `socketColor_1`, `socketContent_1`, `socketColor_2`, `socketContent_2`, `socketColor_3`, `socketContent_3`, `socketBonus`, `GemProperties`, `RequiredDisenchantSkill`, `ArmorDamageModifier`, `duration`, `ItemLimitCategory`, `HolidayId`, `ScriptName`, `DisenchantID`, `FoodType`, `minMoneyLoot`, `maxMoneyLoot`, `flagsCustom`, `WDBVerified`) VALUES (100004, 15, 0, -1, 'V.I.P. Buff Stone', 50216, 4, 1, 0, 100, 0, 0, 0, -1, -1, 290, 80, 0, 0, 0, 0, 0, 0, 0, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18282, 0, 0, 0, 8000, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 0, 0, NULL, 0, -1, 0, -1, 1, 'Click on me to get some nice buffs for you and your group!', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 'Buffer_VIP', 0, 0, 0, 0, 0, 1);
 

Tommy

Founder
Sowie, forgot to mention use negative charges, etc. My item has -1 trigger and -1 charges.
 

Synth

Exalted Member
Sowie, forgot to mention use negative charges, etc. My item has -1 trigger and -1 charges.
Thank you its fixed you can marked as solved.
Code:
UPDATE `item_template` SET `spellcharges_1`=-1, `spellcharges_2`=-1, `spellcharges_3`=-1, `spellcharges_4`=-1, `spellcharges_5`=-1 WHERE  `entry`=100004;
 
Status
Not open for further replies.
Top