• 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] help with Vote Point

Status
Not open for further replies.

Diegito20

Member
hello,guys i have a little problem i want to show, vp, and dp at the same time
with same command without separated commands
i mean if i use .coin i want to see my vp, and dp at the same time
i tried to modify it but i cant the script is made by tommy here is the script

Code:
/*

// Create our map that will hold necessary data for all players
std::unordered_map<uint32, uint32> VoteMap;

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

    void OnStartup() override
    {
        // Give our updateTimer a value of every 5 minutes. Don't want it to be super low.
        updateTimer = 5 * MINUTE * IN_MILLISECONDS;
        // Here we're going to load all the data into our map 'VoteMap'
        // Selects accountId (id) and vp from the account table
        QueryResult result = LoginDatabase.PQuery("SELECT id, vp, dp FROM account");
        if (result)
        {
            do
            {
                Field* field = result->Fetch();
                uint32 accountId = field[0].GetUInt32();
                uint32 vp = field[1].GetUInt32();
				uint32 dp = field[2].GetUInt32();

                // Fill our map
				VoteMap[accountId] = vp, dp;

            } while (result->NextRow());
        }
    }

    void OnUpdate(uint32 diff) override
    {
        // Reload vp for all players every 5 minutes
        if (updateTimer <= diff)
        {
            VoteMap.clear();
            QueryResult result = LoginDatabase.PQuery("SELECT id, vp, dp FROM account");
            if (result)
            {
                do
                {
                Field* field = result->Fetch();
                uint32 accountId = field[0].GetUInt32();
                uint32 vp = field[1].GetUInt32();
				uint32 dp = field[2].GetUInt32();

                // Fill our map
				VoteMap[accountId] = vp, dp;

                } while (result->NextRow());
            }
            updateTimer = 5 * MINUTE * IN_MILLISECONDS;
        }
        else
            updateTimer -= diff;
    }

private:
    uint32 updateTimer;
};

class cmd_vote_points : public CommandScript
{
public:
    cmd_vote_points() : CommandScript("cmd_vote_points") { }

    std::vector<ChatCommand> GetCommands() const override
    {
        static std::vector<ChatCommand> pointCommandTable =
        {
            { "VP", SEC_PLAYER, false, &HandleGetPointsCommand, "" },
        };

        return pointCommandTable;
    }

    static bool HandleGetPointsCommand(ChatHandler* handler, char const* args)
    {
        Player* player = handler->GetSession()->GetPlayer();
        // Find player's data in 'VoteMap' by searching for accountId
        // Remember: first (accountId), second (vp)
        std::unordered_map<uint32, uint32>::iterator itr = VoteMap.find(player->GetSession()->GetAccountId());
        if (itr != VoteMap.begin())
		    ChatHandler(player->GetSession()).PSendSysMessage(78231, itr->second);
		if (itr != VoteMap.end())
		    ChatHandler(player->GetSession()).PSendSysMessage(78230, itr->second);
        return true;
    }
};
 
Last edited:

slp13at420

Mad Scientist
you just want to change the command from '.VP' to '.coin' ?

Change the command in red:
Code:
[COLOR="#808080"]
        static std::vector<ChatCommand> pointCommandTable =
        {
           [COLOR="#DAA520"] { "[COLOR="#FF0000"]VP[/COLOR]", SEC_PLAYER, false, &HandleGetPointsCommand, "" },[/COLOR]
        };
[/COLOR]

to the new command in green:
Code:
[COLOR="#808080"]
        static std::vector<ChatCommand> pointCommandTable =
        {
           [COLOR="#DAA520"] { "[COLOR="#008000"]coin[/COLOR]", SEC_PLAYER, false, &HandleGetPointsCommand, "" },[/COLOR]
        };
[/COLOR]
 
Last edited:

Diegito20

Member
thanks, for reply but no, i want to show vp and dp but only show me vp in both texts
if (itr != VoteMap.begin())
ChatHandler(player->GetSession()).PSendSysMessage(vp text, itr->second);
if (itr != VoteMap.end())
ChatHandler(player->GetSession()).PSendSysMessage(dp text, itr->second);

the original script only has vp
i modifed it with vp and dp but not work
maybe is for this VoteMap[accountId] = vp, dp; Or what I put up
 
Last edited:

slp13at420

Mad Scientist
k dunno why you would want to post the players `vp` twice...

first thing i see is this only Queries the account's `id` and `dp` from the sql server for storage in the `DonorMap` array/map.

so first we would need to also add a 3 request to both of the Queries:

Code:
        QueryResult result = LoginDatabase.PQuery("SELECT id, dp FROM account");

To:
Code:
        QueryResult result = LoginDatabase.PQuery("SELECT id, dp, vp FROM account");


Then we need to modify our table to support sub-addresses:
Code:
// Create our map that will hold necessary data for all players
std::unordered_map<uint32, uint32> DonorMap;

to:
Code:
// Create our map that will hold necessary data for all players
struct DonorElements
{
     uint32 dp;
     uint32 vp;
};
std::unordered_map<uint32, DonorElements>DonorMap;

Now we have 2 slots addressed to store our data.(dp and vp)


Next we need to unpack and transfer the Query data to the proper address:
Code:
        if (result)
        {
            do
            {
                Field* field = result->Fetch();
                uint32 accountId = field[0].GetUInt32();
                uint32 dp = field[1].GetUInt32();

                // Fill our map
                DonorMap[accountId] = dp;

            } while (result->NextRow());
        }


Code:
        if (result)
        {
            do
            {
                Field* field = result->Fetch();
                uint32 accountId = field[0].GetUInt32();
                uint32 dp = field[1].GetUInt32();
                uint32 vp = field[2].GetUInt32();

                // Fill our map
                DonorElements& data = DonorMap[accountId];
		data.dp = dp;
		data.v = vp;

            } while (result->NextRow());
        }

now we have updated the table and both (2) queries,.
Now we just have to update the output-post to player:
Code:
        Player* player = handler->GetSession()->GetPlayer();
        // Find player's data in 'DonorMap' by searching for accountId
        // Remember: first (accountId), second (dp)
        std::unordered_map<uint32, uint32>::iterator itr = DonorMap.find(player->GetSession()->GetAccountId());
        if (itr != DonorMap.end())
            ChatHandler(player->GetSession()).PSendSysMessage(78230, itr->second);
        return true;

To:
Code:
        Player* player = handler->GetSession()->GetPlayer();
        uint32 accountId = player->GetSession()->GetAccountId();

        if (DonorMap[accountId])
            ChatHandler(player->GetSession()).PSendSysMessage("Vote Points:%u Donation Points:%u", DonorMap[accountId].vp, DonorMap[accountId].dp);
        return true;
 
Status
Not open for further replies.
Top