[CODE] Potion Use Delay

#1
Kind of fixed use delay of potion (2 seconds) rather than before which was absolutely ping based. These simple codes kills the advantage for those low ping players in your server thus provide fairer gameplay for other high pingers.

I only did a minor test only but based on codes, they should work without problems. Have fun

Client SRC

Game.h

Find

Code: Select all

class CGame
{
public:

Add

Code: Select all

// sleeq - potion use delay
DWORD PotionUseDelay;

Game.cpp

Find in CGame::UpdateScreen_OnGame

Code: Select all

m_dwFPStime = m_dwCheckConnTime = m_dwCheckSprTime = m_dwCheckChatTime = dwTime;

Add below

Code: Select all

// sleeq - potion use delay
PotionUseDelay = dwTime;

Find in CGame::OnKeyUp

Code: Select all

case VK_INSERT:
		if (m_iHP <= 0) return;
		if (m_bItemUsingStatus == TRUE)
		{	AddEventList(USE_RED_POTION1, 10);
			return;
		}
		if (m_bIsDialogEnabled[27] == TRUE)
		{	AddEventList(USE_RED_POTION2, 10);
			return;
		}
		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 1))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}

		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 2))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}
		break;

	case VK_DELETE:
		if (m_iHP <= 0) return;
		if (m_bItemUsingStatus == TRUE)
		{	AddEventList(USE_BLUE_POTION1, 10);
			return;
		}
		if (m_bIsDialogEnabled[27] == TRUE)
		{	AddEventList(USE_BLUE_POTION2, 10);
			return;
		}

		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 3))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}

		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 4))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}
		break;

Replace with this new one

Code: Select all

case VK_INSERT:
		if (m_iHP <= 0) return;
		if (m_bItemUsingStatus == TRUE)
		{	AddEventList(USE_RED_POTION1, 10);
			return;
		}
		if (m_bIsDialogEnabled[27] == TRUE)
		{	AddEventList(USE_RED_POTION2, 10);
			return;
		}
		/*for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 1))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}

		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 2))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}*/

		// sleeq - potion use delay
		for (i = 0; i < DEF_MAXITEMS; i++)
		if ((m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) && (m_pItemList[i]->m_sSprite == 6)) {
			if (m_pItemList[i]->m_sSpriteFrame == 1 || m_pItemList[i]->m_sSpriteFrame == 2) {
				if (dwTime - PotionUseDelay >= 2000) {
					bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
					m_bIsItemDisabled[i] = TRUE;
					m_bItemUsingStatus = TRUE;
					PotionUseDelay = dwTime;
					return;
				} else { AddEventList("You can only drink another potion after 2 seconds.", 10); return; }
			}
		}
		break;

	case VK_DELETE:
		if (m_iHP <= 0) return;
		if (m_bItemUsingStatus == TRUE)
		{	AddEventList(USE_BLUE_POTION1, 10);
			return;
		}
		if (m_bIsDialogEnabled[27] == TRUE)
		{	AddEventList(USE_BLUE_POTION2, 10);
			return;
		}

		/*for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 3))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}

		for (i = 0; i < DEF_MAXITEMS; i++)
		if ( (m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) &&
			 (m_pItemList[i]->m_sSprite == 6) && (m_pItemList[i]->m_sSpriteFrame == 4))
		{	bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
			m_bIsItemDisabled[i] = TRUE;
			m_bItemUsingStatus = TRUE;
			return;
		}*/

		// sleeq - potion use delay
		for (i = 0; i < DEF_MAXITEMS; i++)
		if ((m_pItemList[i] != NULL) && (m_bIsItemDisabled[i] != TRUE) && (m_pItemList[i]->m_sSprite == 6)) {
			if (m_pItemList[i]->m_sSpriteFrame == 3 || m_pItemList[i]->m_sSpriteFrame == 4) {
				if (dwTime - PotionUseDelay >= 2000) {
					bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, i, NULL, NULL, NULL);
					m_bIsItemDisabled[i] = TRUE;
					m_bItemUsingStatus = TRUE;
					PotionUseDelay = dwTime;
					return;
				} else { AddEventList("You can only drink another potion after 2 seconds.", 10); return; }
			}
		}
		break;

Find in CGame::DlbBoxDoubleClick_Inventory

Code: Select all

bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, cItemID, NULL, NULL, NULL);

Replace with this new one

Code: Select all

				// sleeq - potion use delay
				if (m_pItemList[cItemID]->m_sSprite == 6) {
					if (m_pItemList[cItemID]->m_sSpriteFrame >= 1 && m_pItemList[cItemID]->m_sSpriteFrame <= 4) {
						if ((timeGetTime() - PotionUseDelay) <= 2000) {
							AddEventList("You can only drink another potion after 2 seconds.", 10);
							return;
						} else {
							PotionUseDelay = timeGetTime();
							bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, cItemID, NULL, NULL, NULL);
						}
					}
				}
				bSendCommand(MSGID_COMMAND_COMMON, DEF_COMMONTYPE_REQ_USEITEM, NULL, cItemID, NULL, NULL, NULL);
https://www.youtube.com/channel/UCre_Jw ... -k6CHUsWAw
More videos: http://fb.com/helbreath/videos/
My github: https://github.com/sleeqeels/Helbreath-800x600

Who is online

Users browsing this forum: No registered users and 1 guest