Small scripting samples

From time to time I'll try to present some small scripting samples. As I'm a beginner with REDkit scripting
they all will be "derived" from existing REDkit scripts.
Every sample will be tested/debugged using the Script Studio.
(So if a sample doesn't work for you think about this.)



How to test a sample


For testing you could use the following method (if not otherwise stated in a sample's description):
Copy the sample code BEFORE class CGuiFastMenu in guifastmenu.ws.
Copy the function call of the sample into event OnOpenPanel().
It's MySpawn() for the first sample.

Press icon "Connect to running game" and press F7 (Reload scripts).
Then in REDkit (with a loaded level of course) press left CTRL ingame.
Script should be performed.

If it doesn't work set a breakpoint (BP) on MySpawn(). After pressing left CTRL ingame
the game should freeze; means: the breakpoint's being hit.
Continue wiith F5 in Script studio.


Spawning a Nekker at a given x,y,z, position


The nekker will be spawned near Einar Gausel's bed.
To get your own positions place the line
pos = thePlayer.GetWorldPosition();
after MySpawn() ;

(You also need var pos : Vector; to be copied to event OnOpenPanel() code of course.)
After the above mentioned BP being hit check the x,y,z values of pos in the Locals tab and copy them to
entry function SpawnNekker()

Spawning a nekker
// modified by shak from temp.ws
class NekkerSpawner extends CStateMachine
{
}
state Spawning in NekkerSpawner
{
	var tmpl1 : CEntityTemplate;
	var pos : Vector;
	var rot : EulerAngles;

	entry function SpawnNekker()
	// you can't call spawnNekker() directly because the Latent function 'LoadResource'
	// can be called only from inside of state entry or latent function
	{
		//pos.X = 236.0f; pos.Y = 204.0f; pos.Z = 2.5f;	//cellar pub Flotsam
		pos.X = 253.0f; pos.Y = 247.0f; pos.Z = 9.0f;	// near Einar Gausel's bed
		rot.Yaw = 0.0f; rot.Pitch = 0.0; rot.Roll = 0.0;	
		tmpl1 = (CEntityTemplate)LoadResource("nekker_strong");
		theGame.CreateEntity(tmpl1, pos, rot);
	}
}
exec function MySpawn()
{	
	var spawner : NekkerSpawner;
	spawner = new NekkerSpawner in theGame;

	spawner.SpawnNekker();
}


example 2

...

example 3

...