Modme Forums

Pick up item by shooting the ray gun mark 3

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


ModmeBot:

Thread By: simplyzak09
Hi,
How would I go about writing a script that requires the player to shoot 6 items while using the left gun of the Ray Gun Mark 3?
and then place them down the same way by shooting the left gun onto a crafting table.

and is that even possible?


ModmeBot:

Reply By: Abnormal202

simplyzak09
Hi, How would I go about writing a script that requires the player to shoot 6 items while using the left gun of the Ray Gun Mark 3? and then place them down the same way by shooting the left gun onto a crafting table. and is that even possible?

I had an easter egg system that would do most of this for you already, so I added a feature where instead of pressing "x" to pick items up, you can shoot them with a specific gun, like you asked for above. See if it works


ModmeBot:

Reply By: mathfag
*FIXED*
Maybe this will work maybe not because i think the left ray gun is "special"
Place "trigger_damages" around your map (as many as you want) and make models their target (if you want them to delete when shot. Make sure they're script_models.) and give the triggers the targetname "mark3_left".
Also place a trigger damage on your crafting table and the models that you want to show. Make sure they're script_models with the targetname "craft_models". The trigger's targetname is "craft_trig".

Of course start the script with thread init_ray(); at the top of your mapname.gsc

function init_ray()
{
models = GetEntArray("craft_models","targetname");
foreach(mod in models)
	{
	mod Hide();	
	}


thread wait_for_craft();
trigs = GetEntArray("mark3_left","targetname");
foreach(trig in trigs)
	{
	trig thread shoot_ray();	
	}
}


function shoot_ray() //self == trigger == trig
{
model = GetEnt(self.target, "targetname");
while(1)
	{
	self waittill( "damage", amount, attacker, direction_vec, point, type, tagName, modelName, partName, weapon, dFlags, inflictor, chargeLevel );
	if(weapon == GetWeapon("raygun_mark3lh")) //lh = left hand
		{
		self Delete();
		model Delete();
		break;
		}
	}
}


function wait_for_craft()
{
models = GetEntArray("craft_models","targetname");
craft_trig = GetEnt("craft_trig","targetname");


while(1)
{
craft_trig waittill( "damage", amount, attacker, direction_vec, point, type, tagName, modelName, partName, weapon, dFlags, inflictor, chargeLevel );

trigs = GetEntArray("mark3_left","targetname");
	if(weapon == GetWeapon("raygun_mark3lh") && trigs.size<1)
		{
		foreach(mod in models)
			{
			mod Show();	
			}
		break;
		}		
wait(0.1);		
}
}


ModmeBot:

Reply By: Harry Bo21

models = GetEnt("craft_models","targetname");
foreach(mod in model)


please check your code - its literally littered with mistakes, heres the first example


ModmeBot:

Reply By: mathfag

Harry Bo21
models = GetEnt("craft_models","targetname"); foreach(mod in model) please check your code - its literally littered with mistakes, heres the first example

4 is not littered :)
+the launcher would complain


ModmeBot:

Reply By: Harry Bo21

// Firstly fixed the horrific indentation

function init_ray()
{
	a_models = getEntArray( "craft_models", "targetname" ); // We will check this exists and iPrint some text if it doesnt incase the user made a mistake in radiant
	a_trigers = getEntArray( "mark3_left", "targetname" ); // Moved this here so we can also abandon and print some text warning the user of the issue if he forgot these
	e_craft_trigger = getEnt( "craft_trig", "targetname" ); // Moved this here to check it exists and iPrint some text if it doesnt incase the user made a mistake in radiant
	if ( !isDefined( a_models ) || a_models.size < 1 || !isDefined( a_trigers ) || a_trigers.size < 1 || !isDefined( e_craft_trigger ) )
	{
		if ( !isDefined( e_craft_trigger ) )
			level thread delayed_iprint( "Radiant entity not found - targetname : craft_trig", 30 ); // Delay these iPrints as they may appear and vanish before the black screen is over 
		if ( !isDefined( a_models ) || a_models.size < 1 )
			level thread delayed_iprint( "Radiant entities not found - targetname : craft_models", 30 ); // Delay these iPrints as they may appear and vanish before the black screen is over 
		if ( !isDefined( a_trigers ) || a_trigers.size < 1 )
			level thread delayed_iprint( "Radiant entities not found - targetname : mark3_left", 30 ); // Delay these iPrints as they may appear and vanish before the black screen is over 
		
		return; // Added a debug here in the off chance the guy your helping misnames his ents, didnt place them at all - or simply forgot to compile his map
	}
	
	foreach ( e_model in a_models )
		e_model hide();	

	foreach ( e_trigger in a_trigers )
		e_trigger thread shoot_ray();	
	
	e_craft_trigger thread wait_for_craft( a_models ); // This function now passes the relevent entities to the function. Two reasons, one being so we can abandon it if any are missing and also to be efficient
}

