[req] Auto Clearmap

Codes already submitted by people of the forums.
Hypnotoad
Member
Posts: 100
Joined: Wed Apr 28, 2004 8:16 pm

Post by Hypnotoad »

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....
<img src='http://www.playah.no-ip.com/images/Hypn ... imated.gif' border='0' alt='user posted image' />
Warlord
Regular
Posts: 34
Joined: Sun Dec 05, 2004 11:08 am

Post by Warlord »

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.

Code: Select all

    m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
It keeps telling me that iClientH is an undeclared identifier... ;)

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();
}
SlammeR
Loyal fan
Posts: 219
Joined: Fri Nov 04, 2005 1:52 am
Location: Brazil

Post by SlammeR »

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.

Code: Select all

    m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
It keeps telling me that iClientH is an undeclared identifier... ;)

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:

Code: Select all

m_pMapList[m_pClientList[iClientH]->m_cMapIndex]->GetOwner(&sOwner, &cOwnerType, j, k);
to this:

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>
Warlord
Regular
Posts: 34
Joined: Sun Dec 05, 2004 11:08 am

Post by Warlord »

Thanks SlammeR, it works now.. :lol:
Maxis
Regular
Posts: 51
Joined: Tue Apr 04, 2006 4:47 pm

Post by Maxis »

--------------------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)
what is wrong i have 2 errors ?? do you help me ??:P
Dshaked
&lt;3 bd long time
Posts: 747
Joined: Tue Oct 11, 2005 6:40 pm

Post by Dshaked »

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>
PiotrekK
noob
Posts: 29
Joined: Fri Jan 13, 2006 2:39 am
Location: Poland/Warsaw
Contact:

Post by PiotrekK »

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

}

Code: Select all

in Map.h add this function declaration

void CleanTile(short sX, short sY, DWORD dwItemDeleteDelay);
this piece of code should work, havent tested it cos dont have HB at work :). 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 ;)
This code is good?
0 errors?
sokol
Loyal fan
Posts: 228
Joined: Mon May 02, 2005 7:28 pm
Location: P(r)oland

Post by sokol »

try it he said HE HAVENT TESTED IT !
if got error fix it ez.
Tafka12
&lt;3 bd long time
Posts: 772
Joined: Wed Dec 28, 2005 6:32 pm

Post by Tafka12 »

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' />
marleythe9
Loyal fan
Posts: 391
Joined: Sat Mar 26, 2005 12:41 am

Post by marleythe9 »

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....
<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' />
Cleroth
Loyal fan
Posts: 416
Joined: Wed Jun 16, 2004 7:08 pm

Post by Cleroth »

Dshaked wrote: decleare this to item.h m_dwItemTime, like BOOL m_dwItemTime;
<a href='http://www.justfuckinggoogleit.com/' target='_blank'>BOOL m_dwItemTime;</a> ????
<img src='http://ic1.deviantart.com/fs11/i/2006/1 ... leroth.gif' border='0' alt='user posted image' />
EvilHit
Loyal fan
Posts: 356
Joined: Sun Jan 16, 2005 3:20 am

Post by EvilHit »

i cant found citem in 2.24d so how do i get around this becuz ive done so much work wit this files and i want this in it
naatten
noob
Posts: 27
Joined: Sun Jan 01, 2006 11:17 pm

Post by naatten »

Code works perfectly but crash's the HG preety often... atleast for me it crashes like every second hour... and when i took away autclearmap function it stopped crashing...
SlammeR
Loyal fan
Posts: 219
Joined: Fri Nov 04, 2005 1:52 am
Location: Brazil

Post by SlammeR »

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 :)
Here Is The Fix =) this will update the screen removing the old items =)

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>
Jensen
Loyal fan
Posts: 300
Joined: Tue Aug 02, 2005 7:40 am
Location: Illinois, USA
Contact:

Post by Jensen »

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....
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.

-><-
Post Reply