Creature Stage Class menu

Shout-Out

User Tag List

Results 1 to 3 of 3
  1. #1
    jiggens's Avatar Private
    Reputation
    13
    Join Date
    Nov 2010
    Posts
    2
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creature Stage Class

    Another release.

    With this class, you'll be able to add stages to creatures, specific to players.
    For example you could write a gossip script and integrate this class with it.
    You can update creatures' stages after an event e.g: killed something, talked to some other npc.., development in own gossip; use your creativity.
    The stages are saved in the database, so if a player develops in a npcs stage it stays, whether the server crashes or restarts.
    This makes it possible for npcs to react differently on players.

    - CreatureStage.cpp:
    Code:
    #include "CreatureStage.h"
    #include "StdAfx.h"
    
    void CreatureStage::UpdateStage(uint32 value, uint32 entry, uint32 guid)
    {	
    	if(entry && guid)
    	{
    		std::stringstream ss;
    		ss << "UPDATE creature_phases SET phase = '" << value << "' WHERE entry = '" << entry << "' AND guid = '" << guid << "';";
    		WorldDatabase.Execute(ss.str().c_str());
    		list->second = value;
    	}
    }
    
    void CreatureStage::DeleteRow(uint32 entry, uint32 guid)
    {
    	if(entry && guid)
    	{
    		std::stringstream ss;
    		ss << "DELETE FROM creature_phases WHERE entry='" << entry << "' AND guid='" << guid << "';";
    		WorldDatabase.Execute(ss.str().c_str());
    		players.erase(list);
    	}
    }
    
    void CreatureStage::AddNewPlayer(uint32 entry, uint32 guid, uint32 phase)
    {
    	if(entry && guid)
    	{
    		std::stringstream ss;
    		ss << "INSERT INTO creature_phases (entry, guid, phase) VALUES ('" << entry << "' , " << guid << ", " << phase << ");";
    		WorldDatabase.Execute(ss.str().c_str());
    		players.insert(make_pair(guid, phase));
    	}
    }
    
    void CreatureStage::GetCreatureStages(uint32 entry)
    {
    	std::stringstream ss;
    	ss << "SELECT * FROM creature_phases WHERE entry='" << entry << "';";
    	QueryResult *result = WorldDatabase.Query(ss.str().c_str());
    	if(result)
    	{
    		do 
    		{
    			Field* field = result->Fetch();
    			uint32 low_guid = field[1].GetUInt32();
    			uint32 phase = field[2].GetUInt32();
    			players.insert(make_pair(low_guid, phase)); 
    		} while(result->NextRow());
    	}
    }
    
    bool CreatureStage::FindPlayer(uint32 guid)
    {
    	bool found = true;
    	list = players.find(guid);
    	if(list == players.end())
    		found = false;
    	return found;
    }
    
    uint32 CreatureStage::GetStage()
    {
    	uint32 phase = 0;
    	if(list != players.end())
    		phase = list->second;
    	return phase;
    }
    - CreatureStage.h:
    Code:
    #include "StdAfx.h"
    #pragma once
    
    class CreatureStage
    {
    public:
    	map<uint32, uint32> players;
    	map<uint32,uint32>::iterator list;
    
    	void UpdateStage(uint32 value, uint32 entry, uint32 guid);
    	void DeleteRow(uint32 entry, uint32 guid);
    	void AddNewPlayer(uint32 entry, uint32 guid, uint32 phase);
    	void GetCreatureStages(uint32 entry);
    	
    	bool FindPlayer(uint32 guid);
    	uint32 GetStage();
    
    };
    - CreatureStage.sql(execute on world database):
    Code:
    SET FOREIGN_KEY_CHECKS=0;
    -- ----------------------------
    -- Table structure for `creature_phases`
    -- ----------------------------
    DROP TABLE IF EXISTS `creature_phases`;
    CREATE TABLE `creature_phases` (
      `entry` int(11) NOT NULL,
      `guid` int(11) NOT NULL,
      `phase` int(11) NOT NULL,
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    -- ----------------------------
    -- Records of `creature_phases`
    -- ----------------------------
    - Example code:
    Code:
    class SERVER_DECL Example_Gossip : public GossipScript
    {
    public:
    	CreatureStage* Example;
    	void GossipHello(Object* object, Player* player, bool AutoSend)
        {
    		GossipMenu *Menu;
    		uint32 entry = object->GetEntry();
    		uint32 guid = player->GetLowGUID();
    		Example->GetCreatureStages(entry);
    
    		if(Example->FindPlayer(guid))
    		{
    			switch(Example->GetStage())
    			{
    				case 0: {
    					// Stage 1.
    				} break;
    				case 1: {
    					// Stage 2.
    				} break;
    				case 2: {
    					// stage 3.
    				} break;
    				// And go on..
    			}
    		}
    		else 
    		{
    			// Not staged yet.
    		}
    		Menu->SendTo(player);
    	};
    	
    	void GossipSelectOption(Object* object, Player* player, uint32 Id, uint32 IntId, const char * Code)
        {
    		GossipMenu *Menu;
    		uint32 stage = 0;
    		uint32 entry = object->GetEntry();
    		uint32 guid = player->GetLowGUID();
    
    		switch(IntId)
    		{
    			case 0: {
    				// IntId 0, put something here..
    			} break;
    			case 1: { 
    				// IntId 1, to end the gossip.
    				GossipEnd(object, player); 
    			} break;
    			case 2: 
    			{ 
    				// Well.. Let's add the player, if he isn't in the table yet..
    				if(!Example->FindPlayer(guid))
    				{
    					stage = 1;
    					Example->AddNewPlayer(entry, guid, stage);
    				}
    				GossipEnd(object, player);
    			} break;
    			case 3: 
    			{ 
    				// Well to show how to delete a player from his list ;)
    				if(Example->FindPlayer(guid))
    					Example->DeleteRow(entry, guid);
    
    				GossipHello(object, player, true);
    			} break;
    			case 4: 
    			{	
    				// Let's update the creatures' (- player) stage. :)
    				stage = 2;
    				{
    					if(Example->FindPlayer(guid))
    						Example->UpdateStage(stage, entry, guid);
    				}
    			} break;
    		}
    	};
    
    	void GossipEnd(Object * object, Player* player)
    	{
    		player->GetSession()->OutPacket(SMSG_GOSSIP_COMPLETE, 0, NULL);
    	}
    
    	void Destroy()
    	{
    		delete this;
    	};
    };
    Have fun.
    Last edited by jiggens; 11-08-2010 at 03:29 PM.

    Creature Stage Class
  2. #2
    striker9525's Avatar Private
    Reputation
    1
    Join Date
    Oct 2010
    Posts
    6
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very nice

  3. #3
    Link_S's Avatar Member
    Reputation
    125
    Join Date
    Dec 2008
    Posts
    293
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is actually a great idea, Nice work!
    Why do I need a signature?

Similar Threads

  1. What class do you play as?
    By janzi9 in forum Community Chat
    Replies: 28
    Last Post: 11-13-2006, 04:03 PM
  2. Whats your favorite class?
    By Bossman4 in forum World of Warcraft General
    Replies: 32
    Last Post: 11-07-2006, 09:48 AM
  3. Guide for your class in an instance!
    By Bossman4 in forum World of Warcraft Guides
    Replies: 5
    Last Post: 10-28-2006, 03:39 PM
  4. Full Guide for Dungeon Set 1 items (all classes)
    By Cush in forum World of Warcraft Guides
    Replies: 13
    Last Post: 09-07-2006, 03:07 PM
  5. priest own any class
    By bigbaz in forum World of Warcraft Exploits
    Replies: 4
    Last Post: 06-10-2006, 01:13 AM
All times are GMT -5. The time now is 10:29 AM. 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