Jump to content
  • 0

Stackoverflow in function (Slot Machine System)


Kafa

Question

Hey guys, i found a system released in owsap's github. I implemented it, but when i press the start button, my game crashes and my vdi says "Stackoverflow detected..."

 

Here is the function 

bool CHARACTER::StartSlotMachine(uint8_t bBet)
{
	if (!IsPC())
		return false;

	if (!GetDesc())
		return false;

	if (!CanWarp())
		return false;

	if (!m_bSlotMachineOpen)
		return false;

	if (m_pkSlotMachineEvent)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("[Slot Machine] The machine is already running."));
		return false;
	}

	if (bBet > SlotMachineBetMap.size() || bBet < 1)
		bBet = 1;

	int64_t iPrice = SlotMachineBetMap[bBet];
	if (GetGold() < iPrice)
	{
		ChatPacket(CHAT_TYPE_INFO, LC_TEXT("[Slot Machine] You don't have enough money to bet."));
		return false;
	}

	uint8_t iSlotMachineMltiplier = quest::CQuestManager::instance().GetEventFlag("slot_machine_multiplier");
	if (iSlotMachineMltiplier > 0)
		bBet += iSlotMachineMltiplier;

	uint8_t iSlotMachineReels = quest::CQuestManager::instance().GetEventFlag("slot_machine_reels");
	for (uint8_t bSlot = 0; bSlot < ESlotMachine::MAX_SLOT_MACHINE_SLOTS; ++bSlot)
	{
		std::random_device rd;
		std::mt19937 mt(rd());
		std::uniform_real_distribution<> dist(1, (iSlotMachineReels > 0 ? iSlotMachineReels : ESlotMachine::MAX_SLOT_MACHINE_REELS));
		m_bSlotMachineReel[bSlot] = static_cast<uint8_t>(dist(mt));
	}

 

 

Can someone help me?

Link to post

3 answers to this question

Recommended Posts

  • 0
  • VIP

Here, use int for the loop and you can also use the default number function to randomize the numbers.

	for (int bSlot = 0; bSlot < ESlotMachine::MAX_SLOT_MACHINE_SLOTS; ++bSlot)
	{
		m_bSlotMachineReel[bSlot] = number(1, (iSlotMachineReels > 0 ? iSlotMachineReels : ESlotMachine::MAX_SLOT_MACHINE_REELS));
	}

 

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.