Call of Duty 5: Using FXs Client Scripts

From COD Modding & Mapping Wiki
Jump to navigation Jump to search

This tutorial will explain how to use the same method used by Treyarch in the Stock Maps to spawn FXs on the Clientside to ease server load.

Theory

The method might look very similar to the one used in Call of Duty 4 Modern Warfare but it isnt at all. The serverside scripting used is indeed the same, the different is the use now of CSC scripts or ClientSide Script (as opposed to GSC).

The principle is simple, the server gets the FX scripting but doesnt draw them for clients, instead the Clientside Script will draw the FXs and this for each Client connected. The result is that as FXs are locally drawn by and for each Clients the Server load is lighter and lag is reduced.

Everywhere in this tutorial mp_mapname MUST be replaced by your level name, in this example its mp_example

Server Side Script

The serverside scripting is the same method as COD4:

In this example I will use the following FX: mp_smoke_column_tall -- All files for the below example can be found at the bottom of the Tutorial.

CreateFX script

  • If not already there, create a folder createfx under \raw\maps\mp
  • In that folder create a new file called mp_mapname_fx.gsc, in it put the following
//_createfx generated. Do not touch!!
main()
{
     	ent = maps\mp\_utility::createOneshotEffect( "mp_smoke_column_tall" );
     	ent.v[ "origin" ] = ( X, Y, Z );
     	ent.v[ "angles" ] = ( 270, 0, 0 );
     	ent.v[ "fxid" ] = "mp_smoke_column_tall";
     	ent.v[ "delay" ] = -15;
}

Explanation for each line above:

//_createfx generated. Do not touch!!
  • This line simply needs to be there!
ent = maps\mp\_utility::createOneshotEffect( "mp_smoke_column_tall" );
  • This line is the call for the FX id, in this case mp_smoke_column_tall
ent.v[ "origin" ] = ( X, Y, Z );

This line is very Important. X, Y, Z are the coordinate where you wish to place your FX. The best way to find the coordiantes required is to go in Radiant, then place a Script_origin where you want the FX and press 'N' when selecting it to get the X,Y,Z coordinates.



ent.v[ "angles" ] = ( 270, 0, 0 );
  • This line is as it says the Angle parameters, in the example the FX will be pointing towards sky (smoke ascending)
ent.v[ "fxid" ] = "mp_smoke_column_tall";
  • This line is the FX id, it needs to match with the first call to the same FX id.
ent.v[ "delay" ] = -15;
  • This last line is the delay to start the FX, keep it untouched at -15.

As in COD4 you could add one more line to this to load a Soundalias:

ent.v[ "soundalias" ] = soundalias;

We however wont use it for this example.

The final script used for the example is as follow:

//_createfx generated. Do not touch!!
main()
{
     	ent = maps\_utility::createOneshotEffect( "mp_smoke_column_tall" );
     	ent.v[ "origin" ] = ( -16, 544, 56 );
     	ent.v[ "angles" ] = ( 270, 0, 0 );
     	ent.v[ "fxid" ] = "mp_smoke_column_tall";
     	ent.v[ "delay" ] = -15;
}

Map FX file

Under raw/maps/mp/ create another file called mp_mapname_fx.gsc

  • Have the following in it:
#include maps\mp\_utility;

main()
{
	//maps\mp\createart\mp_mapname_art::main();
	precacheFX();
	spawnFX();
}

precacheFX()
{
	level._effect["mp_smoke_column_tall"] = loadfx("maps/mp_maps/fx_mp_smoke_column_tall");	
}

spawnFX()
{
	if (( getdvar( "createfx" ) != "" ))
	{
		maps\mp\createfx\mp_mapname_fx::main();
	}
}

Map GSC calls

You now need to call the created Files in your Map GSC

  • In your raw/maps/mp/mp_mapname.gsc put the following after maps\mp\_load::main();
maps\mp\mp_mapname_fx::main();

Zone File

  • Last step, in your zone_source/mp_mapname.csv add this line:
fx,maps/mp_maps/fx_mp_smoke_column_tall

Client Side Script

This is the new bit compare to COD4, you knwo have to create CSC files

 Note the extension used here isnt .gsc but .csc

CreateFX file

  • If not already there, create a folder createfx under raw\clientscripts\mp\createfx
  • In that folder create a new file the file mp_mapname_fx.csc:
  • Inside:
//_createfx generated. Do not touch!!
main()
{
     	ent = clientscripts\_fx::createOneshotEffect( "mp_smoke_column_tall" );
     	ent.v[ "origin" ] = ( -16, 544, 56 );
     	ent.v[ "angles" ] = ( 270, 0, 0 );
     	ent.v[ "fxid" ] = "mp_smoke_column_tall";
     	ent.v[ "delay" ] = -15;
}


Map FX file

  • Again, create a new file mp_mapname_fx.csc under
raw\clientscripts\mp\
  • Inside:
#include clientscripts\mp\_utility; 


// load fx used by util scripts
precache_util_fx()
{	
}

precache_scripted_fx()
{
}

// --- AMBIENT SECTION ---//
precache_createfx_fx()
{

	level._effect["mp_smoke_column_tall"] = loadfx("maps/mp_maps/fx_mp_smoke_column_tall");	
  
}


main()
{
	clientscripts\mp\createfx\mp_mapname_fx::main();
	clientscripts\mp\_fx::reportNumEffects();
	
	precache_util_fx();
	precache_createfx_fx();
	
	disableFX = GetDvarInt( "disable_fx" );
	if( !IsDefined( disableFX ) || disableFX <= 0 )
	{
		precache_scripted_fx();
	}
}

Map CSC calls

  • You now need to create a new file similar to your Map GSC
  • Assuming your Map GSC in \raw\maps\mp\ is like this:
main()
{
	maps\mp\_load::main();
	
	// If the team nationalites change in this file,
	// you must update the team nationality in the level's csc file as well!
	game["allies"] = "russian";
	game["axis"] = "german";
	game["attackers"] = "axis";
	game["defenders"] = "allies";
	game["allies_soldiertype"] = "russian";
	game["axis_soldiertype"] = "german";

}

Then create a new file mp_mapname.csc under \raw\clientscripts\mp\ with the following in:

#include clientscripts\mp\_utility;

main()
{
	// If the team nationalites change in this level's gsc file,
	// you must update the team nationality here!
	level.allies_team = "german";
	level.axis_team   = "russian";

	// _load!
	clientscripts\mp\_load::main();
	clientscripts\mp\mp_mapname_fx::main();

	thread clientscripts\mp\_fx::fx_init(0);
	thread clientscripts\mp\_audio::audio_init(0);

	// This needs to be called after all systems have been registered.
	thread waitforclient(0);

	println("*** Client : mp_example running...");
}

Zone File

  • Now open your Zone file again and add this:
rawfile,clientscripts/mp/mp_mapname.csc
rawfile,clientscripts/mp/mp_mapname_fx.csc
rawfile,clientscripts/mp/createfx/mp_mapname_fx.csc


Compile and enjoy Lag-free FX in map!

Download the files

All files in this example are available HERE