• 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] Trinitycore Function

Status
Not open for further replies.

blackmetal

Exalted Member
Hi, i'm currently learning C++ and i have a question:
I'm looking for a function that when equip item, it does something. Example ( I get this script through internet )


Code:
#include "ScriptPCH.h"

#define item_id 999043

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

	bool OnEquip(Player * player, Item * item_id, SpellCastTargets const& /*targets*/)
	{
		player->SetDisplayId(21105);
		return false;
	}
};

void AddSC_lk_ilusion()
{
	new lk_ilusion();
}

I know Function OnEquip doesn't exists in TC, i'm looking for same function like this :D
 

Tommy

Founder
No problem. Regardless, my post should still be fine in terms of information (linking Eluna for example).
 

blackmetal

Exalted Member
Hi, i'm really don't know about this. I tried to write code but when i compile it, it gives me so much error and i don't know which way to fix it :coffee:


Code:
#include "ScriptPCH.h"

#define item_id 999043

class lk_ilusion : public ItemScript
{
public:
	lk_ilusion() : ItemScript("lk_ilusion") {}
	Player* player;
	// EQUIPMENT_SLOT_BODY = 3
	Item* Player::EquipNewItem(3,item_id,bool update){
		player->SetDisplayId(21105);
	}
	
	
		
  

};

void AddSC_lk_ilusion()
{
	new lk_ilusion();
}

Can you give me an example to do this? Thanks !!!
 
Last edited:

Tommy

Founder
Guess you didn't really read what I posted. :3

You weren't supposed to paste the contents of "EquipNewItem" to the ItemScript because obviously it won't work. You were supposed to go in Player.cpp and put "SetDisplayId(...)" in the "EquipNewItem" function.

Example:

Go to "Item* Player::EquipNewItem(uint16 pos, uint32 item, bool update)" function in Player.cpp. Update, let's say, "UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, 1);" put "SetDisplayId(21105);".

Output:

Code:
Item* Player::EquipNewItem(uint16 pos, uint32 item, bool update)
{
    if (Item* pItem = Item::CreateItem(item, 1, this))
    {
        ItemAddedQuestCheck(item, 1);
        UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, 1);
        [COLOR="#00FF00"]SetDisplayId(21105);[/COLOR]
        return EquipItem(pos, pItem, update);
    }

    return NULL;
}
 

blackmetal

Exalted Member
Honestly, i'm kinda new to this ..

Here is what i did:

Code:
#include "ScriptPCH.h"

#define item  999043

class lk_ilusion : public ItemScript
{
public:
	lk_ilusion() : ItemScript("lk_ilusion") {
	Item* Player::EquipNewItem(uint16 pos, uint32 item, bool update)
	{
		if (Item* pItem = Item::CreateItem(item, 1, this))
		{
			ItemAddedQuestCheck(item, 1);
			UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, 1);
			SetDisplayId(21105);
			return EquipItem(pos, pItem, update);
		}

		return NULL;
	}

	}
	
	
		
  

};

void AddSC_lk_ilusion()
{
	new lk_ilusion();
}

And here is my error when i build

Code:
Error	6	error C2059: syntax error : ')'	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	1	scripts
Error	5	error C2062: type 'bool' unexpected	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	1	scripts
Error	12	error C2065: 'pos' : undeclared identifier	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	16	1	scripts
Error	13	error C2065: 'update' : undeclared identifier	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	16	1	scripts
Error	2	error C2143: syntax error : missing ')' before 'constant'	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	1	scripts
Error	7	error C2143: syntax error : missing ';' before '{'	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	10	1	scripts
Error	3	error C2143: syntax error : missing ';' before 'constant'	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	1	scripts
Error	15	error C2534: 'lk_ilusion' : constructor cannot return a value	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	19	1	scripts
Error	16	error C2562: 'lk_ilusion::lk_ilusion' : 'void' function returning a value	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	19	1	scripts
Error	8	error C2664: 'Item *Item::CreateItem(uint32,uint32,const Player *)' : cannot convert argument 3 from 'lk_ilusion *const ' to 'const Player *'	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	11	1	scripts
Error	4	error C2761: 'Item *Player::EquipNewItem(uint16,uint32,bool)' : member function redeclaration not allowed	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	1	scripts
Error	14	error C3861: 'EquipItem': identifier not found	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	16	1	scripts
Error	9	error C3861: 'ItemAddedQuestCheck': identifier not found	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	13	1	scripts
Error	11	error C3861: 'SetDisplayId': identifier not found	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	15	1	scripts
Error	10	error C3861: 'UpdateAchievementCriteria': identifier not found	E:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	14	1	scripts
Error	38	error LNK1181: cannot open input file '..\scripts\Release\scripts.lib'	E:\WowSource Repack\Build\src\server\worldserver\LINK	worldserver
	40	IntelliSense: expected a ')'	e:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	48	scripts
	41	IntelliSense: expected a ';'	e:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	10	2	scripts
	39	IntelliSense: member function "Player::EquipNewItem" may not be redeclared outside its class	e:\WowSource Repack\Source\WoWSource434\src\server\scripts\Custom\lk_ilusion.cpp	9	16	scripts

Sorry for my bad understanding :(
 

Tommy

Founder
You weren't supposed to paste the contents of "EquipNewItem" to the ItemScript because obviously it won't work. You were supposed to go in Player.cpp and put "SetDisplayId(...)" in the "EquipNewItem" function.

Stop using ItemScript and a separate source file completely. Delete the script. Read my post thoroughly.

Go to Player.cpp and search for "Item* Player::EquipNewItem(uint16 pos, uint32 item, bool update)". Inside of that function, above "return EquipNewItem(pos, pItem, update);" put:

Code:
SetDisplayId(21105);
 

blackmetal

Exalted Member
Sorry to make you mad ...
I mean i want to create a script that will assign to an item, then everytime i equip that item, i can transform to another DisplayID ( Example: 21105 ) :( :(
 

Tommy

Founder
Sorry to make you mad ...
I mean i want to create a script that will assign to an item, then everytime i equip that item, i can transform to another DisplayID ( Example: 21105 ) :( :(

I'm not mad. I added so much bbcode to my post so you can read it better. :p

There's no hook like that as we already established, and I gave you an example of where you could add a hook. If you want to learn how to add a hook, view ScriptMgr.cpp and ScriptMgr.h and look at existing hooks for example.
 

blackmetal

Exalted Member
After read again, again and again. I realized that i'm poiting wrong. I mean i want create a "specific" script for "an item" that when i equip that i can transform to another form ( DisplayId) not all item i equip
And spent some time for research over again, i can not find function that catch event onquip -_-. But i have made this script :3

Code:
#include "ScriptPCH.h"

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

	bool OnUse(Player* player, Item* /*item*/, SpellCastTargets const& /*targets*/) 
	{ 
		player->SetDisplayId(21105);
		return false; 
	
	}
};

void AddSC_lk_ilusion()
{
	new lk_ilusion();
}

I set a random spell ( 17529 ) to item template. I have need to click to item to make my character can transform :D

Can you tell me where i can find function that when i unequip it, it set displayId to default displayId?
 
Last edited:

Tommy

Founder
And spent some time for research over again, i can not find function that catch event onquip -_-. But i have made this script :3

It's been said over and over again that there isn't any unless you make your own hook. That goes for un-equipping item hook as well. You have to make your own.
 
Status
Not open for further replies.
Top