[src] Trade Ball

Codes already submitted by people of the forums.
Post Reply
Namesis
Regular
Posts: 88
Joined: Fri Mar 03, 2006 12:53 pm

Post by Namesis »

Trade Ball by <span style='color:green'>Shetar</span>

Code: Select all

~~~At Client.cpp add: 
m_iBallPoints = 0; 

~~~At Client.h add: 
int m_iBallPoints; 

~~~At Item.h add: 
#define DEF_ITEMEFFECTTYPE_ADDBALLPOINTS 33 


~~~At Game.cpp multiple snippets must be added. 
~~~To start look for: 

wsprintf(cTxt, "gizon-item-upgade-left = %d", m_pClientList[iClientH]->m_iGizonItemUpgradeLeft); 
strcat(pData, cTxt 
strcat(pData,"\n"); 

~~~~~And underneath that place this: 

wsprintf(cTxt, "character-ball-points = %d", m_pClientList[iClientH]->m_iBallPoints); 
strcat(pData, cTxt); 
strcat(pData,"\n"); 

~~~~~Then look for these few lines 

m_pClientList[iClientH]->m_iGizonItemUpgradeLeft = atoi(token); 
cReadModeA = 0; 
break; 

~~~~~and again underneath it place: 

case 81: 
if (_bGetIsStringIsNumber(token) == FALSE) { 
wsprintf(cTxt, "(!!!) Player(%s) data file error! (BallPoints) - Connection closed. ", m_pClientList[iClientH]->m_cCharName); 
PutLogList(cTxt); 
delete pContents; 
delete pStrTok; 
return FALSE; 
} 

m_pClientList[iClientH]->m_iBallPoints = atoi(token); 
cReadModeA = 0; 
break; 

then under.. 

if (memcmp(token, "gizon-item-upgade-left", 22) == 0) cReadModeA = 80; 

place: 

if (memcmp(token, "character-ball-points", 21) == 0) cReadModeA = 81; 

~~~Then we go to the part which is giving balls the power to give Ball Points. 
~~~Look for: 

case DEF_ITEMEFFECTTYPE_STUDYMAGIC: 
iV1 = m_pClientList[iClientH]->m_pItemList[sItemIndex]->m_sItemEffectValue1; 
if (m_pMagicConfigList[iV1] != NULL) 
RequestStudyMagicHandler(iClientH, m_pMagicConfigList[iV1]->m_cName, FALSE); 
break; 

~~~~and underneath it place: 

case DEF_ITEMEFFECTTYPE_ADDBALLPOINTS: 
iV1 = m_pClientList[iClientH]->m_pItemList[sItemIndex]->m_sItemEffectValue1; 
m_pClientList[iClientH]->m_iBallPoints += iV1; 

wsprintf(cInfoString,"%d Ball Points added. Total Amount: %d ", iV1, m_pClientList[iClientH]->m_iBallPoints); 
SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_IPACCOUNTINFO, NULL, NULL, NULL, cInfoString); 
break; 

~~~Then we're heading to the part which lets the HGServer read the special item file in which items are named which are buyable with Ball Points. Place this underneath the pieces of code which are loading the other CFG's: 

if (bReadBallSystemConfigFile("..\\GameConfigs\\BallItems.cfg") == FALSE) { 
PutLogList(" "); 
PutLogList("(!!!) CRITICAL ERROR! Cannot execute server! AdminSettings.cfg file contents error!"); 
return FALSE; 
} 

~~~At the bottom of Game.cpp add the function which actually reads the file: 

BOOL CGame::bReadBallSystemConfigFile(char * cFn) 
{ 
FILE * pFile; 
HANDLE hFile; 
DWORD dwFileSize; 
char * cp, * token, cReadModeA, cReadModeB; 
char seps[] = "= \t\n"; 
int iIndex; 
class CStrTok * pStrTok; 
char cTxt[41]; 

cReadModeA = 0; 
cReadModeB = 0; 

hFile = CreateFile(cFn, GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL); 
dwFileSize = GetFileSize(hFile, NULL); 
if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile); 

