release (vote reward vendor) menu

User Tag List

Results 1 to 9 of 9
  1. #1
    pooooo132's Avatar Member
    Reputation
    13
    Join Date
    Sep 2007
    Posts
    113
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    release (vote reward vendor)

    delete please, thanks you



    Last edited by pooooo132; 03-24-2008 at 08:33 PM.

    release (vote reward vendor)
  2. #2
    waymirec's Avatar Member
    Reputation
    49
    Join Date
    Jan 2008
    Posts
    155
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is it a "voting reward" if its just a standard vendor selling items for gold?

  3. #3
    jokerjokes's Avatar Active Member
    Reputation
    75
    Join Date
    Apr 2007
    Posts
    902
    Thanks G/R
    3/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please boxxxxxxx the dame codes lol i gets really annoying.......

  4. #4
    doublehex's Avatar Member
    Reputation
    34
    Join Date
    Mar 2007
    Posts
    385
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yea....this is not a voting vendor....voting vendor would require scripting, hmmm maybe ill work on that.....


  5. #5
    jokerjokes's Avatar Active Member
    Reputation
    75
    Join Date
    Apr 2007
    Posts
    902
    Thanks G/R
    3/3
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh would be very useful double

  6. #6
    doublehex's Avatar Member
    Reputation
    34
    Join Date
    Mar 2007
    Posts
    385
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im on it! (gotta do it fast or ultra spidey will beat me to it! lol)


  7. #7
    Tubaquer's Avatar Member
    Reputation
    7
    Join Date
    Oct 2007
    Posts
    33
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for making a contribution, but something like this would, as previously stated, probably need some sort of script(s).

    Also, when posting codes I suggest placing it in a box, just so it's softer on the eyes, and not painful to read.

    But, thanks for this anyway, I'm sure we're able to work on what you've already done.

  8. #8
    waymirec's Avatar Member
    Reputation
    49
    Join Date
    Jan 2008
    Posts
    155
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've been meaning to look into a way to hack together an ACTUAL vendor that sells items for voting points but in the meantime I threw together a simple gossip npc to do it.
    It references a table (users) within my vote database that contains the amount of voting points each user has and allows them to choose from a list of items which are defined in the 'votingrewards' table under the world database. If they have enough points to afford the item they've selected it adjusts their points appropriatley. I use a custom VoteDatabase object that references my vote database, but you could just as easily put your vote table containing your voting points within the world, logon or character db and adjust the db call appropriately.

    VotingRewards.cpp
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    #include <iostream>
    #include <vector>
    
    using namespace std;
    
    #ifdef WIN32
        #pragma warning(disable:4305)        // warning C4305: 'argument' : truncation from 'double' to 'float'
    #endif
    
    #define SendQuickMenu(textid) objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), textid, Plr); Menu->SendTo(Plr);
    
    // GossipScript only supports 15 items (client side)
    #define MAX_ENTRIES 13
    
    class SCRIPT_DECL VotingRewards : public GossipScript
    {
      public:
        void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
        void DisplayPage(Object * pObject, Player* Plr, uint8 page);
        void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
        void GossipEnd(Object * pObject, Player* Plr);
    
      private:
        void GetRewards(uint32 team,uint32 page,std::vector<vr_item*> &items);
        void GetReward(uint32 id,vr_item &item);
        bool GiveReward(uint32 item,Player * Plr);
        bool CanDisplay(vr_item item, Player * Plr);
        uint32 GetPoints(Player * Plr);
        void UpdatePoints(Player * Plr,uint32 points);
        bool GiveReward(Player * Plr,uint32 item);
    };
    
    void VotingRewards::GossipHello(Object * pObject, Player* Plr, bool AutoSend)
    {
            Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NULL;
            if(pCreature==NULL)
                    return;
    
            uint32 points = GetPoints(Plr);
            std::stringstream msg;
            if(points > 0)
            {
                    msg << "Welcome " << Plr->GetName() << ". You have " << points << " Voting Points to spend.";
                    pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY,LANG_UNIVERSAL,msg.str().c_str());
                    DisplayPage(pObject,Plr,1);
                    return;
            }
    
            msg << "Welcome " << Plr->GetName() << ". Sorry but you have no Voting Points to spend. GO VOTE!";
            pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY,LANG_UNIVERSAL,msg.str().c_str());
            GossipScript::GossipEnd(pObject, Plr);
            return;
    }
    
    void VotingRewards::DisplayPage(Object * pObject, Player * Plr, uint8 page)
    {
            uint32 next = page+1;
            uint32 prev = page > 1 ? page-1 : 0;
            Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NULL;
    
            if(pCreature==NULL)
                    return;
    
            GossipMenu *Menu;
            objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 1, Plr);
    
            std::vector<vr_item*> items;
            GetRewards(Plr->GetTeam(),page,items);
    
            uint32 index = 0;
            for(std::vector<vr_item*>::iterator itItem = items.begin(); itItem != items.end(); itItem++)
            {
                    if(index++ >= MAX_ENTRIES)
                    {
                            Menu->AddItem(7,"[Next]",next);
                            break;
                    }
    
                    vr_item *item = *(itItem);
                    if(CanDisplay(*(item),Plr))
                    {
                            std::stringstream msg;
                            msg << item->name << " (" << item->cost << " pts)";
                            Menu->AddItem(1,msg.str().c_str(),item->id);
                    }
                    delete item;
            }
    
            if(page > 1)
                    Menu->AddItem(7,"[Prev]",prev);
    
            Menu->SendTo(Plr);
    }
    
    void VotingRewards::GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code)
    {
            Creature * pCreature = (pObject->GetTypeId()==TYPEID_UNIT)?((Creature*)pObject):NULL;
    
            if(pCreature==NULL)
                    return;
    
            if (IntId < 10)
            {
                    DisplayPage(pObject,Plr,IntId);
                    return;
            }
    
            uint32 points = GetPoints(Plr);
    
            vr_item item;
            GetReward(IntId,item);
            std::stringstream msg;
    
            if (points > item.cost)
            {
                    if (GiveReward(Plr,item.id))
                    {
                            msg << "Thank You " << Plr->GetName() << ". Enjoy your reward.";
                            pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY,LANG_UNIVERSAL,msg.str().c_str());
                            UpdatePoints(Plr,item.cost);
                    }
                    else
                    {
                            msg << "Sorry " << Plr->GetName() << ", but your inventory is full.";
                            pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY,LANG_UNIVERSAL,msg.str().c_str());
                    }
                    DisplayPage(pObject,Plr,1);
            }
            else
            {
                    msg << "Sorry " << Plr->GetName() << ", but you do not have enough points for that item.";
                    pCreature->SendChatMessage(CHAT_MSG_MONSTER_SAY,LANG_UNIVERSAL,msg.str().c_str());
                    DisplayPage(pObject,Plr,1);
            }
    }
    
    void VotingRewards::GossipEnd(Object * pObject, Player* Plr)
    {
        GossipScript::GossipEnd(pObject, Plr);
    }
    
    void VotingRewards::GetRewards(uint32 team,uint32 page,std::vector<vr_item*> &items)
    {
            uint32 start = (page > 0) ? (page-1) * MAX_ENTRIES : 0;
            QueryResult * res;
            res = WorldDatabase.Query("SELECT v.item,i.name1,v.cost,v.team,v.minlevel,v.maxlevel FROM votingrewards AS v LEFT JOIN items AS i ON (i.entry=v.item) WHERE (v
    .team=-1 OR v.team=%u) ORDER BY i.name1 LIMIT %u,100",team,start);
    
            if(res)
            {
                    do {
                            vr_item *item = new vr_item;
                            item->id = res->Fetch()[0].GetUInt32();
                            item->name = res->Fetch()[1].GetString();
                            item->cost = res->Fetch()[2].GetUInt32();
                            item->team = res->Fetch()[3].GetUInt32();
                            item->maxlevel = res->Fetch()[4].GetUInt32();
                            item->minlevel = res->Fetch()[5].GetUInt32();
                            if ((item->id > 0) && (item->name != 0))
                                    items.push_back(item);
                    } while(res->NextRow());
            }
            delete res;
    }
    
    void VotingRewards::GetReward(uint32 id,vr_item &item)
    {
            QueryResult * res;
            res = WorldDatabase.Query("SELECT v.item,i.name1,v.cost,v.team,v.minlevel,v.maxlevel FROM votingrewards AS v LEFT JOIN items AS i ON (i.entry=v.item) WHERE v.
    item='%u'",id);
            if(res)
            {
                    item.id = res->Fetch()[0].GetUInt32();
                    item.name = res->Fetch()[1].GetString();
                    item.cost = res->Fetch()[2].GetUInt32();
                    item.team = res->Fetch()[3].GetUInt32();
                    item.maxlevel = res->Fetch()[4].GetUInt32();
                    item.minlevel = res->Fetch()[5].GetUInt32();
            }
            delete res;
    }
    
    bool VotingRewards::CanDisplay(vr_item item, Player * Plr)
    {
            if ((item.team != -1) && (item.team != Plr->GetTeam())) return false;
            if ((item.minlevel > 0) && (Plr->getLevel() < item.minlevel)) return false;
            if ((item.maxlevel > 0) && (Plr->getLevel() > item.maxlevel)) return false;
    
            return true;
    }
    
    uint32 VotingRewards::GetPoints(Player * Plr)
    {
            QueryResult * res = VoteDatabase.Query("SELECT points FROM users WHERE username='%s'",Plr->GetSession()->GetAccountName().c_str());
            if(res)
            {
                    uint32 points = res->Fetch()[0].GetUInt32();
                    delete res;
                    return points;
            }
            delete res;
            return 0;
    }
    
    bool VotingRewards::GiveReward(uint32 item,Player * Plr)
    {
            Item * pItem = objmgr.CreateItem(item,Plr);
            return Plr->GetItemInterface()->AddItemToFreeSlot(pItem);
    }
    
    void VotingRewards::UpdatePoints(Player * Plr,uint32 points)
    {
            QueryResult * res = VoteDatabase.Query("UPDATE users SET points=points-%u WHERE username='%s'",points,Plr->GetSession()->GetAccountName().c_str());
            delete res;
    }
    
    bool VotingRewards::GiveReward(Player * Plr,uint32 item)
    {
            ItemPrototype *proto = ItemPrototypeStorage.LookupEntry(item);
            SlotResult slotresult;
            slotresult = Plr->GetItemInterface()->FindFreeInventorySlot(proto);
    
            if(!slotresult.Result)
            {
                Plr->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL);
                return false;
            }
            else
            {
                Item *itm = objmgr.CreateItem(item, Plr);
                itm->SetUInt32Value(ITEM_FIELD_STACK_COUNT, 1);
                Plr->GetItemInterface()->SafeAddItem(itm,slotresult.ContainerSlot, slotresult.Slot);
                return true;
            }
    }
    
    void SetupVotingRewards(ScriptMgr * mgr)
    {
            GossipScript * gs = (GossipScript*) new VotingRewards();
            mgr->register_gossip_script(2, gs);
    
    }
    Setup.cpp
    Code:
    #include "StdAfx.h"
    #include "Setup.h"
    #include <ScriptSetup.h>
    
    extern "C" SCRIPT_DECL uint32 _exp_get_script_type()
    {
            return SCRIPT_TYPE_MISC;
    }
    
    extern "C" SCRIPT_DECL void _exp_script_register(ScriptMgr* mgr)
    {
            SetupVotingRewards(mgr);
    
    }
    
    #ifdef WIN32
    
    BOOL APIENTRY DllMain( HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved )
    {
        return TRUE;
    }
    
    #endif
    Setup.h
    Code:
    #ifndef INSTANCE_SCRIPTS_SETUP_H
    #define INSTANCE_SCRIPTS_SETUP_H
    
    struct vr_item {
            int id;
            const char * name;
            uint32 cost;
            int team;
            uint32 minlevel;
            uint32 maxlevel;
    };
    
    void SetupVotingRewards(ScriptMgr * mgr);
    
    #endif
    Last edited by waymirec; 03-23-2008 at 10:19 AM.

  9. #9
    doublehex's Avatar Member
    Reputation
    34
    Join Date
    Mar 2007
    Posts
    385
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aww dammit, and i just finished mine too, im too slow lol, if someone hadnt bothered me *ahem joker* jk .....oh well no point in posting the same script twice since mine pretty much the same but i like your separate database idea


Similar Threads

  1. [Release] Voting Reward Script
    By TheSpidey in forum WoW EMU General Releases
    Replies: 178
    Last Post: 03-26-2009, 05:25 PM
  2. Voting Rewards
    By mafiaboy in forum Programming
    Replies: 21
    Last Post: 06-30-2008, 03:22 AM
  3. Voting Rewards
    By EmuGod in forum World of Warcraft Emulator Servers
    Replies: 28
    Last Post: 05-07-2008, 09:16 AM
  4. [Release] WORKING! Soda Vendor (Revamped Cola Vendor! ^.^!)
    By Creepfold in forum World of Warcraft Emulator Servers
    Replies: 1
    Last Post: 12-01-2007, 11:00 AM
  5. [Release] Lottery Master Vendor
    By knaur in forum World of Warcraft Emulator Servers
    Replies: 12
    Last Post: 11-29-2007, 01:05 PM
All times are GMT -5. The time now is 07:22 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search