function delayed_iprint( text, delay )
{
	if ( !isDefined( delay ) ) // Again this is another advisable undefined variable / argument check incase of developer mode errors
		delay = 0;
	
	wait delay; // Delay our debug warning text - otherwise it will show and dissapear before the black screen is over
	iPrintLnBold( "^1ERROR : " + text );
}

// You didnt actully need additional triggers for this, you could have used 

// model setCanDamage( 1 );

// and then just ran this logic on the actual model instead

function shoot_ray() //self == trigger == trig
{
	e_model = getEnt( self.target, "targetname" );
	if ( !isDefined( e_model ) ) // We will check this exists and iPrint some text if it doesnt incase the user made a mistake in radiant
	{
		level thread delayed_iprint( "Radiant entities not found - targetname : mark3_left : is not targeting anything", 30 ); // Delay these iPrints as they may appear and vanish before the black screen is over 
		return;
	}
	
	while ( isDefined( self ) ) // Changed the loop to break when self is deleted instead of having additional code to break the loop
	{
		self waittill( "damage", n_amount, e_attacker, v_direction_vec, v_point, str_type, str_tag_name, str_model_name, str_part_pame, w_weapon, b_d_flags, str_inflictor, n_chargeLevel );
		if ( w_weapon.name == "raygun_mark3lh" ) //lh = left hand // Check the weapon file name rather then wasting resources on using getWeapon for no reason
		{
			e_model delete(); // Delete the model "first" as this thread is running "on" self
			self delete(); // Delete "self" last - which will also kill this "while" loop
		}
	}
}

// Same again here

// You didnt actully need additional triggers for this, you could have used 

// model setCanDamage( 1 );

// and then just ran this logic on the actual model instead

function wait_for_craft( a_models )
{
	// models = getEntArray( "craft_models", "targetname" ); // We have obtained this information already - this is now the "a_models" array passed to the function
	// craft_trig = getEnt( "craft_trig", "targetname" ); // We have obtained this information already - this is now "self"

	while ( 1 )
	{
		self waittill( "damage", n_amount, e_attacker, v_direction_vec, v_point, str_type, str_tag_name, str_model_name, str_part_pame, w_weapon, b_d_flags, str_inflictor, n_chargeLevel ); // Thread is now running "on" the entity

		a_triggers = getEntArray( "mark3_left", "targetname" );
		// Check the weapon file name rather then wasting resources on using getWeapon for no reason
		if ( w_weapon.name == "raygun_mark3lh" && ( !isDefined( a_triggers ) || a_triggers.size < 1 ) ) // Added a undefined check, this would have errored in developer because trigs would == undefined, not 0
		{
			foreach ( e_model in a_models )
				e_model show();	
			
			break;
		}		
		// wait .1;	// Dont need this because the loop has a "waittill" in it, only "infinite" loops need a wait, having one could potentially cause a correct shot to not register	
	}
}


Bowser32:

Is there a place I could find more info on the damage arguments.
( "damage", n_amount, e_attacker, v_direction_vec, v_point, str_type, str_tag_name, str_model_name, str_part_pame, w_weapon, b_d_flags, str_inflictor, n_chargeLevel );
For instance to find out if e_attacker returns a player object or an entity object.
If not then how I would get the player object from e_attacker.

EDIT: NVM Found out i can check with

IsPlayer(e_attacker);