pFile = fopen(cFn, "rt"); 
if (pFile == NULL) { 

PutLogList("(!) Cannot open Ball System configuration file."); 
return FALSE; 
} 
else { 
PutLogList("(!) Reading Ball System configuration file..."); 
cp = new char[dwFileSize+2]; 
ZeroMemory(cp, dwFileSize+2); 
fread(cp, dwFileSize, 1, pFile); 

iIndex = 0; 
pStrTok = new class CStrTok(cp, seps); 
token = pStrTok->pGet(); 
while( token != NULL ) { 
if (cReadModeA != 0) { 
switch (cReadModeA) { 
case 1: 
switch (cReadModeB) { 
case 1: 

if (_bGetIsStringIsNumber(token) == FALSE) { 
PutLogList("(!!!) CRITICAL ERROR! Ball System configuration file error - Wrong Data format(1)."); 
delete cp; 
delete pStrTok; 
return FALSE; 
} 
iIndex = atoi(token); 

if (m_pBallItemConfigList[iIndex] != NULL) { 

wsprintf(cTxt, "(!!!) CRITICAL ERROR! Duplicate Ball Item ID (%d)", iIndex); 
PutLogList(cTxt); 
delete pStrTok; 
return FALSE; 
} 
m_pBallItemConfigList[iIndex] = new class CBallSystem; 
m_pBallItemConfigList[iIndex]->m_sBS_ID = iIndex; 

cReadModeB = 2; 
break; 

case 2: 
ZeroMemory(m_pBallItemConfigList[iIndex]->m_cName, sizeof(m_pBallItemConfigList[iIndex]->m_cName)); 
memcpy(m_pBallItemConfigList[iIndex]->m_cName, token, strlen(token)); 
cReadModeB = 3; 
break; 

case 3: 
m_pBallItemConfigList[iIndex]->m_iReqPoints = atoi(token); 
cReadModeA = 0; 
cReadModeB = 0; 
} 
break; 

default: 
break; 
} 
} 
else { 
if (memcmp(token, "Ball-Item", 9) == 0) { 
cReadModeA = 1; 
cReadModeB = 1; 
} 

} 
token = pStrTok->pGet(); 
} 

delete pStrTok; 
delete cp; 

if ((cReadModeA != 0) || (cReadModeB != 0)) { 
PutLogList("(!!!) CRITICAL ERROR! Ball System configuration file contents error!"); 
return FALSE; 
} 
} 

if (pFile != NULL) fclose(pFile); 
return TRUE; 
} 



~~~~Now the command which lets a player obtain items! 

if (memcmp(cp, "/trade ", 7) == 0) { 
RequestBallItem(iClientH, cp, dwMsgSize - 21); 
return; 
} 


~~~~Function which gets to be actived: 

void CGame::RequestBallItem(int iClientH, char *pData, DWORD dwMsgSize) 
{ 
char seps[] = "= \t\n"; 
char * cp, * token, cBuff[256], cWantedItemName[256], cData[256], cInfoString[56]; 
class CStrTok * pStrTok; 
class CItem * pItem; 
short * sp, sCounter; 
int i, iRet, iEraseReq; 
DWORD * dwp; 
WORD * wp; 

if (m_pClientList[iClientH] == NULL) return; 

if ((dwMsgSize) <= 0) 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(cWantedItemName, sizeof(cWantedItemName)); 
strcpy(cWantedItemName, token); 
} 

sCounter = 1; 

for (i = 0, i < DEF_MAXBALLITEMS; i++;) { 
if (sCounter == 1) { 
if (m_pBallItemConfigList[i] != NULL) { 
if (strcmp(cWantedItemName, m_pBallItemConfigList[i]->m_cName) == 0) { 

if (m_pClientList[iClientH]->m_iBallPoints < m_pBallItemConfigList[i]->m_iReqPoints) { 
wsprintf(cInfoString,"Item (%s) cannot be traded, not enough points. ", cWantedItemName); 
SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_IPACCOUNTINFO, NULL, NULL, NULL, cInfoString); 
return; 
} 

m_pClientList[iClientH]->m_iBallPoints -= m_pBallItemConfigList[i]->m_iReqPoints; 

pItem = new class CItem; 

if (_bInitItemAttr(pItem, cWantedItemName) == FALSE) { 
delete pItem; 
return; 
} 

ZeroMemory(cData, sizeof(cData)); 
if (_bAddClientItemList(iClientH, pItem, &iEraseReq) == TRUE) { 

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); 

sCounter = 0; 
return; 
} 
else { 
sCounter = 0; 
delete pItem; 
return; 
} 
} 
} 
} 
} 
} 



