Jump to content
Search In
  • More options...
Find results that contain...
Find results in...



#0
Guest

User Menu


Sign In

Sign In



Sign Up

Forum Menu


Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!

Sign in to follow this  
Jimteck

Donor NPC (C++) (C2259)

Recommended Posts

T
O
P
I
C

S
T
A
R
T
E
R
#include "ScriptPCH.h"
#include <sstream>
#include <string>
#include <vector>

std::string getString(std::string string, uint32 number);
std::string getDPString(std::string string, uint32 number, uint8 quality);
uint32 getDPFromID(uint32 item_id);

bool canRun = true;

class dp_items
{
public:
	dp_items()	{}
	dp_items(uint32 item_id, uint8 item_type, std::string item_name, uint8 quality, uint32 dp_cost)
	{
		this->item_id = item_id;
		this->dp_cost = dp_cost;
		this->quality = quality;
		this->item_type = item_type;
		this->item_name = item_name;
	}
	inline uint32	getItemID()		{ return item_id; }
	inline uint32	getDPCost()		{ return dp_cost; }
	inline uint8	getQuality()	{ return quality; }
	inline uint8	getItemType()	{ return item_type; }
	inline std::string getName()	{ return item_name; }

private:
	uint32 item_id, dp_cost;
	uint8 quality, item_type;
	std::string item_name;
};

std::vector<dp_items> items;

class load_dp : public WorldScript
{
public:
	load_dp() : WorldScript("load_dp") {}

	void OnStartup() {
		QueryResult loadQuery = WorldDatabase.Query(loadStmnt.c_str());
		Field *fields = loadQuery->Fetch();
		if (fields) {
			do
			{
				dp_items item = dp_items(fields[0].GetUInt32(), fields[1].GetUInt8(), fields[2].GetString(), fields[3].GetUInt8(), fields[4].GetUInt32());
				items.push_back(item);
			} while (loadQuery->NextRow());
			TC_LOG_INFO("server.loading", "DP Items Loaded Successfully.");
		}
		else
		{
			canRun = false;
		}
		QueryResult testQuery = LoginDatabase.Query("SELECT * from account LIMIT 1;");
		if (testQuery->GetFieldCount() < 25)
		{
			TC_LOG_INFO("server.loading", "ERROR: Missing dp_balance column.");
			canRun = false;
		}
		else
		{
			TC_LOG_INFO("server.loading", "DP System Loaded Successfully.");
		}		
	}

private:
	std::string loadStmnt = "SELECT * from dp_items;";

};

class gossip_dp : public CreatureScript {
public:
	gossip_dp() : CreatureScript("gossip_dp") { }

	uint32 getDP(Player* player)
	{
		QueryResult dQuery = LoginDatabase.Query(getString(dpQuery, player->GetSession()->GetAccountId()).c_str());
		Field *field = dQuery->Fetch();
		return field[0].GetUInt32();
	}

	bool OnGossipHello(Player* player, Creature* creature) 
	{
		if (canRun)
		{
			if (player->IsInCombat())
			{
				player->GetSession()->SendAreaTriggerMessage("Вы в бою");
				return false;
			}

			AddGossipItemFor(player,GOSSIP_ICON_MONEY_BAG, getString(currentDP, getDP(player)).c_str(), GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1);
			AddGossipItemFor(player,GOSSIP_ICON_VENDOR, "|TInterface/ICONS/Inv_chest_cloth_71:30|t |cffB22222Предпросмотр вещей", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 7);
			AddGossipItemFor(player,GOSSIP_ICON_BATTLE, "|TInterface/ICONS/Inv_weapon_halberd_31:30|t |cffB22222Оружие  за пожертвование", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2);
			AddGossipItemFor(player,GOSSIP_ICON_VENDOR, "|TInterface/ICONS/Inv_chest_cloth_61:30|t |cffB22222Экипировка за пожертвование", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 3);
			AddGossipItemFor(player,GOSSIP_ICON_VENDOR, "|TInterface/ICONS/Inv_misc_armorkit_12:30|t |cffB22222Разные  мелкие  штучки за пожертвование", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 4);
			AddGossipItemFor(player,GOSSIP_ICON_TRAINER, "|TInterface/ICONS/Spell_shaman_ancestralawakening:30|t |cffB22222Спелы  за пожертвования", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 5);
			AddGossipItemFor(player,GOSSIP_ICON_CHAT, "|TInterface/ICONS/Spell_misc_emotionsad:30|t |cff0000CDНичего  не  хочу", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 6);
			SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
			return true;
		}
		else
		{
			return false;
		}

	}

