Modme Forums
Menu:

Usable flashlight

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: Noah Gamerscore
So I'm creating a L4D2 map in Bo3 and right now its quite dark and hard to see. I was going to fix it but then I realized that in L4D2 there was a flashlight you can use while holding your weapon. I know its possible because I've played a map on the workshop that has a usable flashlight that can be turned on and off. If anyone can help me out with this, I would be so grateful! Thanks again in advance.


ModmeBot:

Reply By: dreamzyy

Heres the source of the flashlight I used on lostplace :)
Including FX, scripts and sounds.

Downloadedit:
- removed 1 line of code that i forgot to delete


ModmeBot:

Reply By: Noah Gamerscore

dreamzyy
Heres the source of the flashlight I used on lostplace :) Including FX, scripts and sounds.

you are sooooooo amazing. Thank you so much. You don't know how much this means to me!!!
And btw, I LOVE lostplace, such a beautiful map and you did an amazing job on it :)


ModmeBot:

Reply By: iAr7uRo

dreamzyy
Heres the source of the flashlight I used on lostplace :) Including FX, scripts and sounds.

Thanks for the released. I also want to use the flashlight on my map, but I miss this error when I run my map.
Why this happens or what I need to add to make it work.
I put all the scripts in the place that they go correctly, I do not know what is wrong or what happens.

