Custom "Skip Area When Monster"

03/03/2013 22:36 Evil Knievel#1
Hello,

Im using Muddys bot. I've got a ice sorc that should clear the river of flame but skip it, if there are Grotesques like the "MWConfig_SkipBaalOnDolls" option for the NTBaal script.
As far as I understand it, Ill need a bool var e.g. "MWConfig_SkipRoFOnGrotesques" and I have to modify the RoF script "MWRiverOfFlame".
Code:
/** MWRiverOfFlame.ntj
*	This file was written by [Only registered and activated users can see links. Click Here To Register...]
*	Check the programming section for updates and further scripts
*	Last Update: 16:36 17.08.2011
*/

function NTMain()
{
	Include("libs/common/NTCommon.ntl");
	NTC_IncludeLibs();
	NTC_IncludeConfig("NTBot/char_configs");

	NT_LoadConfig();
	NTSI_LoadNIPFiles("NTBot/item_configs");
	
	MWC_Initialize();
	
	if(!NTTM_CheckAct(me.act, true))
	{
		NTC_SendMsgToScript("MWBotGame.ntj", NTTM_CheckAct, 18, me.act, true);
		return;
	}

	NTTMGR_TownManager();

	if(!NTTM_TownMove("waypoint"))
	{
		NTC_SendMsgToScript("MWBotGame.ntj", NTTM_TownMove, 26, "waypoint");
		return;
	}
	
	if(!NTM_TakeWaypoint(106))
	{
		if(!NTM_TakeWaypoint(107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_TakeWaypoint, 34, 107);
			return;
		}
	}
	else
	{
		if(!NTM_MoveToStair(me.areaid, 107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_MoveToStair, 42, me.areaid, 107);
			return;
		}
		
		if(!NTM_TakeStair(107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_TakeStair, 48, 107);
			return;
		}
	}
	
	NTP_DoPrecast(true);

	NTA_ClearLevel(true, 2, MWConfig_ClearAreaSpectypes.RiverOfFlame);

	NTC_SendMsgToScript("MWBotGame.ntj", "SCRIPT_END");
}
My guess is that Ill need an if statement around the line "NTA_ClearLevel(true, 2, MWConfig_ClearAreaSpectypes.RiverOfFlame);". But Im not sure what I have to write...
The script without modifications will be started with
"MWConfig_Script.push(["MWRiverOfFlame.ntj", 10]); MWConfig_ClearAreaSpectypes.RiverOfFlame = 0x01;".
Ive compared it with the "MWWorldstoneKeep.ntj" script, so my guess is Ill need something like
Code:
if(MWConfig_SkipRoFOnGrotesques && NTC_FindUnit(NTC_UNIT_MONSTER, 300)) // Grotesque ID = 300
{
	if(_area)
		Print("ÿc1Skipping " + _area.name + " due to Grotesques...");		
	continue;
}
03/10/2013 19:21 Muddy Waters#2
You don't really need a bool variable at all, you would only need that if you want to be able to make this an option in your char config.

The essential part is actually this:
Code:
NTC_FindUnit(NTC_UNIT_MONSTER, 300) // I'll just assume that 300 is the correct ID, I honestly don't know...
NTC_FindUnit() will return a linked list of Units representing all nearby monsters with the given classid (i.e. 300). If there are no nearby monsters with that ID, the function will return null (or false?), in any case something that will evaluate to false.

So what we basically need is something like this:
Code:
if(NTC_FindUnit(NTC_UNIT_MONSTER, 300))
{
	// If this block is executed, NTC_FindUnit() will have returned a linked list of monsters which will evaluate to true, meaning that there actually are monsters with the given classid
}
In the statement block we would stop the current script which basically means to use a return statement, since the entire script is merely a JS function which will be stopped immediately on return.

We want to call that before NTA_ClearLevel() is called, since we do not want to clear the area if there happen to be those nasty cold immune monsters around.