	bool OnGossipSelect(Player* player, Creature* creature, uint32 sender, uint32 actions)
	{
		player->PlayerTalkClass->ClearMenus();
		if (sender == GOSSIP_SENDER_MAIN) {
			switch (actions)
			{
			case GOSSIP_ACTION_INFO_DEF + 1:
				creature->Whisper(getString(currentDP, getDP(player)), LANG_UNIVERSAL, player, false);
				player->PlayerTalkClass->SendCloseGossip();
				break;
			case GOSSIP_ACTION_INFO_DEF + 2:
				for (unsigned int i = 0; i < items.size(); i++){
					if (items.at(i).getItemType() == 1)
						AddGossipItemFor(player,GOSSIP_ICON_BATTLE, getDPString(items.at(i).getName(), items.at(i).getDPCost(), items.at(i).getQuality()).c_str(), GOSSIP_SENDER_MAIN+1, items.at(i).getItemID());
				}
				AddGossipItemFor(player, GOSSIP_ICON_CHAT, "|TInterface/ICONS/Spell_misc_emotionsad:30|t |cff0000CDНазад", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
				SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
					\
				break;
			case GOSSIP_ACTION_INFO_DEF + 3:
				for (unsigned int i = 0; i < items.size(); i++) {
					if (items.at(i).getItemType() == 2)
						AddGossipItemFor(player, GOSSIP_ICON_TABARD, getDPString(items.at(i).getName(), items.at(i).getDPCost(), items.at(i).getQuality()).c_str(), GOSSIP_SENDER_MAIN+1, items.at(i).getItemID());
				}
				AddGossipItemFor(player, GOSSIP_ICON_CHAT, "|TInterface/ICONS/Spell_misc_emotionsad:30|t |cff0000CDНазад", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
				SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
				break;
			case GOSSIP_ACTION_INFO_DEF + 4:
				for (unsigned int i = 0; i < items.size(); i++){
					if (items.at(i).getItemType() == 3)
						AddGossipItemFor(player, GOSSIP_ICON_VENDOR, getDPString(items.at(i).getName(), items.at(i).getDPCost(), items.at(i).getQuality()).c_str(), GOSSIP_SENDER_MAIN+1, items.at(i).getItemID());
				}
				AddGossipItemFor(player, GOSSIP_ICON_CHAT, "|TInterface/ICONS/Spell_misc_emotionsad:30|t |cff0000CDНазад", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
				SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
				break;
			case GOSSIP_ACTION_INFO_DEF + 5:
				for (unsigned int i = 0; i < items.size(); i++){
					if (items.at(i).getItemType() == 4)
						AddGossipItemFor(player, GOSSIP_ICON_TRAINER, getDPString(items.at(i).getName(), items.at(i).getDPCost(), items.at(i).getQuality()).c_str(), GOSSIP_SENDER_MAIN+2, items.at(i).getItemID());
				}
				AddGossipItemFor(player, GOSSIP_ICON_CHAT, "|TInterface/ICONS/Spell_misc_emotionsad:30|t |cff0000CDНазад", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 8);
				SendGossipMenuFor(player, DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
				break;
			case GOSSIP_ACTION_INFO_DEF + 6:
				player->PlayerTalkClass->SendCloseGossip();
				break;
			case GOSSIP_ACTION_INFO_DEF + 7:
				player->PlayerTalkClass->SendCloseGossip();
				SendListInventory(player, creature);
				break;
			case GOSSIP_ACTION_INFO_DEF + 8:
				player->PlayerTalkClass->ClearMenus();
				OnGossipHello(player, creature);
				break;
			}
		}
		else if (sender == GOSSIP_SENDER_MAIN + 1)
		{
			uint32 dpCost = getDPFromID(actions);
			uint32 dpBAL = getDP(player);
			if (dpCost <= dpBAL)
			{
				if (player->AddItem(actions, 1)) {
					LoginDatabase.PExecute(accountQuery.c_str(), (dpBAL - dpCost), player->GetSession()->GetAccountId());
					LoginDatabase.PExecute(accountdataQuery.c_str(), (dpBAL - dpCost), player->GetSession()->GetAccountId());
					player->GetSession()->SendNotification("Поздравляю вас с новой покупкой!");
				}
				else
				{
					player->GetSession()->SendNotification("ОШИБКА - ваши сумки полны.");
				}
			}
			else
			{
				creature->Whisper(notEnoughDP, LANG_UNIVERSAL, player, false);
				player->GetSession()->SendNotification("ОШИБКА - у вас  нет монет  пожертвований.");
			}
			player->PlayerTalkClass->SendCloseGossip();
		}
		else if (sender == GOSSIP_SENDER_MAIN + 2)
		{
			uint32 dpCost = getDPFromID(actions);
			uint32 dpBAL = getDP(player);
			if (dpCost <= dpBAL)
			{
				if (!player->HasSpell(actions)){
					player->LearnSpell(actions, false, false);
					LoginDatabase.PExecute(accountQuery.c_str(), (dpBAL - dpCost), player->GetSession()->GetAccountId());
					LoginDatabase.PExecute(accountdataQuery.c_str(), (dpBAL - dpCost), player->GetSession()->GetAccountId());
					player->GetSession()->SendNotification("Поздравляю вас с новой покупкой.");

				}
				else
				{
					player->GetSession()->SendNotification("ОШИБКА - вы уже знаете  это заклинание.");
				}
			}
			else
			{
				creature->Whisper(notEnoughDP, LANG_UNIVERSAL, player, false);
				player->GetSession()->SendNotification("ОШИБКА - у вас нет  монет пожертвований.");
			}
			player->PlayerTalkClass->SendCloseGossip();
		}

		return true;
	}

	// Do NOT modify anything in SendListInventory, may break previewing or allow players to buy items
	void SendListInventory(Player *player, Creature *creature) 
	{
		// remove fake death
		if (player->HasUnitState(UNIT_STATE_DIED))
			player->RemoveAurasByType(SPELL_AURA_FEIGN_DEATH);
		if (creature->HasUnitState(UNIT_STATE_MOVING))
			creature->StopMoving();

		VendorItemData *vItems = new VendorItemData();
		for (uint32 i = 0; i < items.size(); i++) // Allows us to create a vendor window on the fly.
		{
			if (items.at(i).getItemType() != 4) // If the item is not a spell, lets put it in the vendor.
				vItems->AddItem(items.at(i).getItemID(), 0, 0, 59475);
		}
		if (!vItems)
		{
			WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + 1);
			data << uint64(creature->GetGUID());
			data << uint8(0);                                   // count == 0, next will be error code
			data << uint8(0);                                   // "Vendor has no inventory"
			player->GetSession()->SendPacket(&data);
			return;
		}
		uint8 itemCount = vItems->GetItemCount();
		uint8 count = 0;
		WorldPacket data(SMSG_LIST_INVENTORY, 8 + 1 + itemCount * 8 * 4);
		data << uint64(creature->GetGUID());
		size_t countPos = data.wpos();
		data << uint8(count);

		float discountMod = player->GetReputationPriceDiscount(creature);
		for (uint8 slot = 0; slot < itemCount; ++slot)
		{
			if (VendorItem const* item = vItems->GetItem(slot))
			{
				if (ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item->item))
				{
					if (!(itemTemplate->AllowableClass & player->getClassMask()) && itemTemplate->Bonding == BIND_WHEN_PICKED_UP && !player->IsGameMaster())
						continue;
					// Only display items in vendor lists for the team the
					// player is on. If GM on, display all items.
					if (!player->IsGameMaster() && ((itemTemplate->Flags2 & ITEM_FLAG2_FACTION_HORDE && player->GetTeam() == ALLIANCE) || (itemTemplate->Flags2 == ITEM_FLAG2_FACTION_ALLIANCE && player->GetTeam() == HORDE)))
						continue;


					// reputation discount
					int32 price = item->IsGoldRequired(itemTemplate) ? uint32(floor(itemTemplate->BuyPrice * discountMod)) : 0;

					data << uint32(slot + 1);       // client expects counting to start at 1
					data << uint32(item->item);
					data << uint32(itemTemplate->DisplayInfoID);
					data << int32(0);
					data << uint32(price);
					data << uint32(itemTemplate->MaxDurability);
					data << uint32(itemTemplate->BuyCount);
					data << uint32(item->ExtendedCost);

					if (++count >= MAX_VENDOR_ITEMS)
						break;
				}
			}
		}

		if (count == 0)
		{
			data << uint8(0);
			player->GetSession()->SendPacket(&data);
			return;
		}

		data.put<uint8>(countPos, count);
		player->GetSession()->SendPacket(&data);
		
	}
private:
	//Do not edit the Queries/constants below, they're set up 100%.
	std::string accountQuery = "UPDATE account SET dp_balance = %u WHERE id = %u;";
	std::string accountdataQuery = "UPDATE account_data SET dp = %u WHERE id = %u;";
	std::string currentDP = "|TInterface/ICONS/Inv_misc_coin_02:30|t |cffB22222На вашем счету: ";
	std::string notEnoughDP = "У вас нет монет пожертвований,зайдите на сайт или свяжитесь с администрацией сервера.";
	std::string dpQuery = "SELECT dp_balance FROM account WHERE id=";
};

//Do NOT modify any of the below functions unless you are sure you know what you're doing.
uint32 getDPFromID(uint32 item_id)
{
	//Not the most efficient loop. Let me know if you are using a large amount of items/spells
	//and I can implement a more efficient search.
	uint32 dpCost = 99999;
	for (unsigned int i = 0; i < items.size(); i++)
		if (item_id == items.at(i).getItemID())
			dpCost = items.at(i).getDPCost();
	return dpCost;
}
std::string getString(std::string string, uint32 number)
{
	std::ostringstream oss;
	oss << string << number;
	return oss.str();
}
std::string getDPString(std::string string, uint32 number, uint8 quality)
{

	//Colors currently disabled.
	/*std::string color;
	switch (quality)
	{
	case 0:
		color = "|cff9d9d9d";
		break;
	case 1:
		color = "|cffffffff";
		break;
	case 2:
		color = "|cff47b247";
		break;
	case 3:
		color = "|cff00003d";
		break;
	case 5:
		color = "|cff331f00";
		break;
	default:
		color = "|cff3d003d";
		break;
	}*/
	std::ostringstream oss;
	//oss << color << string << " - (" << number << "DP)"; //With Color
	oss << string << " - (" << number << "Монет пожертвований)"; //Without color
	return oss.str();
}


void AddSC_DPSystem()
{
	new load_dp();
	new gossip_dp(); <---class' : cannot instantiate abstract class
                     Code declares an instance of an abstract class or structure.
                     You cannot instantiate a class or structure with one or more pure virtual functions. To instantiate objects of a derived class, the                          derived class must override each pure virtual function.
}

 

Edited by Jimteck

Share this post


Link to post
Share on other sites
T
O
P
I
C

S
T
A
R
T
E
R
5 minutes ago, Valtorei said:

@Jimteck, are you asking for help, or is this a release?

I ask for help fix this error

Share this post


Link to post
Share on other sites

Okay, I'm going to move this to the support section. In the mean time, please clarify what your error is. All you're showing us is a script.

Share this post


Link to post
Share on other sites
T
O
P
I
C

S
T
A
R
T
E
R
4 minutes ago, Valtorei said:

Okay, I'm going to move this to the support section. In the mean time, please clarify what your error is. All you're showing us is a script.

 

I added this script to the custom script, (trinity last revision) 05/05/2017, and here are the errors C2259,and thats all.

http://piccy.info/view3/11158193/ca3f6e1909cf093ac8b8e67c47fc780f/1200/

Share this post


Link to post
Share on other sites

This script seems old/outdated and would need to be updated to work with the latest core (eg #include "ScriptPCH.h").

try replacing

#include "ScriptPCH.h"

with 

#include "ScriptMgr.h"
#include "ScriptedGossip.h"
#include "Player.h"

I'm not at my main computer atm so I am unable to test; so guessing this will cover all you need. Also you may need to update additional code since this is outdated.

 

~hope this helps

Share this post


Link to post
Share on other sites
9 hours ago, Core said:

With the lastest revision of trinitycore, I guess some changes were made somewhere that I can't find. but  when compiling this you get an error

http://prntscr.com/f7ubfl

http://prntscr.com/f7v34u

You are getting errors while on compile.  I have taken a look at the images provided and the errors seem to be from other scripts

http://prntscr.com/f7ubfl    - The error from this one when looking at the images says that it is regards to npc arena spectate 

http://prntscr.com/f7v34u   - The error from this one from the image is showing from buy transmog

If you need help with these scripts then I would suggest making a support thread with the  spectate script and the buy transmog script

Share this post


Link to post
Share on other sites
5 hours ago, DPCoder said:

You are getting errors while on compile.  I have taken a look at the images provided and the errors seem to be from other scripts

http://prntscr.com/f7ubfl    - The error from this one when looking at the images says that it is regards to npc arena spectate 

http://prntscr.com/f7v34u   - The error from this one from the image is showing from buy transmog

If you need help with these scripts then I would suggest making a support thread with the  spectate script and the buy transmog script

Yes I know they are from different scripts, but it's the same error as the OP. With the same exact CreatureScript, the solution to his problem will more than likely be the solution to mine.

Share this post


Link to post
Share on other sites

@Jimteck, were you able to resolve your issue?

 

@Core, please don't hijack other user's requests for support. While your issue may be similar, it is not identical. If you are unable to resolve your issue by the suggestions above; please open a new support request with your specific issue.

 

 

Share this post


Link to post
Share on other sites

This ticket is now marked inactive as the ticket author has not made a reply within the 72 hour timeframe.

If you're the author and still need assistance please create a new ticket.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

About Us

MMO-Society is the Forum former known as Lordcraft, MMO-Society offers various of Resources to help you evolve your knowledge within Emulation, In the process we make sure to form a strong community bond in-between each other and thus we are proud to can admit that MMO-Society is possibly the friendliest Community Forum to currently exist.

All trademarks referenced are the properties of their respective owners.
©2018 MMO-Society. All rights reserved.

Social Links

Discord Server Join
Twitter Follow us
×
×
  • Create New...