Welcome to AC Web.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772

    Need help to update C++ Script


    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Hello guys !

    Can anyone please help me update this script. I think its outdated, it returned some error about unresolved symbol
    Code:
    #include "ScriptPCH.h"
    
    uint32 ITEM_ID = 55000;
    uint8 MAX_LVL = 255;
    
    class item_level : public ItemScript
    {
    public:
        item_level() : ItemScript("item_level") { }
    
        bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/)
        {
            if(player->isInCombat() || player->isInFlight())
            {
                player->GetSession()->SendNotification("You Cant Use This Right Now!");
                return false;
            }
            if(player->getLevel() >= MAX_LVL)
            {
                player->GetSession()->SendNotification("You are already max level.");
                return false;
            }
    
            int32 oldlevel = player->getLevel();
            int32 newLevel = oldlevel + 1;
    
            player->GiveLevel(newLevel);
            player->InitTalentForLevel();
            player->SetUInt32Value(PLAYER_XP, 0);
            player->DestroyItemCount(ITEM_ID, 1, true);
            player->GetSession()->SendNotification("You have used one level token. Thanks for supporting our server");
            return true;
        }
    };
    
    void AddSC_item_level()
    {
        new item_level();
    }

  2. #2
    I can't really test now, but the only issues I'm seeing with the script from looking at it is

    Code:
    if(player->isInCombat() || player->isInFlight())
    These functions were renamed a while back, they should be written like

    Code:
    if(player->IsInCombat() || player->IsInFlight())

  3. #3
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772
    Quote Originally Posted by Loud21 View Post
    I can't really test now, but the only issues I'm seeing with the script from looking at it is

    Code:
    if(player->isInCombat() || player->isInFlight())
    These functions were renamed a while back, they should be written like

    Code:
    if(player->IsInCombat() || player->IsInFlight())
    Yes. The first problem was that i did not rerun cmake so i had unresolved symbol error but now when i try again i had these errors about isInCombat and isInFlight. But i will try again with the new code you added

    - - - Updated - - -

    Okey. Here is the other error
    Code:
    left of '->SendNotification' must point to class/struct/union/generic type
    but it points to GetSession() and i assume GetSession is a class? I don't really know much about C++ xD
    Last edited by Tok124; 08-21-2017 at 10:19 PM.

  4. #4
    Did you modify the script at all since you first posted it?

    Code:
    player->GetSession()->SendNotification("message here");
    Should work perfectly fine, unless trinity devs changed something recently. And yes WorldSession is a class

  5. #5
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772
    Quote Originally Posted by Loud21 View Post
    Did you modify the script at all since you first posted it?

    Code:
    player->GetSession()->SendNotification("message here");
    Should work perfectly fine, unless trinity devs changed something recently. And yes WorldSession is a class
    No i have not edited anything in the script except from what you told me to edit. I tried remove all those SendNotification lines and the script now works just fine. But it obviously doesnt send anything anymore... So i would like to know how to fix it

  6. #6
    Apparently that function is used in the same way on the latest revision of trinity, so i'm not sure why you're getting errors.

    Maybe try replacing it with like

    Code:
    player->GetSession()->SendAreaTriggerMessage("message here");
    - Although this one sends the text in yellow letters so if you want red like in the SendNotification add

    Code:
    |cffFF0000
    infront of your msg and

    Code:
    |r
    at the end of your msg

    Or you could try

    Code:
    ChatHandler(player->GetSession()).SendSysMessage("message here");
    - This one will send a message to the players general chat box instead of at the top of the screen

  7. #7
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772
    Quote Originally Posted by Loud21 View Post
    Apparently that function is used in the same way on the latest revision of trinity, so i'm not sure why you're getting errors.

    Maybe try replacing it with like

    Code:
    player->GetSession()->SendAreaTriggerMessage("message here");
    - Although this one sends the text in yellow letters so if you want red like in the SendNotification add

    Code:
    |cffFF0000
    infront of your msg and

    Code:
    |r
    at the end of your msg

    Or you could try

    Code:
    ChatHandler(player->GetSession()).SendSysMessage("message here");
    - This one will send a message to the players general chat box instead of at the top of the screen
    Oh alright. Thanks i will give it a try

    - - - Updated - - -

    Code:
    'ChatHandler': identifier not found
    Code:
    left of 'SendSysMessage' must have class/struct/union
    Maybe it requires that i include another file? Currently only ScriptPCH.h is included. Maybe chathandler.cpp needs to be included aswell?
    Last edited by Tok124; 08-21-2017 at 10:47 PM.

  8. #8


    Join Date
    Mar 2016
    Location
    Chaos is the score upon which reality is written.
    Posts
    760
    Try to include WorldSession.h
    I don't know if this will work.

  9. #9
    Code:
    #include "ScriptPCH.h"
    #include "ScriptMgr.h"
    #include "ScriptedGossip.h"
    #include "ScriptedCreature.h"
    #include "Player.h"
    #include "Unit.h"
    #include "World.h"
    #include "WorldSession.h"
    One of these will definitely fix it, not sure which, and unfortunately I can't test cause my source is from like april, i need to update it soon, but I think that something with ScriptPCH.h was changed, I remember someone posting in the support section about it. I might be wrong though.

  10. #10
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772
    Quote Originally Posted by mindsear View Post
    Try to include WorldSession.h
    I don't know if this will work.
    I included chathandler.cpp and now it didnt give me any errors and it works just fine. Thanks anyway

    - - - Updated - - -

    Quote Originally Posted by Loud21 View Post
    Code:
    #include "ScriptPCH.h"
    #include "ScriptMgr.h"
    #include "ScriptedGossip.h"
    #include "ScriptedCreature.h"
    #include "Player.h"
    #include "Unit.h"
    #include "World.h"
    #include "WorldSession.h"
    One of these will definitely fix it, not sure which, and unfortunately I can't test cause my source is from like april, i need to update it soon, but I think that something with ScriptPCH.h was changed, I remember someone posting in the support section about it. I might be wrong though.
    chathandler.cpp worked just fine. But thanks for all help !

  11. #11
    A tip for @loud21 and @OP, when having an issue about an incomplete struct, class or similar, it is 100% of the time in Trinitycore due to a missing include, just figure out what main class the function is part of, and include it.

  12. #12
    Hey Tok124 ,

    I've updated the script and changed a few things:
    - The item will no longer be removed / consumed when you use it if you are in combat (You need to use a spell in your item_template to use the OnUse function, otherwise it won't be triggered). I've rewritten some part of the code to achieve this. After each check I returned true because we do not want the function to continue in combat or on maxlevel anyways. This way the player can keep the item even on maxlevel or in combat usage. For the spell I used in my item: it can be any spell but I created my own which basically does nothing ( no effects etc. - I just needed a spell to be used for the item to call the OnUse function.)

    Code:
    #include "ScriptMgr.h"
    #include "Player.h"
    #include "WorldSession.h"
    
    uint32 ITEM_ID = 55000;
    uint8 MAX_LVL = 90;
    
    class item_level : public ItemScript
    {
    public:
    	item_level() : ItemScript("item_level") { }
    
    	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
    	{
    		if (player->IsInCombat() || player->IsInFlight())
    		{
    			player->SendEquipError(EQUIP_ERR_CANT_DO_RIGHT_NOW, item, NULL);
    			return true;
    		}
    		if (player->getLevel() >= MAX_LVL)
    		{
    			player->GetSession()->SendNotification("You already reached the maximum level.");
    			return true;
    		}
    		else
    		{
    			int32 oldlevel = player->getLevel();
    			int32 newLevel = oldlevel + 1;
    
    			player->GiveLevel(newLevel);
    			player->InitTalentForLevel();
    			player->SetUInt32Value(PLAYER_XP, 0);
    			player->DestroyItemCount(ITEM_ID, 1, true);
    			player->GetSession()->SendNotification("You have used one Level Token. Thanks for supporting our server");
    		}
    		return true;
    	}
    };
    
    void AddSC_item_level()
    {
    	new item_level();
    }
    Here is the SQL part:

    Code:
    Set @SPELL_ID := '142000'; -- My custom spellid 
    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`, `VerifiedBuild`) values('55000','0','8','-1','Level Token','34508','1','0','0','1','275','68','0','-1','-1','21','0','0','0','0','0','0','0','0','0','10','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',@SPELL_ID,'0','-1','-1','-1','0','0','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','1','','0','0','0','0','0','-1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','-1','0','0','0','0','item_level','0','0','0','0','0','12340');
    Regards,

    Astyc.
    Last edited by Astyc; 08-22-2017 at 09:54 AM.

  13. #13
    Web Developer

    Join Date
    Oct 2010
    Location
    somewhere between <?php and ?>
    Posts
    2,772
    Quote Originally Posted by Astyc View Post
    Hey Tok124 ,

    I've updated the script and changed a few things:
    - The item will no longer be removed / consumed when you use it if you are in combat (You need to use a spell in your item_template to use the OnUse function, otherwise it won't be triggered). I've rewritten some part of the code to achieve this. After each check I returned true because we do not want the function to continue in combat or on maxlevel anyways. This way the player can keep the item even on maxlevel or in combat usage. For the spell I used in my item: it can be any spell but I created my own which basically does nothing ( no effects etc. - I just needed a spell to be used for the item to call the OnUse function.)

    Code:
    #include "ScriptMgr.h"
    #include "Player.h"
    #include "WorldSession.h"
    
    uint32 ITEM_ID = 55000;
    uint8 MAX_LVL = 90;
    
    class item_level : public ItemScript
    {
    public:
    	item_level() : ItemScript("item_level") { }
    
    	bool OnUse(Player* player, Item* item, SpellCastTargets const& /*targets*/) override
    	{
    		if (player->IsInCombat() || player->IsInFlight())
    		{
    			player->SendEquipError(EQUIP_ERR_CANT_DO_RIGHT_NOW, item, NULL);
    			return true;
    		}
    		if (player->getLevel() >= MAX_LVL)
    		{
    			player->GetSession()->SendNotification("You already reached the maximum level.");
    			return true;
    		}
    		else
    		{
    			int32 oldlevel = player->getLevel();
    			int32 newLevel = oldlevel + 1;
    
    			player->GiveLevel(newLevel);
    			player->InitTalentForLevel();
    			player->SetUInt32Value(PLAYER_XP, 0);
    			player->DestroyItemCount(ITEM_ID, 1, true);
    			player->GetSession()->SendNotification("You have used one Level Token. Thanks for supporting our server");
    		}
    		return true;
    	}
    };
    
    void AddSC_item_level()
    {
    	new item_level();
    }
    Here is the SQL part:

    Code:
    Set @SPELL_ID := '142000'; -- My custom spellid 
    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`, `VerifiedBuild`) values('55000','0','8','-1','Level Token','34508','1','0','0','1','275','68','0','-1','-1','21','0','0','0','0','0','0','0','0','0','10','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',@SPELL_ID,'0','-1','-1','-1','0','0','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','0','0','0','0','-1','0','-1','1','','0','0','0','0','0','-1','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','0','-1','0','0','0','0','item_level','0','0','0','0','0','12340');
    Regards,

    Astyc.
    Thanks mate ! I will give it a try soon And yeah. I know about using a spell. I'm currently using This Spell and it works fine

  14. #14


    Join Date
    Dec 2015
    Location
    Developing the world
    Posts
    762
    In lua you can return false so the spell wont even be casted, just saying I am not sure is it like this in CPP.

  15. #15
    weird like that

    Join Date
    Feb 2010
    Location
    http://rochet2.github.io/
    Posts
    5,114

    REGISTER! (FREE)
    Registered members see less ads
    and also gain access to other great features.
    Quote Originally Posted by titkata_bg View Post
    In lua you can return false so the spell wont even be casted, just saying I am not sure is it like this in CPP.
    The spell gets visually bugged if you just return false in c++. In Eluna there is a workaround to fix the visual bug:
    https://github.com/ElunaLuaEngine/El...ks.cpp#L62-L74
    So by using that you can achieve the same.

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •