Modme Forums

How to add progress bar (like buildable progress, reviving)

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


ModmeBot:

Thread By: Frost Iceforge
I was going to make things such as buildable tables or ammo/item drops that you would hold down F to interact with that would take a certain amount of time, say 3 seconds. How do I display a bar showing the remaining time?


ModmeBot:

Reply By: KillJoyYT
I'm probably not much help but I know archaicvirus's buildable script can be edited for something else

https://www.ugx-mods.com/forum/index.php?topic=15031.0


ModmeBot:

Reply By: NoScopeNinja25
I used the progress bar from the craftables script and edited out the things that check for craftable parts

Here is my edited code if you want to use it. There is a variable for the radius, craft time, and the text on the progress bar. I included comments where the triggers go and where the variables are. It also plays the build fx and craftable sounds. Code to edit has EDIT THIS next to part you need to edit in comments just search for those comments.

Make sure these are included at the top of your file, there may be more:

#using scripts\zm\_zm_utility;
#using scripts\zm\_zm_weapons;
#using scripts\shared\laststand_shared;
#using scripts\shared\util_shared;

#insert scripts\zm\craftables\_zm_craftables.gsh;
#using scripts\zm\craftables\_zm_craftables;

This part goes in your function that waits for the bar to fill up:

function example()
{
    // Setup trigger here
    // example_trig = GetEnt("example_trig_name","targetname");

    do
    {
        // ====================================================================================
        // EDIT THIS
    	example_trig waittill("trigger", player);    // Change example_trig to your trigger
        // ====================================================================================
    	result = self craftable_use_hold_think_override( player );
    } while(!result);

    player PlaySound( "zmb_craftable_complete" );

    // Code to run after progress bar is successful
}



This is all the functions that handle the progress bar:

function craftable_use_hold_think_override( player )
{
	self thread zm_craftables::craftable_play_craft_fx( player );
	self thread craftable_use_hold_think_internal_override( player );
	retval = self util::waittill_any_return( "craft_succeed", "craft_failed" );

	if ( retval == "craft_succeed" )
	{
		return true;
	}

	return false;
}

function craftable_use_hold_think_internal_override( player )
{
	wait(0.01);

	if ( !isdefined( self ) )
	{
		//make sure the audio sounds go away
		if ( isdefined( player.craftableAudio ) )
		{
			player.craftableAudio delete();
			player.craftableAudio = undefined;
		}

		return;
	}
	
	if ( !isdefined( self.useTime ) )
	{
		// ====================================================================================
		// (Optional) EDIT THIS
		self.useTime = int( 3 * 1000 );		// This sets the craft time - in miliseconds 3 * 1000 = 3000 miliseconds or 3 seconds
		// ====================================================================================
	}

	self.craft_time = self.useTime;
	self.craft_start_time = getTime();
	craft_time = self.craft_time;
	craft_start_time = self.craft_start_time;

	if ( craft_time > 0 )
	{
	    player zm_utility::disable_player_move_states( true );

		player zm_utility::increment_is_drinking();
		orgweapon = player GetCurrentWeapon();
		build_weapon = GetWeapon( "zombie_builder" );
		player GiveWeapon( build_weapon );
		player SwitchToWeapon( build_weapon );

		player thread zm_craftables::player_progress_bar( craft_start_time, craft_time );

		while ( isdefined( self ) && player player_continue_crafting_override() && getTime() - self.craft_start_time < self.craft_time )
		{
			wait(0.01);
			if ( isdefined( player ) && !isdefined( player.craftableAudio ) )
			{
				player.craftableAudio = spawn( "script_origin", player.origin );
				player.craftableAudio PlayLoopSound( "zmb_craftable_loop" );
			}
		}

		//make sure the audio sounds go away
		if ( isdefined( player.craftableAudio ) )
		{
			player.craftableAudio delete();
			player.craftableAudio = undefined;
		}

		player notify( "craftable_progress_end" );

		player zm_weapons::switch_back_primary_weapon( orgweapon );
		//player SwitchToWeapon( orgweapon );
		player TakeWeapon( build_weapon );

		if ( IS_TRUE( player.is_drinking ) )
		{
			player zm_utility::decrement_is_drinking();
		}

		player zm_utility::enable_player_move_states();
	}

	if ( isdefined( self ) &&
	        player player_continue_crafting_override() &&
	        ( self.craft_time <= 0 || getTime() - self.craft_start_time >= self.craft_time ) )
	{
		self notify( "craft_succeed" );
	}
	else
	{
		//make sure the audio sounds go away
		if ( isdefined( player.craftableAudio ) )
		{
			player.craftableAudio delete();
			player.craftableAudio = undefined;
		}

		self notify( "craft_failed" );
	}
}

