• 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] storage players

Status
Not open for further replies.

Xele

Enthusiast
hello,
i'm working on a script that's do something like these,

.ticketoff <playername> this don't let player to makes new ticket,
.ticketon <playername> this makes player to be able make a new ticket,

i'm looking for a way to storage players,thats my problem i cant storage players list...
 

Tommy

Founder
So basically you want to make a command that turns off and on the ticket system for players, right? You also want to store the players that this is being done to, correct?

This shouldn't be too hard to do. I whipped something up here. First, some small information. Surprisingly enough it would probably be quicker to add a string variable to tell that, that instance of the player ticket creation is off/on. However, I'll do this without altering the Player's source.

Put this anywhere (except in a class) in TicketMgr.h:

Code:
static std::map<std::string, std::string> ToggleTicketMap;

Put this in cs_ticket.cpp: (Change SEC_ADMINISTRATOR to your custom RBAC command permission)

Code:
{ "toggle",        SEC_ADMINISTRATOR,                            true, &HandleToggleTicketCommand,              "", NULL },

Put this in cs_ticket.cpp where the rest of the functions are:

Code:
    static bool HandleToggleTicketCommand(ChatHandler* handler, const char* args)
    {
        if (!*args)
            return false;

        Player* player = sObjectAccessor->FindPlayerByName(args);
        if (!player)
        {
            handler->PSendSysMessage("Player %s not found", args);
            return false;
        }

        std::map<std::string, std::string>::iterator itr = ToggleTicketMap.find(args);
        if (itr != ToggleTicketMap.end())
        {
            if (itr->second == "off")
            {
                itr->second = "on";
                handler->PSendSysMessage("Turned create ticket on for %s", args);
            }
            else
            {
                itr->second = "off";
                handler->PSendSysMessage("Turned create ticket off for %s", args);
            }
        }
        else
            ToggleTicketMap[args] = "on";

        return true;
    }

I haven't tested this, thought you might want to give it a try.
 

Xele

Enthusiast
no, i dont want do that,that was an example but my job is same as ticket turn off/on,
i think ur script is useful for trying...
 

Tommy

Founder
Well, I'm not following. It would be helpful if you pasted your script since you said you're working on one..
 

Xele

Enthusiast
well,this is my script

Code:
class Filtering : public PlayerScript
{
    public:
        Filtering() : PlayerScript("Filtering") { }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void CheckMessage(Player* player, uint32 type, uint32 lang, std::string& msg)
        {
            if (lang == LANG_ADDON || type == CHAT_MSG_ADDON)
                return;

            // Here I Want Check if player isnt on list, then return

            std::string Message = "|cff66ff00[CHAT]|r [";
            Message += player->GetName();
            Message += "]: |cfffaeb00";
            Message += msg;

            SessionMap Sessions = sWorld->GetAllSessions();
            for (SessionMap::iterator itr = Sessions.begin(); itr != Sessions.end(); ++itr)
                if (Player* plr = itr->second->GetPlayer())
                    if (plr->GetReceiveMessage(SEE_CHAT) == true)
                    {
                        WorldPacket data(SMSG_SERVER_MESSAGE, 50);
                        data << uint32(3);
                        data << Message;
                        plr->GetSession()->SendPacket(&data);
                    }
        }
};
 

Xele

Enthusiast
My Result ... this will works?
i will change toggle in another script, like as u post

Code:
class Filtering : public PlayerScript
{
    public:
        Filtering() : PlayerScript("Filtering") { }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Player*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Group*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Guild*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void OnChat(Player* player, uint32 type, uint32 lang, std::string& msg, Channel*)
        {
            CheckMessage(player, type, lang, msg);
        }

        void CheckMessage(Player* player, uint32 type, uint32 lang, std::string& msg)
        {
            if (lang == LANG_ADDON || type == CHAT_MSG_ADDON)
                return;

            uint64 PGUID = player->GetGUID();

            if (ToggleChat[PGUID].Toggle == true)
            {
                std::string Message = "|cff66ff00[CHAT]|r [";
                Message += player->GetName();
                Message += "]: |cfffaeb00";
                Message += msg;

                SessionMap Sessions = sWorld->GetAllSessions();
                for (SessionMap::iterator itr = Sessions.begin(); itr != Sessions.end(); ++itr)
                    if (Player* plr = itr->second->GetPlayer())
                        if (plr->GetReceiveMessage(SEE_CHAT) == true)
                        {
                            WorldPacket data(SMSG_SERVER_MESSAGE, 50);
                            data << uint32(3);
                            data << Message;
                            plr->GetSession()->SendPacket(&data);
                        }
            }

            struct PInfo
            {
                bool Toggle = false;
            };

            static std::map<uint64, PInfo> ToggleChat;
        }
};
 

Jameyboor

Retired Staff
You don't need a struct for your container if there's only going to be 1 member in the struct, use this instead:
Code:
static std::unordered_map<uint64, bool> ToggleChat;
 
Status
Not open for further replies.
Top