pWorld->ADDOBJ Problem

12/04/2016 15:36 raventh1984#1
Hi elitepvpers,

With an lot of thanks from Alfredico i have created an new system.

However there is something i still cant wrap my head arround.

What i want to do is when an player has been moved to the map that its creating an Mover.

Code:
pMatch->CreateMover();
Code:
void CRiftMatch::CreateMover()
{
	vector<__RIFT_WORLD> vecWorld = CRiftMng::GetInstance()->m_vecRiftWorld;
	for (DWORD i = 0; i < vecWorld.size(); i++)
	{
		CWorld* pWorld = g_WorldMng.GetWorld(vecWorld.at(i).dwWorldID);
		if (!pWorld)
			continue;

		vector<__RIFT_MONSTER>::iterator it = CRiftMng::GetInstance()->m_vecMonster.begin();

		MoverProp* pMoverProp = prj.GetMoverPropEx((*it).dwId);
		if (pMoverProp && pMoverProp->dwID != 0)
		{
			CObj* pObj = CreateObj(D3DDEVICE, OT_MOVER, pMoverProp->dwID);
			if (NULL == pObj)
			{
				OUTPUTDEBUGSTRING("\nPobj is NULL");
				return;
			}
			pObj->SetPos((*it).vPos);
			pObj->InitMotion(MTI_STAND);
			pObj->UpdateLocalMatrix();

			((CMover*)pObj)->m_bActiveAttack = (*it).bRed;
			pWorld->ADDOBJ(pObj, TRUE, nDefaultLayer);
		}
		OUTPUTDEBUGSTRING("\nGetting WorldID and MoverID: WorldID = %d MoverID = %d\n", vecWorld.at(i).dwWorldID, (*it).dwId);
	}
}
Before you asking well is the mover existing
Yes it is existing

Cause i test it like this
Code:
void CRiftMatch::GetMover()
{
	vector<__RIFT_MONSTER> vecMon = CRiftMng::GetInstance()->m_vecMonster;
	for (int i = 0; i < vecMon.size(); i++)
	{
		OUTPUTDEBUGSTRING("\nGetMover: MoverId = %d nState = %d bRed = %d vPos = %d\n", vecMon.at(i).dwId, vecMon.at(i).nState, vecMon.at(i).bRed, vecMon.at(i).vPos);
	}
}
So when i enter the world i can see in debug modes that the mover is inside __RIFT_MONSTER.

I checked multiple snippets from other .cpp files and tested them out.
But for some reason it isn't spawning the mob.
12/04/2016 15:42 Nortix#2
Spawn them on the correct layer
12/04/2016 15:48 raventh1984#3
Thanks haha. Didnt noticed it.

I had indeed defaultlayer.
But my layer was created by dwPlayerId.

Changed it its now working.
12/04/2016 18:49 alfredico#4
The following part is unnecessary. Once in your system you select your world from the possible options, it should be saved somewhere.

Code:
vector<__RIFT_WORLD> vecWorld = CRiftMng::GetInstance()->m_vecRiftWorld;
	for (DWORD i = 0; i < vecWorld.size(); i++)
	{
		CWorld* pWorld = g_WorldMng.GetWorld(vecWorld.at(i).dwWorldID);
		if (!pWorld)
			continue;

On vector used for store monsters, the .begin() will always return you the first stored value on the vector, you need to loop to get all the monsters.


Code:
void CRiftMatch::CreateMover()
{
	CWorld* pWorld = g_WorldMng.GetWorld(__WORLD); //World member variable
	if(!pWorld || !pWorld->m_linkMap.GetLinkMap(_LINKMAP_ID)) //No need to continue if there is no linkmap
		return;
		
	vector<__RIFT_MONSTER>::iterator it = CRiftMng::GetInstance()->m_vecMonster.begin();
	for( ; it != CRiftMng::GetInstance()->m_vecMonster.end(); ++it)
	{
		CObj* pObj = CreateObj(D3DDEVICE, OT_MOVER, (*it).dwId);
		if(pObj == nullptr)
			return;
			
		pObj->SetPos((*it).vPos);
		pObj->InitMotion(MTI_STAND);
		pObj->UpdateLocalMatrix();

		((CMover*)pObj)->m_bActiveAttack = (*it).bRed;
		pWorld->ADDOBJ(pObj, TRUE, __LAYER); //Linkmap
	}
}

Edit: Forgot to tell, there is no need to check if MoverProp*, it is generated from the config files you write, it should exist.