[CODE] /createitem Amount

#1
Able to create multiple amounts of item at a time. However the structure is bit different from the old one.

Old: /createitem <itemName> <stats>

New:
EG: /createitem <itemName> <amount> <stats>
EG2: /createitem Dagger 3 65456451, will create 3 stated daggers

HGServer

Find

Code: Select all

void CGame::AdminOrder_CreateItem

Replace all the codes with this new one

Code: Select all

// sleeq - adjusted to create multiple amount of item
// /createitem <name> <amount> <stats>
void CGame::AdminOrder_CreateItem(int iClientH, char *pData, DWORD dwMsgSize)
{
 char   seps[] = "= \t\n";
 char   * cp, * token, cBuff[256], cItemName[256], cData[256], cTemp[256], cAttribute[256], cValue[256];
 SYSTEMTIME SysTime;
 class  CStrTok * pStrTok;
 class  CItem * pItem;
 short  * sp;
 int    iRet, iTemp, iEraseReq, iValue, iAmount, i = 0;
 DWORD * dwp;
 WORD  * wp, wTemp;
 double dV1, dV2, dV3;
 
	if (m_pClientList[iClientH] == NULL) return;
	if (m_pClientList[iClientH]->m_bIsAdminCommandEnabled == FALSE) return;
	
	if ((dwMsgSize)	<= 0) return;

	if (m_pClientList[iClientH]->m_iAdminUserLevel < m_iAdminLevelCreateItem) {
		SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_ADMINUSERLEVELLOW, NULL, NULL, NULL, NULL);
		return;
	}
	
	if (m_pClientList[iClientH]->m_bIsAdminCreateItemEnabled == FALSE) return;
	
	ZeroMemory(cBuff, sizeof(cBuff));
	memcpy(cBuff, pData, dwMsgSize);
	pStrTok = new class CStrTok(cBuff, seps);
	token = pStrTok->pGet();
	token = pStrTok->pGet();

	if (token != NULL) {
		ZeroMemory(cItemName, sizeof(cItemName));
		strcpy(cItemName, token);
	}

	iAmount = 0;
	token = pStrTok->pGet();
	if (token != NULL) {
		iAmount = atoi(token);
	}
	if (iAmount <= 0 || iAmount >= 50) iAmount = 1;

	ZeroMemory(cAttribute, sizeof(cAttribute));
	token = pStrTok->pGet();
	if (token != NULL) {
		ZeroMemory(cAttribute, sizeof(cAttribute));
		strcpy(cAttribute, token);
	}

	ZeroMemory(cValue, sizeof(cValue));
	iValue = 0;
	token = pStrTok->pGet();
	if (token != NULL) {
		ZeroMemory(cValue, sizeof(cValue));
		strcpy(cValue, token);
		iValue = atoi(cValue);
	}

	while (i < iAmount) {
		pItem = new class CItem;
		if (_bInitItemAttr(pItem, cItemName) == FALSE) 
		{	delete pItem;
			return;	}
		if (strlen(cAttribute) != 0) {
			pItem->m_dwAttribute = atoi(cAttribute);
			if (pItem->m_dwAttribute == 1) {
				if ((iValue >= 1) && (iValue <= 200)) {
					pItem->m_cItemColor = 2;
					pItem->m_sItemSpecEffectValue2 = iValue - 100;
								
					dV2 = (double)pItem->m_sItemSpecEffectValue2;
					dV3 = (double)pItem->m_wMaxLifeSpan;
					dV1 = (dV2/100.0f)*dV3;

					iTemp  = (int)pItem->m_wMaxLifeSpan;
					iTemp += (int)dV1;

					if (iTemp <= 0) wTemp = 1;
					else wTemp = (WORD)iTemp;

					if (wTemp <= pItem->m_wMaxLifeSpan*2) {
						pItem->m_wMaxLifeSpan = wTemp;
						pItem->m_sItemSpecEffectValue1 = (short)wTemp;
						pItem->m_wCurLifeSpan = pItem->m_wMaxLifeSpan;
					}
					else pItem->m_sItemSpecEffectValue1 = (short)pItem->m_wMaxLifeSpan;
				}
				else pItem->m_dwAttribute = NULL;
			}
			else {
				if (pItem->m_sItemEffectType == DEF_ITEMEFFECTTYPE_ATTACK) {
					switch ((pItem->m_dwAttribute & 0xF00000) >> 20) {
					case 6:	pItem->m_cItemColor = 2; break;
					case 8: pItem->m_cItemColor = 3; break;
					case 1:	pItem->m_cItemColor = 5; break;
					case 5:	pItem->m_cItemColor = 1; break;
					case 3:	pItem->m_cItemColor = 7; break;
					case 2:	pItem->m_cItemColor = 4; break;
					case 7:	pItem->m_cItemColor = 6; break;
					case 9:	pItem->m_cItemColor = 8; break;
					} 
				}
				else if (pItem->m_sItemEffectType == DEF_ITEMEFFECTTYPE_ATTACK_MANASAVE) {
					switch ((pItem->m_dwAttribute & 0xF00000) >> 20) {
					case 10: pItem->m_cItemColor = 5; break;
					}
				}
			}
		}
		
		switch (pItem->m_sIDnum) {
		case 511:
		case 513:
		case 515:
		case 517:
		case 530:
		case 531:
		case 532:
		case 533:
		case 534:
			GetLocalTime(&SysTime);
			pItem->m_sTouchEffectType   = DEF_ITET_DATE;
			pItem->m_sTouchEffectValue1 = (short)SysTime.wMonth;
			pItem->m_sTouchEffectValue2 = (short)SysTime.wDay;
			pItem->m_sTouchEffectValue3 = 24 ;
			break;
		default:
			GetLocalTime(&SysTime);
			pItem->m_sTouchEffectType   = DEF_ITET_ID;
			pItem->m_sTouchEffectValue1 = iDice(1,100000);
			pItem->m_sTouchEffectValue2 = iDice(1,100000);
			ZeroMemory(cTemp, sizeof(cTemp));
			wsprintf(cTemp, "%d%2d",  (short)SysTime.wMonth, (short)SysTime.wDay);
			pItem->m_sTouchEffectValue3 = atoi(cTemp);
			break;
		}
	
		
		if (_bAddClientItemList(iClientH, pItem, &iEraseReq) == TRUE) {
			ZeroMemory(cData, sizeof(cData));
			dwp  = (DWORD *)(cData + DEF_INDEX4_MSGID);
			*dwp = MSGID_NOTIFY;
			wp   = (WORD *)(cData + DEF_INDEX2_MSGTYPE);
			*wp  = DEF_NOTIFY_ITEMOBTAINED;
			
			cp = (char *)(cData + DEF_INDEX2_MSGTYPE + 2);
			
			*cp = 1;
			cp++;
			
			memcpy(cp, pItem->m_cName, 20);
			cp += 20;
			
			dwp  = (DWORD *)cp;
			*dwp = pItem->m_dwCount;
			cp += 4;
			
			*cp = pItem->m_cItemType;
			cp++;
			
			*cp = pItem->m_cEquipPos;
			cp++;
			
			*cp = (char)0;
			cp++;
			
			sp  = (short *)cp;
			*sp = pItem->m_sLevelLimit;
			cp += 2;
			
			*cp = pItem->m_cGenderLimit;
			cp++;
			
			wp = (WORD *)cp;
			*wp = pItem->m_wCurLifeSpan;
			cp += 2;
			
			wp = (WORD *)cp;
			*wp = pItem->m_wWeight;
			cp += 2;
			
			sp  = (short *)cp;
			*sp = pItem->m_sSprite;
			cp += 2;
			
			sp  = (short *)cp;
			*sp = pItem->m_sSpriteFrame;
			cp += 2;
			
			*cp = pItem->m_cItemColor;
			cp++;

			*cp = (char)pItem->m_sItemSpecEffectValue2;
			cp++;
			
			dwp = (DWORD *)cp;
			*dwp = pItem->m_dwAttribute;
			cp += 4;

			if (iEraseReq == 1) {
				delete pItem;
				pItem = NULL ;
			}

			iRet = m_pClientList[iClientH]->m_pXSock->iSendMsg(cData, 53);
			i++;

			wsprintf(G_cTxt, "(%s) GM Order(%s): Create ItemName(%s)",m_pClientList[iClientH]->m_cIPaddress, m_pClientList[iClientH]->m_cCharName, cItemName);
			bSendMsgToLS(MSGID_GAMEMASTERLOG, iClientH, NULL,G_cTxt);
		} else {	
			delete pItem;
			return;
		}
	}
}
https://www.youtube.com/channel/UCre_Jw ... -k6CHUsWAw
More videos: http://fb.com/helbreath/videos/
My github: https://github.com/sleeqeels/Helbreath-800x600

Re: [CODE] /createitem Amount

#3
Thanks. Weight and item space checks are done in BOOL CGame::_bAddClientItemList hence why "if (_bAddClientItemList(iClientH, pItem, &iEraseReq) == TRUE) {" is there to perform a check before creating the item. If the checker returns false then item creation fails.
https://www.youtube.com/channel/UCre_Jw ... -k6CHUsWAw
More videos: http://fb.com/helbreath/videos/
My github: https://github.com/sleeqeels/Helbreath-800x600

Re: [CODE] /createitem Amount

#5
In any HG source, I believe there is already this in CGame::_bAddClientItemList

Code: Select all

iCalcTotalWeight();
This checks item space in bag as well. If you mean smth like _iGetItemSpaceLeft is missing or needed in the codes, even shops don't rely on that alone because it just calculate total items in bag and ignore weight load.

Result from unmodified, only my custom createitem cmd

youtu.be/zT5iuHzcd0o
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

cron