Hello & Welcome to our community. Is this your first visit? Register
Follow us on
Follow us on Facebook Follow us on Twitter Watch us on YouTube


MMOCoin

Likes Likes:  0
Results 1 to 3 of 3
  1. #1
    Contributor
    Cocain's Avatar
    Join Date
    Mar 2010
    Posts
    208
    Post Thanks / Like
    Rep Power
    16
    Reputation
    92

    Exclamation [C++]ArcEmu voting system.


    Register to remove this ad
    A small voting system, which you can use ingame.




    Code:
    #include "StdAfx.h"
    #define SKIP_ALLOCATOR_SHARING 1
    #include <ScriptSetup.h>
    
    void SetupVoteBallot(ScriptMgr * mgr);
    void SendVoteBallotToAll();
    void EndVote();
    
    enum VOTES
    {
        VOTE_YES = 0,
        VOTE_NO,
        VOTE_BLANK
    };
    
    bool vote = false;
    int voteamounts[4];
    int originalamounts[4];
    
    ostringstream stream;
    string question;
    string answer;
    
    TimedEvent * te;
    
    
    class VoteBallot : public GossipScript
    {
        void GossipHello(Object* pObject, Player* Plr, bool AutoSend)
        {
            if(vote)
            {
                GossipMenu * menu;
                objmgr.CreateGossipMenuForPlayer(&menu, pObject->GetGUID(), 1, Plr);
    
                menu->AddItem(0, "Yes", 1);
                menu->AddItem(0, "No", 2);
                menu->AddItem(0, "Blank vote", 3);
                if(AutoSend)
                    menu->SendTo(Plr);
            }
            else
            {
                Plr->BroadcastMessage("No active vote at the moment.");
                Plr->GetItemInterface()->RemoveItemAmt(90001, Plr->GetItemInterface()->GetItemCount(90001, true));
            }
    
        }
    
        void GossipSelectOption(Object* pObject, Player* Plr, uint32 Id, uint32 IntId, const char * EnteredCode)
        {
            voteamounts[IntId - 1]++;
            Plr->BroadcastMessage("Thanks for voting.");
            Plr->GetItemInterface()->RemoveItemAmt(90001, Plr->GetItemInterface()->GetItemCount(90001, true));
            Plr->Gossip_Complete();
        }
    
        void GossipEnd(Object * pObject, Player * pPlayer)
        {
        }
    
        void Destroy()
        {
            delete this;
        }
    
    public:
        void EndVote()
        {
            sWorld.SendWorldText("|cff00ff00[VoteSystem]|cff8aff00Vote ended.");
    
            stream.str("");
            stream << "|cff00ff00[VoteSystem]|cff8aff00Question was \'" << question << "\'.";
            sWorld.SendWorldText(stream.str().c_str());
    
            int voteamount = 0;
            int temp = 0;
    
            for (int i = 0; i < 4; i++)
            {
                originalamounts[i] = voteamounts[i];
            }
    
            //Sort array
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    if(voteamounts[j] < voteamounts[j + 1])
                    {
                        temp = voteamounts[j];
                        voteamounts[j] = voteamounts[j + 1];
                        voteamounts[j + 1] = temp;
                    }
                }
            }
    
            //Check for ties with the winning option, and give answer if there are ties
            if(voteamounts[0] == voteamounts[1])
            {
                if(voteamounts[1] == voteamounts[2])
                    answer = "undecided. All vote amounts are equal";
                else
                {
                    answer = "undecided. 2 vote amounts are equal";
                }
            }
            else
            {
                if(voteamounts[0] == originalamounts[VOTE_YES])
                    answer = "\'Yes\'";
                else if(voteamounts[0] == originalamounts[VOTE_NO])
                    answer = "\'No\'";
                else if(voteamounts[0] == originalamounts[VOTE_BLANK])
                    answer = "\'Blank\'";
            }
    
            stream.str("");
            stream << "|cff00ff00[VoteSystem]|cff8aff00Answer was " << answer << ".";
            sWorld.SendWorldText(stream.str().c_str());
            vote = false;
        }
    };
    
    VoteBallot * voteballot;
    
    void SetupVoteBallot(ScriptMgr * mgr)
    {
        voteballot = new VoteBallot();
        GossipScript * gs = voteballot;
        mgr->register_item_gossip_script(90001, gs);
    }
    
    bool OnChat(Player * pPlayer, uint32 Type, uint32 Lang, const char * Message, const char * Misc)
    {
        string msg(Message);
        string cmd = msg.substr(0, 10);
    
        if(strcmp(cmd.c_str(), "#startvote") == 0 && pPlayer->GetSession()->GetPermissionCount())
        {
            if(vote)
            {
                pPlayer->BroadcastMessage("|cff00ff00[VoteSystem]|cff8aff00There's already a vote active. Use #endvote to end the current vote manually.");
                return false;
            }
                
            unsigned int questionfound1 = msg.find(" ");
    
            if(questionfound1 != string::npos)
            {
                question = msg.substr(questionfound1 + 1, msg.length());
    
                stream.str("");
                stream << "|cff00ff00[VoteSystem]|cff8aff00<GM>" << pPlayer->GetName() << " started a vote.";
                sWorld.SendWorldText(stream.str().c_str());
                stream.str("");
                stream << "|cff00ff00[VoteSystem]|cff8aff00Question: " << question;
                sWorld.SendWorldText(stream.str().c_str());
                sWorld.SendWorldText("|cff00ff00[VoteSystem]|cff8aff00Voting will end in 1 minute.");
    
                //clean up vote amounts
                for(int i = 0; i < 3;i++)
                {
                    voteamounts[i] = 0;
                }
                voteamounts[3] = -1;
    
                vote = true;
    
                SendVoteBallotToAll();
    
                te = TimedEvent::Allocate(voteballot, new CallbackP0<VoteBallot>(voteballot, &VoteBallot::EndVote), 0, 60000, 1);
                pPlayer->event_AddEvent(te);
            }
            else
            {
                pPlayer->BroadcastMessage("|cff00ff00[VoteSystem]|cff8aff00Please use the correct syntax. For example: #startvote question?.");
            }
    
            return false;
        }
        else if(strcmp(msg.c_str(), "#endvote") == 0 && pPlayer->GetSession()->GetPermissionCount())
        {
            pPlayer->event_RemoveByPointer(te);
            voteballot->EndVote();
            stream.str("");
            stream << "|cff00ff00[VoteSystem]|cff8aff00Vote was stopped by <GM>" << pPlayer->GetName() << ".";
            sWorld.SendWorldText(stream.str().c_str());
            return false;
        }
        else
        {
            return true;
        }
    }
    
    
    
    
    
    void SendVoteBallotToAll()
    {
        PlayerStorageMap::const_iterator itr;
        objmgr._playerslock.AcquireReadLock();
        for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++)
        {
            Item * item = objmgr.CreateItem(90001, itr->second);
            itr->second->GetItemInterface()->AddItemToFreeSlot(item);
            item->SoulBind();
            itr->second->BroadcastMessage("A vote ballot has been added to your backpack. Right-Click it to vote.");
        }
        objmgr._playerslock.ReleaseReadLock();
    }
    
    extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
    {
        return SCRIPT_TYPE_MISC;
    }
    
    extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr * mgr)
    {
        SetupVoteBallot(mgr);
        mgr->register_hook(SERVER_HOOK_EVENT_ON_CHAT, (void*)OnChat);
    }
    Credits to me & Banaanaz.


    › See More: [C++]ArcEmu voting system.



  2. Related Threads - Scroll Down after related threads if you are only interested to view replies for above post/thread

  3. #2
    Founder
    Apple's Avatar
    Join Date
    Jul 2008
    Location
    HeaveN
    Posts
    15,916
    Post Thanks / Like
    Rep Power
    10
    Reputation
    295
    nice one





  4. #3
    Contributor
    Cocain's Avatar
    Join Date
    Mar 2010
    Posts
    208
    Post Thanks / Like
    Rep Power
    16
    Reputation
    92

    Register to remove this ad
    Thank you.

 

 

Visitors found this page by searching for:

polling system project in c

voting system project in c

voting system using c

voting system in c language

c program voting system

c voting system

online voting system in c

arcemu vote system

Vote Systemc code for voting systemonline voting system project in c c program for voting systemprogram voting system c c code for online voting systemvoting system in c voting system c what is polling system code c cpp program voting systempolling system code in c online polling system project c polling system project for election in c online voting system code in conline polling system code in csample c program for voting systemvote registration program in c voting system project code in c voting system in c ianguagec language voting systemprojects in c language voting systemcoding poll system using c voting system program in c using c on voting systemvoting system c programmingc program for voter registrationvoting system code in c c project for election voting systemc projects voting system c program for voting systemc language in voting systemc programming voting systemsample voting system for c online election voting system code in c GossipHello many use button times for trinitycoreproject on online voting system using c languagec program online voting systemc program project for voting systemsvotng system in c Ascent Vote System для ArcEmyarcemu check if const char == const chararemu vote script
SEO Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -5. The time now is 07:20 PM.
Powered by vBulletin® Copyright ©2000-2024, Jelsoft Enterprises Ltd.
See More links by ForumSetup.net. Feedback Buttons provided by Advanced Post Thanks / Like (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
vBulletin Licensed to: MMOPro.org