Page 1 of 2

Moving FX Lights

Posted: April 19th, 2009, 7:50 pm
by Scorpion
Hello

Is there any Tutorials out there for Moving FX Lights?

Thanks 8)

Re: Moving FX Lights

Posted: April 19th, 2009, 8:11 pm
by waywaaaard
moving your FX shouldn't be that hard, only creating your light in effectsed could take some time

Re: Moving FX Lights

Posted: April 20th, 2009, 4:29 am
by Nightmare
Hark! What is that in the sky? Is it a bird, a plane? No! It's NM coming to save the day!

Moving lights isn't that hard in theory, all it takes is a moving effect that will play a light effect, which can be custom.

So first, with the mapping.
Very simple if you know how to create your typical entities.
In this case, all you have to do is spawn a script_origin by right clicking on the 2d grid and selecting script then origin.
Now you want to give it values, you can use the example below, but I highly advise putting your map name in front to avoid conflicting.
Key: targetname
Value: fxOrigin

That's all it takes for the mapping part.

Now on to the scripting.
First off, you will need to make a brand new effect, and lucky you, I have a light emiting effect here just for you!
Now I'm going to assume you know how to make a pk3 file, so beside your maps, mp, and levelshots folder, you will want to make another folder called fx. In this folder, you can put an extra folder with your map name to avoid conflicting.
I went ahead and put another folder called myFxFolder inside the fx folder.
Now make a txt file in this folder, and paste the following.

Code: Select all

Light
{
	life				1000   //Length of time the light is on in milliseconds, 1000 = 1 second

	rgb   //Color of the light can be changed here, with Red Green Blue (2.55 2.55 2.55 = White)
	{
		start	2.55 2.55 2.55   //Color of the light at the beginning of its life
		end		2.55 2.55 2.55   //Color of the light at the end of its life
		flags			linear
	}

	size
	{
		start			250   //Intensity of the light at the beginning of its life
		end				250   //Intensity of the light at the end of its life
		flags			linear
	}
}
This is the code to give off a light effect, you can modify the variables to your liking to fit your needs.
Now when saving the file, make sure that it is saved as an efx file. I called this file myLight.efx

Now for the actual map scripting.
I'm going to assume you know the basics of how to script for a map, such as making a gsc file and how to code simple movements.
So here, we want to both play an effect and make it move, so I will be running two threads in parallel.

Code: Select all

main()
{
	maps\mp\_load::main();   //Load main functions
	lightOrigin = getent ("fxOrigin","targetname");   //Assign the fxOrigin entity to lightOrigin
	level._effect["light"] = loadfx ("fx/myFxFolder/myLight.efx");  //Load myLight effect from myFxFolder
	maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.
	lightOrigin thread lightsMove();   //Run moving light thread while sending assigned lightOrigin
}

lightsMove(){    //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
   while(1){
      self moveX (64,1,0.5,0.5);
      self waittill ("movedone");
      self moveX (-64,1,0.5,0.5);
      self waittill ("movedone");
   }
}
That's about it. Now of course, if you have any questions, just ask, I'll explain a little more in detail if you don't understand.
Feel free to modify it however you want.

Re: Moving FX Lights

Posted: April 20th, 2009, 3:24 pm
by Rezil
Wow awesome tut nm, do you think this will work in cod2 aswell?

Re: Moving FX Lights

Posted: April 20th, 2009, 9:12 pm
by Scorpion
Thanks for the Tutorial :D

Instead of lights , there is flames :roll:

Re: Moving FX Lights

Posted: April 20th, 2009, 10:54 pm
by Nightmare
Rez|l wrote:Wow awesome tut nm, do you think this will work in cod2 aswell?
I don't see why it shouldn't
Scorpion wrote:Thanks for the Tutorial :D

Instead of lights , there is flames :roll:
Are you sure? What kind of flames is it?
The reason I am asking is because if the flames go very high into the sky, then that is the error.efx playing.
This effect usually plays when it cannot find the efx file you are refering to, so make sure to double check the path and file name.

Re: Moving FX Lights

Posted: April 21st, 2009, 8:25 pm
by Drofder2004
And make sure you simply haven't copied and pasted NM's script (which we all know, you have).
You need to change the FX file location in both script and folder.

Re: Moving FX Lights

Posted: April 22nd, 2009, 6:46 pm
by Scorpion
Hi , Finally Works :D (I was using the compile MP folder and it didnt like it, so i placed into a pk3 and it worked :lol: )

Iv tried to add a trigger to it

Code: Select all

main()
{
   maps\mp\_load::main();   //Load main functions
   lightOrigin = getent ("fxOrigin","targetname");   //Assign the fxOrigin entity to lightOrigin
   trigger = getent ("lighttrigger","targetname");
   level._effect["light"] = loadfx ("fx/light/light.efx");  //Load myLight effect from myFxFolder
   maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.
   lightOrigin thread lightsMove();   //Run moving light thread while sending assigned lightOrigin
}

lightsMove(){    //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
   while(1)
      {
      trigger waittill ("trigger");
      wait(1);
      lightOrigin moveZ (-1000,1,0.5,0.5);
      lightOrigin waittill ("movedone");
      wait(10);      
      lightOrigin moveZ (1000,1,0.5,0.5);
      lightOrigin waittill ("movedone");
   }
}


