A to Z Scripting: Getting map information

From The DarkMod Wiki
Revision as of 11:00, 21 December 2020 by Dragofer (talk | contribs) (Created page with "== Getting map information == Your scripts unlock much potential if they can see and react to what's happening in the map. The way to get up-to-date information about the sta...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Getting map information

Your scripts unlock much potential if they can see and react to what's happening in the map. The way to get up-to-date information about the state and properties of entities is with "get" script events. There are a lot of them, and as said they have a ton of potential.


Often you'll store their results as a variable, like this:

float health_current = $lord_marlow.getHealth();	//Lord Marlow's current health

Or use them directly in a conditional:

if ($lord_marlow.getHealth() < 100)			//If Lord Marlow has been hurt...


Getting spawnargs

Spawnargs are a special case. All spawnargs are strings, so if you want to store them as a variable you need to choose a "get" event which converts them into the matching data type:

string name		= $mover.getKey("name");		//for strings
float move_time		= $mover.getFloatKey("move_time");	//for floats
vector rotate		= $mover.getVectorKey("rotate");	//for vectors
boolean open		= $mover.getBoolKey("open");		//for booleans
entity frob_master	= $mover.getEntityKey("frob_master");	//for entities


Example: checking an AI's health for a "No harm" objective

This script is for an objective to let no harm come to an AI. It would check the AI's "health" spawnarg to find what his max health is, then compare that with the AI's current health. If there's a difference, the objective fails.

void check_health()
{
	float health_max	= $lord_marlow.getFloatKey("health"); 			//find max health by checking the spawnarg
	float health_current	= $lord_marlow.getHealth();				//get current health

	if(health_current != health_max) $player1.setObjectiveState(5, OBJ_FAILED);	//if health is no longer max, set objective 5 to failed

	sys.wait(0.5);			//wait 0.5s...
	thread check_health();		//... before repeating this whole script
}


Next / previous article