~~~~And at last.. a command which shows a player his amount of Ball Points: 

if (memcmp(cp, "/ballpoint", 10) == 0) { 
char cInfoString[50]; 
wsprintf(cInfoString," Amount of Ball Points: (%d) ", m_pClientList[iClientH]->m_iBallPoints); 
SendNotifyMsg(NULL, iClientH, DEF_NOTIFY_IPACCOUNTINFO, NULL, NULL, NULL, cInfoString); 
return; 
} 
~~~~~ADD to Game.h Search DEF_MAXBANNED add this under it: 
#define DEF_MAXBALLITEMS         50 

~~~~~Search 
class CDelayEvent    * m_pDelayEventList[DEF_MAXDELAYEVENTS]; 

~~~~~add under it 
class CBallSystem    * m_pBallItemConfigList[DEF_MAXBALLITEMS]; 

~~~~~also add 
   void RequestBallItem(int iClientH, char *pData, DWORD dwMsgSize); 
   BOOL bReadBallSystemConfigFile(char * cFn); 

~~~befor 
}; 

#endif // !defined(AFX_GAME_H__C3D29FC5_755B_11D2_A8E6_00001C7030A6__INCLUDED_) 

~~~IN item.h 
~~~befor 
#endif // !defined(AFX_ITEM_H__211A1360_91B9_11D2_B143_00001C7030A6__INCLUDED_) 

~~~ADD 
   //ball trade 
   class CBallSystem  
{ 
public: 
    
      short m_sBS_ID; 
      char m_cName[20]; 
      int m_iReqPoints; 

}; 

~~~~~ missing a char under case DEF_ITEMEFFECTTYPE_ADDBALLPOINTS 
~~~~~ search case DEF_ITEMEFFECTTYPE_ADDBALLPOINTS 
~~~~~ add under it 
char cInfoString[56]; 




Ball-Item = 1 Devastator   100 
Ball-Item = 2 KlonessAxe  60 
Ball-Item = 3 CancelManual 100
espero que les sirva :)

un par de datos por si alguien no lo sabe..:

Code: Select all

Item = 655 PearlBall "7" 0 34 0 0 0 0 0 0 3 0 6 127 -5000 4000 -1 0 0 0 0 0 -1 31 0
ese "7" lo hay que poner obligado para que se coman las balls y te den los puntos

Code: Select all

Item = 655 PearlBall 7 0 34 "0" 0 0 0 0 0 3 0 6 127 -5000 4000 -1 0 0 0 0 0 -1 31 0
ese "0" equivale a los puntos de los balls, osea, si la PearlBall de tu game vale 35 puntos, poner 35.
Namesis
Regular
Posts: 88
Joined: Fri Mar 03, 2006 12:53 pm

Post by Namesis »

Ahora, tengo una pregunta :P :

quiero saber como poner para que el /trade sirva, porque me como las balls y todo eso, pero cuando pongo /trade, no me da el item, ni me quita las balls, es como si el commando no existiera.. que pudiera hacer? estara alguna parte del src mal?

edit:
~english
i want to know how to put the /trade to work, because i can eat the ball and it give me points, etc.., but when i try to put /trade, it doesnt give me the item and decrease the balls.. like if the command doesnt exist... what i can do? some part of the src if bad? :S
-apok-
Regular
Posts: 48
Joined: Sat Nov 06, 2004 1:59 am
Location: Australia

Post by -apok- »

in english for everyone else? kthx
<img src='http://i39.photobucket.com/albums/e160/ ... gycopy.png' border='0' alt='user posted image' />
Namesis
Regular
Posts: 88
Joined: Fri Mar 03, 2006 12:53 pm

Post by Namesis »

h.e.l.p =\
Post Reply