little bug Rift System

12/29/2016 16:04 raventh1984#1
Hi all,

Some of you know that i am working on an rift system for flyff.

Well i need an bit of help once again xD.

I thought i finished it but then i noticed an little bug.
Ok here it goes.

.lua file contains
AddWorld(WorldID, TotalMonster, StartPosition)

SetMonsterSpawn(WorldID, Position)
SetMonsterSpawn(WorldID, Position)
SetMonsterSpawn(WorldID, Position)

now for test its filled like this

AddWorld(1, 5, 123, 100, 20)

SetMonsterSpawn(1, 127,100,25)
SetMonsterSpawn(1, 50,100,300)
SetMonsterSpawn(2, 150,100,500)

Ok so far so good.
The problem is when i enter the rift at world id 1 instead of random 5 monsters it sometimes set just 2 monsters at 2 diff locations.

That is because its also using the SetMonsterSpawn (2).

So my question is how can i make it so that it only loops true the RIFT_SPAWN vector if the WorldId is the same as SetMonsterSpawn(WorldId).

Atm i have it like this
Code:
D3DXVECTOR3 CRiftMatch::GetMoverSpawnPoints(DWORD dwWorldId)
{
	vector<RIFT_MONSTER_SPAWN> vecSpawn = CRiftMng::GetInstance()->m_vecMSpawnPoint;
	for (int i = 0; i < vecSpawn.size(); i++)
	{
		if (vecSpawn[i].dwWorldId == dwWorldId)
		{
			OUTPUTDEBUGSTRING("\n GetSpawnPoints %d", vecSpawn.size());
		}
	}
	int nRand = rand() % vecSpawn.size();
	return vecSpawn[nRand].vPos;
}
Output is still 3! it should be 2. Cause only 2 SpawnPoints exists with the same WorldId.

@[Only registered and activated users can see links. Click Here To Register...] i will tag you to cause you already have helped me an lot in understanding vectors. but i can't seem to solve this one.

With kind regards/.
12/29/2016 16:27 Nortix#2
Code:
OUTPUTDEBUGSTRING("\n GetSpawnPoints %d", vecSpawn.size());
You are printing the size of the vector, of course it's 3. Put the spawn points you need into a new vector or even better save the spawnpoints per world and not globally
12/29/2016 16:36 raventh1984#3
well actualy they are saved per world.

Code:
while (Lua.TableLoop(-2))
		{
			RIFT_MONSTER_SPAWN rSpawnPoint;
			rSpawnPoint.dwWorldId = static_cast<int>(CScript::GetDefineNum(Lua.GetFieldToString(-1, "dwWorldId")));
			rSpawnPoint.vPos.x = static_cast<float>(Lua.GetFieldToNumber(-1, "x"));
			rSpawnPoint.vPos.y = static_cast<float>(Lua.GetFieldToNumber(-1, "y"));
			rSpawnPoint.vPos.z = static_cast<float>(Lua.GetFieldToNumber(-1, "z"));

			m_vecMSpawnPoint.push_back(rSpawnPoint);
			Lua.Pop(1);
		}
The only thing i need to figure out if that if dwWorldId == the same as the vectors world id then output the correct positions. so yeah then i can make an new vector that contains the proper Positions per worldId and then loop true it.

Maybe its that i am to long awake xD.
12/29/2016 16:43 Nortix#4
No, they are not saved per world, just with the ID of the world. Have a look at PartyDungeon.lua and how it is loaded

But to address your problem, it's almost the same
[Only registered and activated users can see links. Click Here To Register...]
12/29/2016 17:04 alfredico#5
You have to loop the entire spawn vector but cannot return when the first result is found.
Also you could use std::find_if() with a lambda expression, but this is fine.

For returning all data correctly, use pointers.

Code:
void CRiftMatch::GetMoverSpawnPoints(DWORD dwWorldId, std::vector<RIFT_MONSTER_SPAWN>* vec)
{
	vector<RIFT_MONSTER_SPAWN> vecSpawn = CRiftMng::GetInstance()->m_vecMSpawnPoint;
	for (int i = 0; i < vecSpawn.size(); i++)
	{
		if (vecSpawn[i].dwWorldId == dwWorldId)
		{
			int nRand = rand() % vecSpawn.size();
			vec.push_back(vecSpawn[nRand]);
			OUTPUTDEBUGSTRING("\n GetSpawnPoints %d", vecSpawn.size());
		}
	}
}

std::vector<RIFT_MONSTER_SPAWN> v;
GetMoverSpawnPoints(WORLD, &v); //v is filled with data from function
I won't do using this way. I will use an enum for defining each phase (hope there are not many phases) and a container for each phase to keep the progress of the instance.
Removing monsters from container when dying and adding at the start of each phase. A std::map(MONSTER_ID, MONSTER_DATA) or std::map(WORLD, MONSTER_DATA) or std::map(WORLD+PHASE_DATA, MONSTER_DATA).