The light shows up but it doesnt move up or down with the trigger or without the trigger.

Any ideas?

Thanks :)

Re: Moving FX Lights

Posted: April 22nd, 2009, 7:31 pm
by waywaaaard
main()
{
maps\mp\_load::main(); //Load main functions
lightOrigin = getent ("fxOrigin","targetname"); //Assign the fxOrigin entity to lightOrigin
trigger = getent ("lighttrigger","targetname");
level._effect["light"] = loadfx ("fx/light/light.efx"); //Load myLight effect from myFxFolder
maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.
lightOrigin thread lightsMove(); //Run moving light thread while sending assigned lightOrigin
}

lightsMove(){ //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
while(1)
{
trigger waittill ("trigger");
wait(1);
self moveZ (-1000,1,0.5,0.5);
self waittill ("movedone");
wait(10);
self moveZ (1000,1,0.5,0.5);
self waittill ("movedone");
}
}

Re: Moving FX Lights

Posted: April 22nd, 2009, 7:40 pm
by Scorpion
Hi

Doesnt work

The light shows but doesnt go up / down.

Iv checked the names etc and there right

I took out the trgger part of it and it still doesnt work :shock:

Any idea?

Thanks :)

Re: Moving FX Lights

Posted: April 23rd, 2009, 2:11 am
by Nightmare
Scorpion wrote:Hi , Finally Works :D (I was using the compile MP folder and it didnt like it, so i placed into a pk3 and it worked :lol: )

Iv tried to add a trigger to it

CODE

The light shows up but it doesnt move up or down with the trigger or without the trigger.

Any ideas?

Thanks :)
Obvious problem is very obvious, you are defining what trigger is all the way in the main, but for the game, by the time it gets to that thread, it has forgotten about it. (Lev made the same mistake. :))
Two solutions, make trigger a level wide variable or define it in the movement thread.
I chose the later for simplicity.

Code: Select all

main()
{
	maps\mp\_load::main();   //Load main functions
	lightOrigin = getent ("fxOrigin","targetname");   //Assign the fxOrigin entity to lightOrigin
	level._effect["light"] = loadfx ("fx/light/light.efx");  //Load myLight effect from myFxFolder
	maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.
	lightOrigin thread lightsMove();   //Run moving light thread while sending assigned lightOrigin
}

lightsMove(){    //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
	while(1)
	{
		trigger = getent ("lighttrigger","targetname");
		trigger waittill ("trigger");
		wait(1);
		self moveZ (-1000,1,0.5,0.5);
		self waittill ("movedone");
		wait(10);      
		self moveZ (1000,1,0.5,0.5);
		self waittill ("movedone");
	}
}
You can also have it so the light turns on and stays on only after you press the trigger by doing this:

Code: Select all

main()
{
	maps\mp\_load::main();   //Load main functions
	lightOrigin = getent ("fxOrigin","targetname");   //Assign the fxOrigin entity to lightOrigin
	level._effect["light"] = loadfx ("fx/light/light.efx");  //Load myLight effect from myFxFolder
	lightOrigin thread lightsMove();   //Run moving light thread while sending assigned lightOrigin
}

lightsMove(){    //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
	while(1)
	{
		trigger = getent ("lighttrigger","targetname");
		trigger waittill ("trigger");
		maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.
		wait(1);
		self moveZ (-1000,1,0.5,0.5);
		self waittill ("movedone");
		wait(10);      
		self moveZ (1000,1,0.5,0.5);
		self waittill ("movedone");
	}
}

Re: Moving FX Lights

Posted: April 23rd, 2009, 7:26 am
by waywaaaard
oopsy, was reading to fast -.-

yep no trigger was defined

Re: Moving FX Lights

Posted: April 23rd, 2009, 2:45 pm
by Drofder2004
small modification to the above...

Code: Select all

lightsMove(){    //Move lightOrigin back and forth along the X axis 64 units while looping continuously.
   trigger = getent ("lighttrigger","targetname");
   maps\mp\_fx::loopfx("light",lightOrigin.origin, 1); //Play loaded light effect at lightOrigin's origin every sec.

   while(1)
   {     
      trigger waittill ("trigger");
      wait(1);
      self moveZ (-1000,1,0.5,0.5);
      self waittill ("movedone");
      wait(10);     
      self moveZ (1000,1,0.5,0.5);
      self waittill ("movedone");
   }
}
Firstly, remember this is an INFINITE LOOP, why would you want the engine to find the entity more than once if it isn't changing? Keep it outside the loop.

Secondly, Loops inside loops = infinite amounts of infinite loops.
Every time the loop went round, it created a NEW fx to play, after 1 minute passing you would have 6, eventually stacking to the point where your FPS would be shot and the server would crash.

Re: Moving FX Lights

Posted: April 23rd, 2009, 5:25 pm
by Scorpion
Hello

The light still shows up but it doesnt move. :roll:

Any Ideas?

Thanks

Re: Moving FX Lights

Posted: April 23rd, 2009, 10:01 pm
by Drofder2004
Are you definitely using a script_origin?