Image error help :(


ModmeBot:

Reply By: mathfag

iAr7uRo
dreamzyy Heres the source of the flashlight I used on lostplace :) Including FX, scripts and sounds. Thanks for the released. I also want to use the flashlight on my map, but I miss this error when I run my map.Why this happens or what I need to add to make it work.I put all the scripts in the place that they go correctly, I do not know what is wrong or what happens. Imagen error help :(

You didn't thread something correctly on line 453


ModmeBot:

Reply By: Harry Bo21
no....


he did not add the #using line for the script....


ModmeBot:

Reply By: iAr7uRo

Harry Bo21
no.... he did not add the #using line for the script....


<em>This is all the .gsc content I put in the correct order, but you say that #using is missing, I have no idea how to call that function,
nor is it in the script that I just attached.</em>

// dont replace anything in your .csc, only add stuff :)

function main()
{
	//// CLIENTFIELDS //// ##############################################################################

    clientfield::register( "toplayer",		"flashlight_fx_view",			VERSION_SHIP, 1, "int" );
    clientfield::register( "allplayers",	"flashlight_fx_world",			VERSION_SHIP, 1, "int" );

    //-&gt; Add callback after zm_usermap::main();

	callback::on_connect 	( &amp;on_player_connect );
}


function on_player_connect()
{
	self thread flashlight_init();
}

function flashlight_init()
{
	self.flashlight_enabled = true;

	self clientfield::set_to_player( "flashlight_fx_view", 1 ); // Flashlight is enabled on spawn
	self clientfield::set( "flashlight_fx_world",	 1 );		// Flashlight is enabled on spawn

	self thread flashlight_watch_usebutton(); // This is the line where I mark error when running the game
	self thread flashlight_watch_orgelweap(); // This is the line where I mark error when running the game
}

function flashlight_watch_usebutton()
{
	self endon( "kill_flashlight" );
	
	while( 1 )
	{
		if( self UseButtonPressed() )
		{
			catch_next = false;
			for( i = 0; i &lt;= 0.5; i += 0.05 )
			{
				if( catch_next &amp;&amp; self UseButtonPressed() )
				{
					if( !self.flashlight_enabled )
					{
						self flashlight_state( "ON" );
						wait 1;
						break;
					}

					else
					{
						self flashlight_state( "OFF" );
						wait 1;
						break;
					}
				}

				else if( !( self UseButtonPressed() ) )
					catch_next = true;

				wait 0.05;
			}
		}
		wait 0.05;
	}
}

function flashlight_state( state )
{
	if( !isdefined( state ) )
		break;

	if( state == "ON" )
	{
		self clientfield::set_to_player( "flashlight_fx_view", 1 );
		self clientfield::set( "flashlight_fx_world",	 1 );
		self.flashlight_enabled = true;
		break;
	}

	if( state == "OFF" )
	{
		self clientfield::set_to_player( "flashlight_fx_view", 0 );
		self clientfield::set( "flashlight_fx_world",	 0 );
		self.flashlight_enabled = false;
		break;
	}
}

This is all stuff .csc and same i put in correct order.
// dont replace anything in your .csc, only add stuff :)

#precache ("client_fx", "custom/flashlight/flashlight_loop");
#precache ("client_fx", "custom/flashlight/flashlight_loop_world");
#precache ("client_fx", "custom/flashlight/flashlight_loop_view_moths");

function main()
{
    //// LEVEL EFFECTS //// ##############################################################################

    level._effect[ "flashlight_fx_loop_view" ]          = "custom/flashlight/flashlight_loop";
    level._effect[ "flashlight_fx_loop_view_moths" ]    = "custom/flashlight/flashlight_loop_view_moths";
    level._effect[ "flashlight_fx_loop_world" ]         = "custom/flashlight/flashlight_loop_world";

    //// CLIENTFIELDS //// ##############################################################################

    clientfield::register( "toplayer",      "flashlight_fx_view",           VERSION_SHIP, 1, "int", &amp;flashlight_fx_view,        !CF_HOST_ONLY, !CF_CALLBACK_ZERO_ON_NEW_ENT );
    clientfield::register( "allplayers",    "flashlight_fx_world",          VERSION_SHIP, 1, "int", &amp;flashlight_fx_world,       !CF_HOST_ONLY, !CF_CALLBACK_ZERO_ON_NEW_ENT );
}

//// FLASHLIGHT //// ##############################################################################

function flashlight_fx_view( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump ) // self == player
{
    if ( newVal )
    {
        if ( isdefined( self.fx_flashlight_view ) )
            KillFx( localClientNum, self.fx_flashlight_view );

        if ( isdefined( self.fx_flashlight_moth ) )
            KillFx( localClientNum, self.fx_flashlight_moth );

        flash_fx_view = level._effect[ "flashlight_fx_loop_view" ];
            self.fx_flashlight_view = PlayViewmodelFx( localclientnum, flash_fx_view, "tag_flash" ); 

        flash_fx_moth = level._effect[ "flashlight_fx_loop_view_moths" ];
            self.fx_flashlight_moth = PlayFxOnTag( localClientNum, flash_fx_moth, self, "j_spine4" );

        playsound( localClientNum, "1_flashlight_click", self.origin ); 
    }

    else
    {
        if ( isdefined( self.fx_flashlight_view ) )
        {
            KillFx( localClientNum, self.fx_flashlight_view );
                self.fx_flashlight_view = undefined;

            playsound( localClientNum, "1_flashlight_click", self.origin ); 
        }

        if ( isdefined( self.fx_flashlight_moth ) )
        {
            KillFx( localClientNum, self.fx_flashlight_moth );
                self.fx_flashlight_moth = undefined;
        }
    }
}

function flashlight_fx_world( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump ) // self == player
{
    if ( newVal )
    {
        curr_player = GetLocalPlayer( localClientNum );

        if ( isdefined( self.fx_flashlight_world ) )
            KillFx( localClientNum, self.fx_flashlight_world );

        if( curr_player != self )
        {
            flash_fx_world = level._effect[ "flashlight_fx_loop_world" ];
                self.fx_flashlight_world = PlayFxOnTag( localClientNum, flash_fx_world, self, "tag_flash" );
        }
    }

    else
    {
        if ( isdefined( self.fx_flashlight_world ) )
        {
            KillFx( localClientNum, self.fx_flashlight_world );
                self.fx_flashlight_world = undefined;
        }
    }
}


ModmeBot:

Reply By: Noah Gamerscore

iAr7uRo
Harry Bo21 no.... he did not add the #using line for the script.... This is all the .gsc content I put in the correct order, but you say that #using is missing, I have no idea how to call that function,nor is it in the script that I just attached. // dont replace anything in your .csc, only add stuff :) function main() { //// CLIENTFIELDS //// ############################################################################## clientfield::register( "toplayer", "flashlight_fx_view", VERSION_SHIP, 1, "int" ); clientfield::register( "allplayers", "flashlight_fx_world", VERSION_SHIP, 1, "int" ); //-> Add callback after zm_usermap::main(); callback::on_connect ( &on_player_connect ); } function on_player_connect() { self thread flashlight_init(); } function flashlight_init() { self.flashlight_enabled = true; self clientfield::set_to_player( "flashlight_fx_view", 1 ); // Flashlight is enabled on spawn self clientfield::set( "flashlight_fx_world", 1 ); // Flashlight is enabled on spawn self thread flashlight_watch_usebutton(); // This is the line where I mark error when running the game self thread flashlight_watch_orgelweap(); // This is the line where I mark error when running the game } function flashlight_watch_usebutton() { self endon( "kill_flashlight" ); while( 1 ) { if( self UseButtonPressed() ) { catch_next = false; for( i = 0; i <= 0.5; i += 0.05 ) { if( catch_next && self UseButtonPressed() ) { if( !self.flashlight_enabled ) { self flashlight_state( "ON" ); wait 1; break; } else { self flashlight_state( "OFF" ); wait 1; break; } } else if( !( self UseButtonPressed() ) ) catch_next = true; wait 0.05; } } wait 0.05; } } function flashlight_state( state ) { if( !isdefined( state ) ) break; if( state == "ON" ) { self clientfield::set_to_player( "flashlight_fx_view", 1 ); self clientfield::set( "flashlight_fx_world", 1 ); self.flashlight_enabled = true; break; } if( state == "OFF" ) { self clientfield::set_to_player( "flashlight_fx_view", 0 ); self clientfield::set( "flashlight_fx_world", 0 ); self.flashlight_enabled = false; break; } } This is all stuff .csc and same i put in correct order. // dont replace anything in your .csc, only add stuff :) #precache ("client_fx", "custom/flashlight/flashlight_loop"); #precache ("client_fx", "custom/flashlight/flashlight_loop_world"); #precache ("client_fx", "custom/flashlight/flashlight_loop_view_moths"); function main() { //// LEVEL EFFECTS //// ############################################################################## level._effect[ "flashlight_fx_loop_view" ] = "custom/flashlight/flashlight_loop"; level._effect[ "flashlight_fx_loop_view_moths" ] = "custom/flashlight/flashlight_loop_view_moths"; level._effect[ "flashlight_fx_loop_world" ] = "custom/flashlight/flashlight_loop_world"; //// CLIENTFIELDS //// ############################################################################## clientfield::register( "toplayer", "flashlight_fx_view", VERSION_SHIP, 1, "int", &flashlight_fx_view, !CF_HOST_ONLY, !CF_CALLBACK_ZERO_ON_NEW_ENT ); clientfield::register( "allplayers", "flashlight_fx_world", VERSION_SHIP, 1, "int", &flashlight_fx_world, !CF_HOST_ONLY, !CF_CALLBACK_ZERO_ON_NEW_ENT ); } //// FLASHLIGHT //// ############################################################################## function flashlight_fx_view( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump ) // self == player { if ( newVal ) { if ( isdefined( self.fx_flashlight_view ) ) KillFx( localClientNum, self.fx_flashlight_view ); if ( isdefined( self.fx_flashlight_moth ) ) KillFx( localClientNum, self.fx_flashlight_moth ); flash_fx_view = level._effect[ "flashlight_fx_loop_view" ]; self.fx_flashlight_view = PlayViewmodelFx( localclientnum, flash_fx_view, "tag_flash" ); flash_fx_moth = level._effect[ "flashlight_fx_loop_view_moths" ]; self.fx_flashlight_moth = PlayFxOnTag( localClientNum, flash_fx_moth, self, "j_spine4" ); playsound( localClientNum, "1_flashlight_click", self.origin ); } else { if ( isdefined( self.fx_flashlight_view ) ) { KillFx( localClientNum, self.fx_flashlight_view ); self.fx_flashlight_view = undefined; playsound( localClientNum, "1_flashlight_click", self.origin ); } if ( isdefined( self.fx_flashlight_moth ) ) { KillFx( localClientNum, self.fx_flashlight_moth ); self.fx_flashlight_moth = undefined; } } } function flashlight_fx_world( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump ) // self == player { if ( newVal ) { curr_player = GetLocalPlayer( localClientNum ); if ( isdefined( self.fx_flashlight_world ) ) KillFx( localClientNum, self.fx_flashlight_world ); if( curr_player != self ) { flash_fx_world = level._effect[ "flashlight_fx_loop_world" ]; self.fx_flashlight_world = PlayFxOnTag( localClientNum, flash_fx_world, self, "tag_flash" ); } } else { if ( isdefined( self.fx_flashlight_world ) ) { KillFx( localClientNum, self.fx_flashlight_world ); self.fx_flashlight_world = undefined; } } }

I was actually getting the same problem/error. Im so Glad you can help out and fix it man! Hopefully this works.


ModmeBot:

Reply By: dreamzyy
just remove:

self thread flashlight_watch_orgelweap();
like you said, the function does not exist within my posted script. I forgot to remove that line there :p


ModmeBot:

Reply By: iAr7uRo

dreamzyy
just remove: self thread flashlight_watch_orgelweap(); like you said, the function does not exist within my posted script. I forgot to remove that line there :p

LOL yeah I just had to remove that line to make it work, thanks for answering, so that the problem would be fixed and another one will not suffer the same jajaj

Greet release! :D


ModmeBot:

Reply By: MyNameIsNobody2
Can somebody please post this as properly installed on a new maps .csc and .gsc files (as in the entire content of both files)? I have seriously spent like 3 hours trying to get this working, on 2 different occasions, and I think it is due to me being extremely dumb and repeatedly putting stuff in the wrong spot. Please someone save my hairs from all being pulled out, I would greatly appreciate it.


ModmeBot:

Reply By: eatdatpussy445
How do I get this to work on my MR6?