[Trinity] Npc Selling Levels For Tokens menu

User Tag List

Results 1 to 1 of 1
  1. #1
    _Hkarta's Avatar Corporal
    Reputation
    46
    Join Date
    Apr 2010
    Posts
    20
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [Trinity] Npc Selling Levels For Tokens

    Hello there,

    I have written script recetly (on some otheracweborgsite :P) and i thought it'd be a good idea to release it there as well. Its not something special, in fact, it took me just like 30 minutes including time spent fixing some strange libmysql compile error that occoured after last merge, but it could be useful to some people.

    Basicaly it is a npc that sells levels.

    It works on player input, first it tells you (in popup box) how many levels you can request, than input box appears and if value is correct (not too high, and numeric) it takes you to next step, where it displays required amount of tokens and asks you if your willing to finish transaction. In case you are, and youv got all the tokens needed, npc gives you your levels and removes tokens.

    Pricing of levels is somewhat logical, lower levels are cheaper, and ofc, it doesnt count levels youv already gained. You can set price increase rate in the script. With default settings, level 2 should cost 1 or two tokens - but going all the way from 1 to 80 is worth something close to 2000 tokens. If you are level 75 and want to buy last 5 levels, however, it will cost only something like 500 tokens, because you have already gained 75 levels yourself.

    Its got various protections in place to prevent exploiting. All you need is to register the script to scriptloader and create npc with gossip npcflag (1) and assign him npc_level_vendor scriptname.

    Hope you will enjoy, dont hesitate to post your feedback.

    Code:
    #include "ScriptPCH.h"
    #include <cstring>
    
    enum eEnums
    {
    	OFFSET_LEVELS				= 10,
        MAXIMAL_LEVEL				= 80,
    	TOKEN_ID					= 52021,
    	TOKENS_PER_LEVEL_1			= 1,
    	INCREASE_RATE_PERCENTUAL    = 110
    };
    
    
    class npc_level_vendor : public CreatureScript
    {
        public:
    
            npc_level_vendor()
                : CreatureScript("npc_level_vendor")
            {
            }
    
            bool OnGossipHello(Player* player, Creature* creature)
            {
    			MainMenu(player, creature);
                return true;
            }
    
    		int GetMaximum(Player *player)
    		{
    			return MAXIMAL_LEVEL - player->getLevel();
    		}
    
    		bool IsNumeric(std::string str)
    		{
    		   for (int i = 0; i < str.length(); i++) {
    			   if (!std::iswdigit(str[i]))
    				   return false;
    		   }
    
    		   return true;
    		}
    
    		std::string JoinStIn(std::string st, int in)
    		{
    			std::stringstream sstm;
    			sstm << st << in;
    			return sstm.str();
    		}
    
    		int StringToInt(std::string str)
    		{
    			if(IsNumeric(str))
    			{
    				int result;
    				std::stringstream sstm(str);
    				sstm >> result;
    				return result;
    			}
    			else
    				return -1;
    		}
    
    		float GetPriceForLevel(int level)
    		{
    			float price = TOKENS_PER_LEVEL_1;
    			for(int x = 0; x < level; x++)
    			{
    				price = price * ((float)INCREASE_RATE_PERCENTUAL / (float)100);
    			}
    			return price;
    		}
    
    		void MainMenu(Player *player, Creature *creature)
    		{
    			std::string message = JoinStIn("Please enter amount of levels you would like to get. Maximal value you can enter is ", GetMaximum(player)) + ".";
    			if(player->getLevel() < MAXIMAL_LEVEL)
    				player->ADD_GOSSIP_ITEM_EXTENDED(0, "I'd like to purchase level or two :-)", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+3, 
    				message, 0, true);
    			player->ADD_GOSSIP_ITEM(0, "Not interested", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1);
    			
    			player->PlayerTalkClass->SendGossipMenu(907, creature->GetGUID());
    		}
    
    		bool OnGossipSelectCode(Player* player, Creature* creature, uint32 uiSender, uint32 uiAction, const char* code)
            {
                player->PlayerTalkClass->ClearMenus();
                if (uiSender == GOSSIP_SENDER_MAIN)
                {
                    if (uiAction == GOSSIP_ACTION_INFO_DEF+3)
    				{
    					int reqIncrease = StringToInt(code);
    					if(reqIncrease != -1 && player->getLevel() + reqIncrease < MAXIMAL_LEVEL + 1)
    					{
    						float toPay = GetPriceForLevel(player->getLevel() + reqIncrease) - GetPriceForLevel(player->getLevel());
    						std::string message = JoinStIn("Buy ", reqIncrease) + JoinStIn(" for ", (int)toPay) + " tokens.";
    
    						player->ADD_GOSSIP_ITEM(0, message, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+OFFSET_LEVELS+reqIncrease);
    						player->ADD_GOSSIP_ITEM(0, "Thats too much!", GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);
    
    						player->PlayerTalkClass->SendGossipMenu(907, creature->GetGUID());
    
    					
    					}
    					else // not numeric value, or invalid
    						MainMenu(player, creature);	
    				}
                }
    
                return false;
            }
    
            bool OnGossipSelect(Player* player, Creature* creature, uint32, uint32 uiAction)
            {
    			player->PlayerTalkClass->ClearMenus();
                if (uiAction == GOSSIP_ACTION_INFO_DEF+1)
                {
    					player->CLOSE_GOSSIP_MENU();
    			}
    			else if (uiAction == GOSSIP_ACTION_INFO_DEF+2)
                {
    					MainMenu(player, creature);
    			}
    			else if (uiAction > GOSSIP_ACTION_INFO_DEF+OFFSET_LEVELS)
    			{
    				int reqIncrease = uiAction - GOSSIP_ACTION_INFO_DEF - OFFSET_LEVELS;
    				if(reqIncrease != -1 && player->getLevel() + reqIncrease < MAXIMAL_LEVEL + 1)
    				{
    					float toPay = GetPriceForLevel(player->getLevel() + reqIncrease) - GetPriceForLevel(player->getLevel());
    					if(player->HasItemCount(TOKEN_ID, (int)toPay))
    					{
    						player->DestroyItemCount(TOKEN_ID, (int)toPay, true);
    						player->GiveLevel(player->getLevel() + reqIncrease);
    						player->SaveToDB();
    						player->CLOSE_GOSSIP_MENU();
    					}
    					else
    						MainMenu(player, creature); // not enough tokens
    				}
    				else
    					MainMenu(player, creature); // player leveled up before clicking on buy
    			}
    
    			return true;
    		}
    };
    
    void AddSC_npc_level_vendor()
    {
        new npc_level_vendor();
    }

    [Trinity] Npc Selling Levels For Tokens

Similar Threads

  1. [Selling] selling level 25 guild(eu server) for gold
    By frawrs in forum World of Warcraft Buy Sell Trade
    Replies: 0
    Last Post: 09-24-2012, 05:47 PM
  2. [Selling] Selling Level 82 Human Mage for gold
    By Crazier in forum WoW-US Account Buy Sell Trade
    Replies: 0
    Last Post: 09-23-2012, 11:11 PM
  3. [Selling] Selling Diablo 3 Power Leveling for very cheap
    By IIDecpetII in forum Diablo 3 Buy Sell Trade
    Replies: 2
    Last Post: 06-08-2012, 11:39 PM
  4. [Selling] Selling Level 25 Guild on the biggest server for PVP/PVE [Blackrock]
    By m4gicman in forum World of Warcraft Buy Sell Trade
    Replies: 3
    Last Post: 10-10-2011, 02:02 PM
  5. Selling level 80 DK for 250
    By Free Hugs in forum Members Only Accounts And CD Keys Buy Sell
    Replies: 1
    Last Post: 12-04-2008, 04:35 AM
All times are GMT -5. The time now is 02:12 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search