function player_continue_crafting_override()
{
	if ( self laststand::player_is_in_laststand() || self zm_utility::in_revive_trigger() )
	{
		return false;
	}

	if ( isdefined( self.screecher ) )
	{
		return false;
	}

	if ( !self UseButtonPressed() )
	{
		return false;
	}

	// ====================================================================================
	// EDIT THIS
	trigger = GetEnt("camo_button_empty_trig","targetname");	// Change camo_button_empty_trig to the tagrgetname of your trigger
	script_unitrigger_type = "unitrigger_radius_use";			// If you change this to anything else it will check to see if the player is still touching the trigger instead of checking radius
	radius = 40;												// Radius from trigger to cancel progress bar
	// ====================================================================================

	if ( script_unitrigger_type == "unitrigger_radius_use" )
	{
		torigin = trigger.origin;
		porigin = self GetEye();
		radius_sq = ( 1.5 * 1.5 ) * radius * radius;

		if ( Distance2DSquared( torigin, porigin ) > radius_sq )
		{
			return false;
		}
	}
	else
	{
		if ( !isdefined( trigger ) || !trigger IsTouching( self ) ) //self IsTouching(trigger))
		{
			return false;
		}
	}

	if (!self util::is_player_looking_at( trigger.origin, ZM_CRAFTABLES_LOOKAT_DOT ) )
	{
		return false;
	}

	return true;
}



If you want to change the text above the bar add this:

function player_progress_bar_override( start_time, craft_time )
{
    self.useBar = self hud::createPrimaryProgressBar();
    self.useBarText = self hud::createPrimaryProgressBarText();

    // ====================================================================================
    // EDIT THIS
    self.useBarText setText( &"ZOMBIE_BUILDING" );    // Remove the & symbol and replace ZOMBIE_BUILDING with text
    // ====================================================================================

    if ( isdefined( self ) && isdefined( start_time ) && isdefined( craft_time ) )
    {
        self zm_craftables::player_progress_bar_update( start_time, craft_time );
    }

    self.useBarText hud::destroyElem();
    self.useBar hud::destroyElem();
}



Replace any "zm_craftables::player_progress_bar" with this "player_progress_bar_override"
If you want to remove the fx delete/comment out this:
self thread zm_craftables::craftable_play_craft_fx( player );

If you want to remove the sounds delete/comment out these:
player.craftableAudio PlayLoopSound( "zmb_craftable_loop" );
AND
player PlaySound( "zmb_craftable_complete" );


ModmeBot:

Reply By: mathfag
Here's what I used in a generator script. It shouldn't be too hard to see what you need.

width = 300;
		height = 100;

		trigr = Spawn("trigger_radius", self.origin, 0, width, height);
		prog = Float(0.0);

		players = GetPlayers();

		foreach(player in players)
			{
			if(player IsTouching(trigr))
				{
				self.hackProgressBar = player hud::createPrimaryProgressBar();
				self.hackProgressText = player hud::createPrimaryProgressBarText();
				self.hackProgressBar hud::updateBar( 0.0, 0.0 );
				self.hackProgressBar hud::showElem();
				self.hackProgressText hud::showElem();
				self.hackProgressText SetText("Powering generator at "+location);
				}
			}
		self PlaySound("gen_start");
		wait(0.05);
		self thread gen_sound();

		trigr waittill("trigger", player);
		while(1)
			{
				if(player IsTouching(trigr))
					{
					prog+= Float(0.005);	
					self.hackProgressBar hud::updateBar( prog, 0.0 );
					}
	//hud::updateBar(barFrac, rateOfChange)
				else
					{
					prog-= Float(0.01);
					self.hackProgressBar hud::updateBar( prog, 0.0 );
					}

				//IPrintLnBold(prog);
				if(prog <= 0)
					{
					self.hackProgressBar hud::destroyElem();
					self.hackProgressText hud::destroyElem();
					self StopLoopSound(1);
					PlaySoundAtPosition("gen_fail",self.origin);
					//IPrintLnBold("failed");
					thread do_gens(location);	
					break;
					}

				if(prog >= 1)
					{
					self.hackProgressBar hud::destroyElem();
					self.hackProgressText hud::destroyElem();
					self StopLoopSound(1);
					PlaySoundAtPosition("gen_succeed",self.origin);
					foreach(player in GetPlayers())
						{
						if(player IsTouching(trigr))
							player zm_score::add_to_player_score(gen_cost*2);

						}
					//IPrintLnBold("complete");
					prog = 2;
					break;
					}
				
			wait(0.05);
			}