Generating Random dwWorldID.

11/28/2016 22:59 raventh1984#1
Hi elitepvpers,

I am working on something so that if you enter an dungeon that it randomize the dungeons.

So what i did was this
Code:
TestMng::SetRandomWorld()
{
	int x = rand() % 2;

	switch (x)
	{
	case 0:
	{
			  dwWorldTest = WI_INSTANCE_CONTAMINTRAILS;
	}
		break;
	case 1:
	{
			  dwWorldTest = WI_INSTANCE_BEHAMAH;
	}
		break;
	}

}
Code:
int TestMng::GetRandomWorld()
{
	//if (dwWorldTest != NULL_ID)
//		Error("dwWorldTest %d", dwWorldTest);
		return dwWorldTest;
}
Code:
CWorld* pWorld = g_WorldMng.GetWorld(pTestMng->GetRandomWorld());
	if (pWorld && pWorld->m_linkMap.GetLinkMap(static_cast<int>(dwPlayerID)))
		pWorld->Invalidate(dwPlayerID);
And
Code:
CWorld* pWorld = g_WorldMng.GetWorld(pTestMng->GetRandomWorld());
	ASSERT(pWorld);
	if (IsValidObj(pUser))
	{
		if (pWorld->m_linkMap.GetLinkMap(static_cast<int>(dwPlayerID)))
		{
			//pUser->REPLACE(g_uIdofMulti, WI_INSTANCE_CONTAMINTRAILS, D3DXVECTOR3(1413.187f, 100.487f, 1261.361f), REPLACE_NORMAL, static_cast<int>(dwPlayerID));
			pUser->REPLACE(g_uIdofMulti, pTestMng->GetRandomWorld(), D3DXVECTOR3(1413.187f, 100.487f, 1261.361f), REPLACE_NORMAL, static_cast<int>(dwPlayerID));
		}
	}
The problem is when i am willing to enter the dungeon its crashing.
On Debugging its telling me that its crashing on

return dwWorldTest; @[Only registered and activated users can see links. Click Here To Register...]stMng::GetRandomWorld()

When i enable the error logging. Then the error is saying the correct ID. for each time i try to enter. So i know that SetRandomWorld is functional.

Any tips?

With kind regards.
11/29/2016 09:14 XorArsen#2
DWORD dwWorldId = xRandom(2) == TRUE ? WI_INSTANCE_CONTAMINTRAILS : WI_INSTANCE_BEHAMAH;

only one line code..

and without more informations we cant help you..
11/29/2016 09:25 alfredico#3
Quote:
Originally Posted by XorArsen View Post
DWORD dwWorldId = xRandom(2) == TRUE ? WI_INSTANCE_CONTAMINTRAILS : WI_INSTANCE_BEHAMAH;

only one line code..

and without more informations we cant help you..
And?


The pointer pTestMng is wrong.
11/29/2016 10:24 XorArsen#4
Quote:
Originally Posted by alfredico View Post
And?


The pointer pTestMng is wrong.
Why should you write 20 lines if you can do it with only one line?
11/29/2016 11:35 Meutledaron#5
where SetRandomWorld() is called ?
11/29/2016 13:24 alfredico#6
Quote:
Originally Posted by XorArsen View Post
Why should you write 20 lines if you can do it with only one line?
It's optional the programming style you want to do, but in this case I'm pretty sure many programmers will agree with this way. You have in this case, different worlds to load which will load for the moment two cases but you could have many other worlds. I prefer to use abbreviations when you have for example just two cases, like true o false; or similar.

Personally, I would use a struct and a vector for the random maps @[Only registered and activated users can see links. Click Here To Register...].
11/29/2016 14:53 raventh1984#7
Thanks all.

I solved the problem by re-scripting some of the code.

And for the Switch cases yeah the intention is to load all dungeons.

So its indead better for struct and vector. I will do that one. xD.

Thanks for the tips all.