Code :
#include "precompiled.h"
#include "../../../../shared/Config/Config.h"
#include "../../Config.h"
#include "../../../../game/Language.h"
#include "../../../../shared/Database/DatabaseMysql.h" //Wasn't entirely sure if I needed this one so added it just in case
extern DatabaseMysql SD2Database;
bool GossipHello_VoteVendorNPC(Player *player, Creature *_Creature)
{
Config SD2Config;
if(!SD2Config.SetSource(_SCRIPTDEV2_CONFIG)) //Check if scriptdev2.conf exists
{
error_log("SD2: Unable to open configuration file");
}
if(SD2Config.GetBoolDefault("VoteVendorNPC.OnlyGMs", false)) // If VoteVendor.OnlyGMs is enabled in scriptdev2.conf
{
if(player->GetSession()->GetSecurity() == SEC_PLAYER)
{
_Creature->MonsterWhisper("Sorry, I'm only availible to Game Masters.", player);
return true;
}
}
//Some examples of what can be done:
player->ADD_GOSSIP_ITEM( 5, "Trade Vote Points for Vote Coins" , GOSSIP_SENDER_MAIN, 1000);
player->ADD_GOSSIP_ITEM( 5, "10 Gold - 20 Vote Coins" , GOSSIP_SENDER_MAIN, 2000);
if(player->getLevel() < 80) //We don't want players to level above 80 :)
{
player->ADD_GOSSIP_ITEM( 5, "1 Level up - 40 Vote Coins" , GOSSIP_SENDER_MAIN, 3000);
}
player->ADD_GOSSIP_ITEM( 5, "36 Slot bag - 25 Vote Coins" , GOSSIP_SENDER_MAIN, 4000);
player->ADD_GOSSIP_ITEM( 7, "1 item [call GM before paying!] - 60 Vote Coins" , GOSSIP_SENDER_MAIN, 5000);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetObjectGuid());
return true;
}
void SendDefaultMenu_VoteVendorNPC(Player *player, Creature *_Creature, uint32 action)
{
QueryResult *result;
//This query is just an example. I suggest using the account table in the realmd database to store the users
//vote points. It makes it easier to get the account that belongs to the user ingame.
result = SD2Database.PQuery("SELECT votepoints FROM account WHERE id = '%u'", player->GetSession()->GetAccountId());
Field *Fields = result->Fetch();
Item* item;
ItemPosCountVec dest;
uint32 noSpaceForCount = 0;
uint32 itemId = 0; //Change 0 to whichever item id your Vote Coins have (do this everywhere in the script where it says //change 0)
int32 count = Fields[0].GetUInt32(); //Get x Vote Points from database
uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
//When we're going to use multiple item rewards, so we need more variables etc etc
ItemPosCountVec dest2;
uint32 itemId2 = 23162;
int32 count2 = 1;
uint8 msg2 = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest2, itemId2, count2, &noSpaceForCount );
// Disable npc if in combat
if(!player->getAttackers().empty())
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You are in combat!", LANG_UNIVERSAL, NULL);
return;
}
switch(action)
{
case 6000: //Back to Main Menu
player->ADD_GOSSIP_ITEM( 5, "Trade Vote Points for Vote Coins" , GOSSIP_SENDER_MAIN, 1000);
player->ADD_GOSSIP_ITEM( 5, "10 Gold - 20 Vote Coins" , GOSSIP_SENDER_MAIN, 2000);
if(player->getLevel() < 80) //We don't want players to level above 80 :)
{
player->ADD_GOSSIP_ITEM( 5, "1 Level up - 40 Vote Coins" , GOSSIP_SENDER_MAIN, 3000);
}
player->ADD_GOSSIP_ITEM( 5, "36 Slot bag - 25 Vote Coins" , GOSSIP_SENDER_MAIN, 4000);
player->ADD_GOSSIP_ITEM( 7, "1 item [call GM before paying!] - 60 Vote Coins" , GOSSIP_SENDER_MAIN, 5000);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetObjectGuid());
break;
case 1000: //Trade Vote Points for Vote Coins
if(result)
{
if( msg2 != EQUIP_ERR_OK ) // convert to possible store amount
count2 -= noSpaceForCount;
if( count2 == 0 || dest.empty()) // If the player doesn't have any vote points
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You don't have any vote points!", LANG_UNIVERSAL, NULL);
}
item = player->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
if (count2 > 0 && item)
{
player->CLOSE_GOSSIP_MENU();
player->SendNewItem(item,count,false,true);
//Ofcorse we reset the players Vote Points to 0 in database
SD2Database.PExecute("UPDATE account SET vote_points = '0' WHERE id = '%u'", player->GetSession()->GetAccountId());
_Creature->MonsterWhisper("Vote Points reset to 0", player);
}
if(noSpaceForCount > 0)
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterWhisper("Unable to create item", player);
}
}
else //Just in case something went wrong with the first query
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("Error: Problem with database data. Please inform a GM about this error.", LANG_UNIVERSAL, NULL);
}
break;
case 2000: //10 Gold - 20 Vote Coins
if(player->HasItemCount(24245, 20)) //change 0
{
player->CLOSE_GOSSIP_MENU();
player->DestroyItemCount(24245, 20, true); //change 0
player->ModifyMoney(100000);
_Creature->MonsterWhisper("You received 10 Gold", player);
}
else
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
}
break;
case 3000: //1 Level up - 40 Vote Coins
if(player->HasItemCount(24245, 40)) //change 0
{
player->CLOSE_GOSSIP_MENU();
player->DestroyItemCount(24245, 40, true); //change 0
player->GiveLevel(player->getLevel() + 1);
_Creature->MonsterWhisper("You received 1 level up", player);
}
else
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
}
break;
case 4000: //36 Slot bag - 25 Vote Coins
if( msg2 != EQUIP_ERR_OK ) // convert to possible store amount
count2 -= noSpaceForCount;
if( count2 == 0 || dest.empty()) // If count2 is set 0 for some reason
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterWhisper("Error: Item count set to 0. Please inform a GM about this error.", player);
}
item = player->StoreNewItem( dest2, itemId2, true, Item::GenerateItemRandomPropertyId(itemId2));
if(count2 > 0 && item)
{
player->CLOSE_GOSSIP_MENU();
player->SendNewItem(item,count2,false,true);
}
if(noSpaceForCount > 0)
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterWhisper("Unable to create item", player);
}
else
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
}
break;
case 5000: //1 item [call GM before paying!] - 60 Vote Coins
player->ADD_GOSSIP_ITEM( 5, "A GM is with me, pay now" , GOSSIP_SENDER_MAIN, 5001);
player->ADD_GOSSIP_ITEM( 5, "There is no GM with me, return to Main menu" , GOSSIP_SENDER_MAIN, 6000);
player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE,_Creature->GetGUID());
break;
case 5001:
if(player->HasItemCount(60004, 60))
{
player->CLOSE_GOSSIP_MENU();
player->DestroyItemCount(60004, 60, true);
_Creature->MonsterSay("I just received 60 Vote Coins for a Green or Blue item", LANG_UNIVERSAL, NULL);
}
else
{
player->CLOSE_GOSSIP_MENU();
_Creature->MonsterSay("You don't have enough Vote Coins to purchase that reward!", LANG_UNIVERSAL, NULL);
}
break;
} //End switch
} //End function
bool GossipSelect_VoteVendorNPC(Player *player, Creature *_Creature, uint32 sender, uint32 action)
{
// Main menu
if (sender == GOSSIP_SENDER_MAIN)
SendDefaultMenu_VoteVendorNPC( player, _Creature, action );
return true;
}
void AddSC_votevendornpc()
{
Script *newscript;
newscript = new Script;
newscript->Name = "votevendornpc";
newscript->pGossipHello = &GossipHello_VoteVendorNPC;
newscript->pGossipSelect = &GossipSelect_VoteVendorNPC;
newscript->RegisterSelf();
}
ce crash nest pas du au pnj mais il est identiques sa maffiche les meme truc au moment du crash.
Comme j'ai dit sa bug a l'envoie de l'item lorsque mangos crach sa reste sur les ligne ou sa envoie l'item..meme quand le pnj menvoie le message qui dit que je nai aps assez de points sa me fait pareil sa mrche deux ou trois fois et sa crash
Si quelqu'un peut me renseigner merci bien.
j'ai essayer pas mal de chose repris du code dans le fichier level3.cpp quand un gm envoie l'items enfin jai essayer pas mal de solution et rien
Cordialement Toxic