Difference between revisions of "Hotspot Scripting"

From Wolfire Games Wiki
Jump to: navigation, search
(Created page with "In Overgrowth you can use hotspots to trigger certain events. For example give health, add velocity to character or change the level. <pre> //Variables can be created outside an...")
(No difference)

Revision as of 21:41, 13 February 2015

In Overgrowth you can use hotspots to trigger certain events. For example give health, add velocity to character or change the level.

//Variables can be created outside any function, these will be available to all following functions.
float force;
int friendly;
void Init() {
	//Inside the init function you can put something that only needs to happen once.
	Print("Initializing hotspot\n");
}
//Inside the SetParameters function you can set declare variables that the user can change. By selecting the hotspot and press Ctrl + U the parameters will be available to the user.
void SetParameters() {
	params.AddString("Upward force", "5.0");
	//You can either assign the parameter to a variable straight away or fetch it when it is used.
	force = params.GetFloat("Upward force");
	//Sliders can be usefull for the user to quickly change parameters.
	params.AddFloatSlider("Recovery Time", 1.0f, "min:0.0,max:50.0");
	//You can add checkboxes for simple on/off functions.
	params.AddIntCheckbox("Friendly", false);
    friendly = (params.GetInt("Friendly") == 1);
}
//You can check for a character or an item to enter or exit the hotspot.
void HandleEvent(string event, MovementObject @mo){
	//Here we check if a character enters the hotspot.
    if(event == "enter"){
        OnEnterChar(mo);
    }
	//The function "OnExitChar()" will be called if a character exits teh hotspot
    else if(event == "exit"){
        OnExitChar(mo);
    }
}
//The same technique can be used for an item. 
Note: There is a difference between an ItemObject and an Object. An ItemObject is affected by gravity, such as weapons and collectables. 
An Object is static for example a hexcrete or joshua tree.
void HandleEventItem(string event, ItemObject @obj){
    if(event == "enter"){
        OnEnterItem(obj);
    } 
    if(event == "exit"){
        OnExitItem(obj);
    } 
}

void OnEnterItem(ItemObject @obj) {
	if(obj.GetType() == _collectable){
		Print("A " + obj.GetType() + " item has entered the hotspot\n")
	}
	//An item can just like a character have it's properties changed via a hotspot.
	vec3 vel(0.0f,15.5f,0.0f);
	obj.SetLinearVelocity(vel);
}

void OnExitItem(ItemObject @obj) {
	
}
void OnEnterChar(MovementObject @mo) {
	//To check if the character is the user you can check if it is a controller MovementObject.
	if(mo.controlled){
		Print("A user has entered the hotspot\n")
		//If you choose to retrieve the parameter as needed you can request by name.
		mo.velocity.y = params.GetFloat("Upward force");
	}
	else{
		Print("An NPC has entered the hotspot\n");
	}
	//You can create effects with MakeParticle.The first parameter is the particle file to load. The second parameter is the position in the world to spawn this particle. The last parameter is the direction the particle is moving. The higher the values the faster it will move.
	MakeParticle("Data/Particles/fire.xml", mo.position,vec3(0.0f,15.0f,0.0f));

	//Certain functions are only accessible if you go through the Execute() function. These can contain multiple functions and even parameters.
	mo.Execute("SetOnGround(false);DropWeapon();recovery_time = "+params.GetFloat("Recovery time")+";");
	
	//The level itself can also receive various function
	level.SendMessage("loadlevel \"/Data/Levels/sea_cliffs.xml");
	
	//To put some text on the screen in stead of the console you can use.
	level.SendMessage("displaytext Test Message");
	//And to clear it.
	level.SendMessage("cleartext");

	//You can also reset the level.
	level.SendMessage("reset");

	//If you want to put an image onto the screen
	level.SendMessage("displayhud /Data/Textures/twisted_paths.png");
	//And to remove this again use
	level.SendMessage("clearhud");

	//To play a sound you use the PlaySound function. The second parameter to specify the location is optional. Make sure the audio file mono or else the positional effect won't work.
	PlaySound("Data/Sounds/fall_swoosh.wav", mo.position);

	//To get a random value you can use RangedRandomFloat. This will be usefull for example with particle effects.
	float direction = RangedRandomFloat(-100.0f,100.0f);

	//To spawn objects you can use the CreateObject function. This can be an Object, ItemObject or Character.
	int objectid = CreateObject("Data/Objects/rock.xml");
	//The function return an id number which you can use to get the Object. Now the Object can be manipulated.
	[email protected] objectid = ReadObjectFromID(obj_id);
	//If the object is character use the MovementObject type.
	[email protected] character = ReadCharacterID(objectid);
	//If the object is a plant use the EnvObject type.
	[email protected] plant = ReadEnvObjectID(objectid);
	//If the object is weapon or collectable use the ItemObject type.
	[email protected] weapon = ReadItemID(objectid);

	//The hotspot is also an object inside the game. You can also move and resize it.
	[email protected] this_hotspot = ReadObjectFromID(hotspot.GetID());
}
void OnExitChar(MovementObject @mo) {


}
//The Update() function will continue to execute as long as the hotspot is loaded. It does not need to be triggered.
void Update() {	

}