That's why said if statement goes right before the NTA_ClearLevel() call, even before the NTP_DoPrecast() call since we don't really need precast if we are not going to clear the area, resulting in this:
Code:
/** MWRiverOfFlame.ntj
*	This file was written by [Only registered and activated users can see links. Click Here To Register...]
*	Check the programming section for updates and further scripts
*	Last Update: 16:36 17.08.2011
*/

function NTMain()
{
	Include("libs/common/NTCommon.ntl");
	NTC_IncludeLibs();
	NTC_IncludeConfig("NTBot/char_configs");

	NT_LoadConfig();
	NTSI_LoadNIPFiles("NTBot/item_configs");
	
	MWC_Initialize();
	
	if(!NTTM_CheckAct(me.act, true))
	{
		NTC_SendMsgToScript("MWBotGame.ntj", NTTM_CheckAct, 18, me.act, true);
		return;
	}

	NTTMGR_TownManager();

	if(!NTTM_TownMove("waypoint"))
	{
		NTC_SendMsgToScript("MWBotGame.ntj", NTTM_TownMove, 26, "waypoint");
		return;
	}
	
	if(!NTM_TakeWaypoint(106))
	{
		if(!NTM_TakeWaypoint(107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_TakeWaypoint, 34, 107);
			return;
		}
	}
	else
	{
		if(!NTM_MoveToStair(me.areaid, 107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_MoveToStair, 42, me.areaid, 107);
			return;
		}
		
		if(!NTM_TakeStair(107))
		{
			NTC_SendMsgToScript("MWBotGame.ntj", NTM_TakeStair, 48, 107);
			return;
		}
	}
	
	if(NTC_FindUnit(NTC_UNIT_MONSTER, 300))
	{
		NTC_SendMsgToScript("MWBotGame.ntj", NTC_FindUnit, 55, 300); // Let's print an error message in manager log
		return; // Stop this function (a.k.a. bot script) right at this point and return undefined
	}
	
	NTP_DoPrecast(true);

	NTA_ClearLevel(true, 2, MWConfig_ClearAreaSpectypes.RiverOfFlame);

	NTC_SendMsgToScript("MWBotGame.ntj", "SCRIPT_END");
}
This is basically how checking for a specific monster type works. Now there are some restrictions, essentially owing to the fact that NTC_FindUnit() can only check for monsters in a limited range (which is about 70 "yards", which is a lot). So if there actually were those Grotesque thingies, but not in a radius of ~70 yards around the waypoint, this little mod could not detect them. In order to make it fully dependable, one would have to edit the NTA_Level() function directly.
That would be a bit more complicated and for most scenarios, not really necessary.
03/10/2013 23:03 Evil Knievel#3
Thanks for the answer. I was missing the info how to end a script via "return;".

Quote:
Originally Posted by Muddy Waters View Post
This is basically how checking for a specific monster type works. Now there are some restrictions, essentially owing to the fact that NTC_FindUnit() can only check for monsters in a limited range (which is about 70 "yards", which is a lot). So if there actually were those Grotesque thingies, but not in a radius of ~70 yards around the waypoint, this little mod could not detect them. In order to make it fully dependable, one would have to edit the NTA_Level() function directly.
That would be a bit more complicated and for most scenarios, not really necessary.
Where can I find the "NTA_Level()" function?

€: Works fine so far doob
03/11/2013 13:22 Muddy Waters#4
Sorry, that was a typo, what I meant to say was NTA_ClearLevel(). :o
03/11/2013 14:33 Evil Knievel#5
Quote:
Originally Posted by Muddy Waters View Post
Sorry, that was a typo, what I meant to say was NTA_ClearLevel(). :o
And where can I find that function? :confused:
03/12/2013 19:15 Muddy Waters#6
Just check the prefix, it always points to the library in which a function is implemented.

In this case the prefix is NTA, hence the function must be implemented in: NTAttack.ntl