[req] Auto Clearmap
i already coded this using klks help in 3.02 source look for the functions:
ClearMap() which is called on timer after 360000...it is also a gm command /clearmap AdminOrder_CleanMap....
ClearMap() which is called on timer after 360000...it is also a gm command /clearmap AdminOrder_CleanMap....
<img src='http://www.playah.no-ip.com/images/Hypn ... imated.gif' border='0' alt='user posted image' />
btw..Can I use this code for 2.24 sources? I get one error in the Game.cpp where i added this ClearMap function..
the code where I get 1 error.
It keeps telling me that iClientH is an undeclared identifier... 
this AutoClearMap() function should look like this. Repair me if Im wrong.
the code where I get 1 error.
Code: Select all
m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);

this AutoClearMap() function should look like this. Repair me if Im wrong.
Code: Select all
void CGame::AutoClearMap()
{
int i, k, j, m_y, m_x;
short sOwner;
char cOwnerType;
for (i = 0; i < DEF_MAXMAPS; i++) { //Enum all maps
if (m_pMapList[i] != NULL) { //Is allocated map
m_x = m_pMapList[i]->m_sSizeX;
m_y = m_pMapList[i]->m_sSizeY;
for(j = 1; j < m_x; j++) {
for(k = 1; k < m_y; k++){
m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
if (sOwner == NULL || cOwnerType != DEF_OWNERTYPE_PLAYER) {
m_pMapList[i]->CleanTile(j, k, dwItemDeleteDelay);
}
}
}
}
}
PutLogList("(!!!) AutoClearMap Executed!");
//Update last clean time
dwItemCleanLastTime = GetTickCount();
}
change this:Warlord wrote: btw..Can I use this code for 2.24 sources? I get one error in the Game.cpp where i added this ClearMap function..
the code where I get 1 error.
It keeps telling me that iClientH is an undeclared identifier...Code: Select all
m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
this AutoClearMap() function should look like this. Repair me if Im wrong.
Code: Select all
void CGame::AutoClearMap() { int i, k, j, m_y, m_x; short sOwner; char cOwnerType; for (i = 0; i < DEF_MAXMAPS; i++) { //Enum all maps if (m_pMapList[i] != NULL) { //Is allocated map m_x = m_pMapList[i]->m_sSizeX; m_y = m_pMapList[i]->m_sSizeY; for(j = 1; j < m_x; j++) { for(k = 1; k < m_y; k++){ m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k); if (sOwner == NULL || cOwnerType != DEF_OWNERTYPE_PLAYER) { m_pMapList[i]->CleanTile(j, k, dwItemDeleteDelay); } } } } } PutLogList("(!!!) AutoClearMap Executed!"); //Update last clean time dwItemCleanLastTime = GetTickCount(); }
Code: Select all
m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
Code: Select all
m_pMapList[m_pClientList[i]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
OWNED!<br><img src='http://img50.imageshack.us/img50/1386/p ... 3vsqn2.gif' border='0' alt='user posted image' /><br><br><img src="http://hbtop50.com/button.php?u=hbuonline" alt="Helbreath Top 50 - Keepin' it real." border="0" /><br><a href='http://www.hbuonline.net' target='_blank'>Helbreath United</a>
what is wrong i have 2 errors ?? do you help me ??:P--------------------Configuration: HGserver - Win32 Debug--------------------
Compiling...
Game.cpp
d:\sources\sources hgserverów\2.24c sources\netmessages.h(223) : warning C4005: 'DEF_NOTIFY_FORCEDISCONN' : macro redefinition
d:\sources\sources hgserverów\2.24c sources\netmessages.h(73) : see previous definition of 'DEF_NOTIFY_FORCEDISCONN'
d:\sources\sources hgserverów\2.24c sources\netmessages.h(224) : warning C4005: 'DEF_NOTIFY_FIGHTZONERESERVE' : macro redefinition
d:\sources\sources hgserverów\4.01 sources\netmessages.h(74) : see previous definition of 'DEF_NOTIFY_FIGHTZONERESERVE'
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(801) : warning C4101: 'cTargetName' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(801) : warning C4101: 'cName' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(801) : warning C4101: 'token' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(800) : warning C4101: 'm_iRating' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(799) : warning C4101: 'pStrTok' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(802) : warning C4101: 'i' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(801) : warning C4101: 'cBuff' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(1555) : warning C4101: 'dwTime' : unreferenced local variable
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(2557) : warning C4305: '=' : truncation from 'const int' to 'char'
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(2557) : warning C4309: '=' : truncation of constant value
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(9380) : warning C4305: '=' : truncation from 'const int' to 'short'
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(9380) : warning C4309: '=' : truncation of constant value
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(12954) : error C2039: 'm_dwItemTime' : is not a member of 'CItem'
d:\sources\sources hgserverów\2.24c sources\item.h(86) : see declaration of 'CItem'
D:\Sources\Sources HGServerów\2.24c Sources\Game.cpp(55310) : warning C4552: '/' : operator has no effect; expected operator with side-effect
Map.cpp
d:\sources\sources hgserverów\2.24c sources\netmessages.h(223) : warning C4005: 'DEF_NOTIFY_FORCEDISCONN' : macro redefinition
d:\sources\sources hgserverów\2.24c sources\netmessages.h(73) : see previous definition of 'DEF_NOTIFY_FORCEDISCONN'
d:\sources\sources hgserverów\2.24c sources\netmessages.h(224) : warning C4005: 'DEF_NOTIFY_FIGHTZONERESERVE' : macro redefinition
d:\sources\sources hgserverów\2.24c sources\netmessages.h(74) : see previous definition of 'DEF_NOTIFY_FIGHTZONERESERVE'
D:\Sources\Sources HGServerów\4.01 Sources\Map.cpp(891) : error C2039: 'm_dwItemTime' : is not a member of 'CItem'
d:\sources\sources hgserverów\4.01 sources\item.h(86) : see declaration of 'CItem'
Error executing cl.exe.
HGserver.exe - 2 error(s), 17 warning(s)
decleare this to item.h m_dwItemTime, like BOOL m_dwItemTime;
Old Helbreath Nemesis Player<br><img src='http://img232.imageshack.us/img232/9784/dshakedqc5.jpg' border='0' alt='user posted image' /><br><img src='http://img232.imageshack.us/img232/6475 ... barqj0.jpg' border='0' alt='user posted image' /><br><a href='index.php?showtopic=7107&hl=' target='_blank'>MainServer Hexing Tutorial</a><br><a href='index.php?showtopic=7663&hl=x-mas' target='_blank'>My Files</a>
This code is good?KLKS wrote: and thats why smart people break down their maps into multiple HG's
Code: Select all
in CGame::CGame(HWND hWnd) add dwItemCleanLastTime = GetTickCount(); dwItemCleanDelay = 600000; //600k ms = 10 mins dwItemDeleteDelay = 300000; //300k ms = 5 mins
Code: Select all
in "class CGame" add DWORD dwItemCleanLastTime; //Last time a map was cleaned DWORD dwItemCleanDelay; //After how long before we should clean DWORD dwItemDeleteDelay; //How long should an item be on floor before it gets deleted
Code: Select all
in "class CItem" add DWORD m_dwItemTime;
Code: Select all
in "CItem::CItem()" add m_dwItemTime = GetTickCount();
Code: Select all
in DropItemHandler add if ((m_pClientList[iClientH]->m_pItemList[sItemIndex]->m_sItemEffectType == DEF_ITEMEFFECTTYPE_ALTERITEMDROP) && (m_pClientList[iClientH]->m_pItemList[sItemIndex]->m_wCurLifeSpan == 0)) { delete m_pClientList[iClientH]->m_pItemList[sItemIndex]; m_pClientList[iClientH]->m_pItemList[sItemIndex] = NULL; } else { //Update item time *NEW* m_pClientList[iClientH]->m_pItemList[sItemIndex]->m_dwItemTime = GetTickCount(); m_pMapList[ m_pClientList[iClientH]->m_cMapIndex ]->bSetItem(m_pClientList[iClientH]->m_sX, m_pClientList[iClientH]->m_sY, m_pClientList[iClientH]->m_pItemList[sItemIndex]);
Code: Select all
in DelayEventProcessor() add if ((dwTime - dwItemCleanLastTime) > dwItemCleanDelay) //Had time elapsed ? AutoClearMap();
Code: Select all
in Map.cpp add this new function int CMap::iGetTotalItemsOnTile(short sX, short sY) { class CTile * pTile; class CItem * pItem; if ((sX < 0) || (sX >= m_sSizeX) || (sY < 0) || (sY >= m_sSizeY)) return NULL; pTile = (class CTile *)(m_pTile + sX + sY*m_sSizeY); pItem = pTile->m_pItem[0]; return pTile->m_cTotalItem; }
Code: Select all
in Map.h add this function declaration int iGetTotalItemsOnTile(short sX, short sY);
Code: Select all
add a new function void CGame::AutoClearMap() void CGame::AutoClearMap() { int i, k, j, m_y, m_x; for (i = 0; i < DEF_MAXMAPS; i++) { //Enum all maps if (m_pMapList[i] != NULL) { //Is allocated map m_x = m_pMapList[i]->m_sSizeX; m_y = m_pMapList[i]->m_sSizeY; for(j = 1; j < m_x; j++) { for(k = 1; k < m_y; k++){ m_pMapList[i]->CleanTile(j, k, dwItemDeleteDelay); } } } } PutLogList("(!!!) AutoClearMap Executed!"); //Update last clean time dwItemCleanLastTime = GetTickCount(); }
Code: Select all
in Game.h add this function declaration void AutoClearMap();
Code: Select all
add a new function in Map.cpp void CMap::CleanTile(short sX, short sY, DWORD dwItemDeleteDelay) { class CTile * pTile; class CItem * pItem[DEF_TILE_PER_ITEMS]; register int i,j; DWORD dwTime; if ((sX < 0) || (sX >= m_sSizeX) || (sY < 0) || (sY >= m_sSizeY)) return; pTile = (class CTile *)(m_pTile + sX + sY*m_sSizeY); if (pTile->m_cTotalItem == 0) return; dwTime = GetTickCount(); //Get time ZeroMemory(pItem, sizeof(pItem)); //Zero the whole pItem structure for (i = 0, j = 0; i <= DEF_TILE_PER_ITEMS-2; i++){ //Enum all items on tile if (pTile->m_pItem[i] != NULL) { if ((dwTime - pTile->m_pItem[i]->m_dwItemTime) > dwItemDeleteDelay) //Item has been on ground for too long { delete pTile->m_pItem[i]; //Delete item which has been on floor for too long pTile->m_pItem[i] = NULL; } else{ //This code only keeps live items pItem[j++] = pTile->m_pItem[i]; //Copy item to a temp place } } } //Copy back data of items //No need to NULL out pTile as pItem has its sturcture NULLED out at the start for (i = 0; i <= DEF_TILE_PER_ITEMS-2; i++) pTile->m_pItem[i] = pItem[i]; }
this piece of code should work, havent tested it cos dont have HB at workCode: Select all
in Map.h add this function declaration void CleanTile(short sX, short sY, DWORD dwItemDeleteDelay);
. anyhow please test it and tell me if there is any bugs.
one bug to note tho, when the map is cleaned, items at the top which are deleted are not refreshed so player still "sees" the old items, but its not there. i'll fix that problem once i get more time
ps for all u wannabe HB coders, you cant code, if you could, you would be helping instead of posting useless stuff![]()
0 errors?
try it he said HE HAVENT TESTED IT !
if got error fix it ez.
if got error fix it ez.
<a href=http://profile.xfire.com/sok0l><img src=http://miniprofile.xfire.com/bg/co/type/0/sok0l.png width=440 height=111></a>
No it doesn't have errors, works too. use it
<img src='http://www.hot.ee/carvanho/taavi.png' border='0' alt='user posted image' /><br><br><img src='http://www.hot.ee/carvanho/Elvine.png' border='0' alt='user posted image' /><br><img src='http://www.hot.ee/carvanho/LieroX.png' border='0' alt='user posted image' /><br><img src='http://www.hot.ee/carvanho/Football.png' border='0' alt='user posted image' />
-
- Loyal fan
- Posts: 391
- Joined: Sat Mar 26, 2005 12:41 am
lol this is funny, makeing time on each item = more memory and the point of clearing the map is to prevent that..
ya i thought of doing this too but, after thinking about it, it dosnt help at all it acculy makes things wors.
unless u find some reason you realy need it, its realy up to u, but this code dose not save memory....it just adds more +veriables just so u can delete an item after 5min on ground veriables = + memory this just gives your HGsrever more work for no reason....
ya i thought of doing this too but, after thinking about it, it dosnt help at all it acculy makes things wors.
unless u find some reason you realy need it, its realy up to u, but this code dose not save memory....it just adds more +veriables just so u can delete an item after 5min on ground veriables = + memory this just gives your HGsrever more work for no reason....
<img src='http://freewebs.com/trickro/70s.png' border='0' alt='user posted image' /><img src='http://freewebs.com/trickro/70s2.jpg' border='0' alt='user posted image' />
<a href='http://www.justfuckinggoogleit.com/' target='_blank'>BOOL m_dwItemTime;</a> ????Dshaked wrote: decleare this to item.h m_dwItemTime, like BOOL m_dwItemTime;
<img src='http://ic1.deviantart.com/fs11/i/2006/1 ... leroth.gif' border='0' alt='user posted image' />
Here Is The Fix =) this will update the screen removing the old items =)one bug to note tho, when the map is cleaned, items at the top which are deleted are not refreshed so player still "sees" the old items, but its not there. i'll fix that problem once i get more time![]()
Code: Select all
void CGame::AutoClearMap()
{
int i, k, j, m_y, m_x;
short dX, dY;
char cMapName[11];
if (iDice(1,5) == 1) {
for (i = 0; i < DEF_MAXMAPS; i++) { //Enum all maps
if (m_pMapList[i] != NULL) { //Is allocated map
m_x = m_pMapList[i]->m_sSizeX;
m_y = m_pMapList[i]->m_sSizeY;
for(j = 1; j < m_x; j++) {
for(k = 1; k < m_y; k++){
m_pMapList[i]->CleanTile(j, k, dwItemDeleteDelay);
}
}
}
}
for(i = 1; i < DEF_MAXCLIENTS; i++) {
if (m_pClientList[i] != NULL) {
dX = m_pClientList[i]->m_sX;
dY = m_pClientList[i]->m_sY;
ZeroMemory(cMapName,sizeof(cMapName));
strcpy(cMapName, m_pClientList[i]->m_cMapName);
RequestTeleportHandler(i,"2 ", cMapName, dX, dY);
}
}
PutLogList("(!!!) AutoClearMap Executed!");
//Update last clean time
dwItemCleanLastTime = GetTickCount();
}
}
OWNED!<br><img src='http://img50.imageshack.us/img50/1386/p ... 3vsqn2.gif' border='0' alt='user posted image' /><br><br><img src="http://hbtop50.com/button.php?u=hbuonline" alt="Helbreath Top 50 - Keepin' it real." border="0" /><br><a href='http://www.hbuonline.net' target='_blank'>Helbreath United</a>
the point isnt to save on memory, well a little bit, NULL pointers take alot less space than items, but having a cleaner map also saves bandwidth.marleythe9 wrote: lol this is funny, makeing time on each item = more memory and the point of clearing the map is to prevent that..
ya i thought of doing this too but, after thinking about it, it dosnt help at all it acculy makes things wors.
unless u find some reason you realy need it, its realy up to u, but this code dose not save memory....it just adds more +veriables just so u can delete an item after 5min on ground veriables = + memory this just gives your HGsrever more work for no reason....
-><-