UGX-Mods

Call of Duty: Black Ops 3 => Tutorial Desk => Scripting => Topic started by: shinged on October 17, 2016, 12:47:20 am

Title: [Tutorial] Buildable power switch
Post by: shinged on October 17, 2016, 12:47:20 am
Heres the finished result


So to start off, download this prefab https://mega.nz/#!M9sBhZCT!ewDyF1nJVaCDdHUtc8UrcN_tKXM6Zl0_L4ca7xblPSg (https://mega.nz/#!M9sBhZCT!ewDyF1nJVaCDdHUtc8UrcN_tKXM6Zl0_L4ca7xblPSg)
Place the prefab in root/map_source/_prefabs/ and your ready for radiant.

Radiant:
 All you need to do is open the prefab by going to misc > prefab and opening the prefab, then stamp the prefab and move the pieces where you want them to be. If your on a tutorial map then delete the other power switch or this wont work.

Script:
 Navigate over to your mapname.gsc in root/usermaps/mapname/scripts/zm/mapname.gsc (Not the CSC) and open it.
 
 Below this
Code Snippet
Plaintext
#using scripts\zm\zm_usermap;
Add this
Code Snippet
Plaintext
#define PAP_WEAPON_KNUCKLE_CRACK		"zombie_knuckle_crack"


 At the bottom of the main function, add this
Code Snippet
Plaintext
thread buildableinit();

 And finally at the bottom of your gsc, paste this
Code Snippet
Plaintext
function buildableinit()
{
buildTable = getEnt("powcraft_crafting_trig", "targetname");
buildTable SetHintString("Missing parts");
buildTable SetCursorHint("HINT_NOICON");

level.allParts = 0;
level.finishedCraft = 2;

power_trigger = GetEnt("use_elec_switch", "targetname");
power_trigger TriggerEnable( false );
power_handle_model = GetEnt("elec_switch", "script_noteworthy");
power_handle_model hide();
power_clip = GetEnt("powcraft_clip_build", "targetname");
power_clip hide();
power_shaft_model = GetEnt("powcraft_build1", "targetname");
power_shaft_model hide();

level thread pick1();
level thread pick2();
}

function pick1()
{
pick_trig1 = getent("powcraft_pick1_trig", "targetname");
pick_trig1 SetHintString("Press and hold &&1 to pickup part");
pick_trig1 SetCursorHint("HINT_NOICON");
pick_model1 = getent("powcraft_pick1", "targetname");

while(1)
{
pick_trig1 waittill("trigger", player);

playfx(level._effect["powerup_grabbed"] ,GetEnt("powcraft_pick1","targetname").origin);

level.allParts++;

//IPrintLnBold(level.allParts);

thread build();

break;
}

pick_trig1 delete();
pick_model1 delete();
}

function pick2()
{
pick_trig2 = getent("powcraft_pick2_trig", "targetname");
pick_trig2 SetHintString("Press and hold &&1 to pickup part");
pick_trig2 SetCursorHint("HINT_NOICON");
pick_model2 = getent("powcraft_pick2", "targetname");

while(1)
{
pick_trig2 waittill("trigger", player);

playfx(level._effect["powerup_grabbed"] ,GetEnt("powcraft_pick2","targetname").origin);

level.allParts++;

//IPrintLnBold(level.allParts);

thread build();

break;
}

pick_trig2 delete();
pick_model2 delete();
}

function build()
{

while(1)
{
self waittill( level.allParts >= level.finishedCraft );

if ( level.allParts >= level.finishedCraft )
{
buildTable = GetEnt("powcraft_crafting_trig", "targetname");
buildTable SetHintString("Press and hold &&1 to craft");
buildTable SetCursorHint("HINT_NOICON");
buildTable waittill("trigger", player);

buildTable SetHintString("");

//playfx(level._effect["powerup_grabbed"] ,GetEnt("powcraft_crafting_trig","targetname").origin);

player thread do_knuckle_crack();

wait(2.7);

thread power_crafted();

buildTable delete();
}
break;
}
}

function power_crafted()
{
power_trigger = GetEnt("use_elec_switch", "targetname");
power_trigger TriggerEnable( true );
playfx(level._effect["powerup_grabbed"] ,GetEnt("use_elec_switch","targetname").origin);
power_handle_model = GetEnt("elec_switch", "script_noteworthy");
power_handle_model show();
power_clip = GetEnt("powcraft_clip_build", "targetname");
power_clip show();
power_shaft_model = GetEnt("powcraft_build1", "targetname");
power_shaft_model show();
}

/*
KNUCKLE CRACK SCRIPT
*/
function private do_knuckle_crack()
{
self endon("disconnect");
self upgrade_knuckle_crack_begin();

self util::waittill_any( "fake_death", "death", "player_downed", "weapon_change_complete" );

self upgrade_knuckle_crack_end();

}


// Switch to the knuckles
//
function private upgrade_knuckle_crack_begin()
{
self zm_utility::increment_is_drinking();

self zm_utility::disable_player_move_states(true);

primaries = self GetWeaponsListPrimaries();

original_weapon = self GetCurrentWeapon();
weapon = GetWeapon( PAP_WEAPON_KNUCKLE_CRACK );



self GiveWeapon( weapon );
self SwitchToWeapon( weapon );
}

// Anim has ended, now switch back to something
//
function private upgrade_knuckle_crack_end()
{
self zm_utility::enable_player_move_states();

weapon = GetWeapon( PAP_WEAPON_KNUCKLE_CRACK );

// TODO: race condition?
if ( self laststand::player_is_in_laststand() || IS_TRUE( self.intermission ) )
{
self TakeWeapon(weapon);
return;
}

self zm_utility::decrement_is_drinking();

self TakeWeapon(weapon);
primaries = self GetWeaponsListPrimaries();
if( IS_DRINKING(self.is_drinking) )
{
return;
}
else
{
self zm_weapons::switch_back_primary_weapon();
}
}
/*
KNUCKLE CRACK SCRIPT END
*/
Title: Re: [Tutorial] Buildable power switch
Post by: Blink-420 on October 17, 2016, 03:53:28 am
Was hoping for this soon..Thank you very much! Works flawlessly
Title: Re: [Tutorial] Buildable power switch
Post by: Warheez on October 17, 2016, 10:26:54 am
This is beautiful! Going to try it out later  :D

Double Post Merge: October 17, 2016, 04:10:58 pm
Works perfectly! I give it 5 out of 5 Slav-Squats  ;)
Title: Re: [Tutorial] Buildable power switch
Post by: Archaicvirus on November 19, 2016, 07:44:48 pm
Very nice, thanks.

I noticed something in the script: Your functions pick1() and pick2() both thread your build() function, so essentially you have 2 of the same build() functions running in parallel, and build() won't break if you only have 1 part, because the first line wait's until the variable level.allParts equals 2.

Does this explain why some custom maps are playing the power up sound twice for players when you hit the power switch?

The way you have it set up is perfect, but instead of threading build() two times in the pick1() and pick2() functions, just thread build() once before pick1() & pick2() are threaded, and it will only execute once after the variable level.allParts= 2. Then of course remove the "thread build()" line from pick1() and pick2().

Maybe i'm reading it wrong or something, but just thought I would give some potentially helpful feedback. Thanks again, this is very useful.
Title: Re: [Tutorial] Buildable power switch
Post by: reckfullies on November 20, 2016, 10:13:44 am
Very nice, thanks.

I noticed something in the script: Your functions pick1() and pick2() both thread your build() function, so essentially you have 2 of the same build() functions running in parallel, and build() won't break if you only have 1 part, because the first line wait's until the variable level.allParts equals 2.

Does this explain why some custom maps are playing the power up sound twice for players when you hit the power switch?

The way you have it set up is perfect, but instead of threading build() two times in the pick1() and pick2() functions, just thread build() once before pick1() & pick2() are threaded, and it will only execute once after the variable level.allParts= 2. Then of course remove the "thread build()" line from pick1() and pick2().

Maybe i'm reading it wrong or something, but just thought I would give some potentially helpful feedback. Thanks again, this is very useful.

You are correct, from what I see there is also no need to use a while loop inside the build function since waittill only needs to be called once and it will continue to wait.

I believe this was the first script he released so its safe to assume that it might have errors.
Title: Re: [Tutorial] Buildable power switch
Post by: LingerCustomMap on December 30, 2016, 10:01:05 pm
I Will try this :D
Title: Re: [Tutorial] Buildable power switch
Post by: BarkseyLXIX on June 04, 2017, 06:25:05 am
i put the script into to my gsc and loaded the game after i did everything and i got fatal error "getweapon" with 0 parameters in script at line 306
***unresolved external "getweapon" with 0 parameters in script
and this  is what is at line 306, weapon = GetWeapon( PAP_WEAPON_KNUCKLE_CRACK );

can anyone help?
Title: Re: [Tutorial] Buildable power switch
Post by: Archaicvirus on June 05, 2017, 05:01:05 am
i put the script into to my gsc and loaded the game after i did everything and i got fatal error "getweapon" with 0 parameters in script at line 306
***unresolved external "getweapon" with 0 parameters in script
and this  is what is at line 306, weapon = GetWeapon( PAP_WEAPON_KNUCKLE_CRACK );

can anyone help?

You're getting an unresolved variable, which probably means the .gsh file in which PAP_WEAPON_KNUCKLE_CRACK is defined isn't getting parsed or included somewhere. Or simply that PAP_WEAPON_KNUCKLE_CRACK isn't defined. In my script I did it differently, like this
Code Snippet
Plaintext
	weapon = GetWeapon("zombie_builder");

and in that script at the top I put
Code Snippet
Plaintext
#precache("weapon", "zombie_builder");

I may be wrong, but good luck.
Title: Re: [Tutorial] Buildable power switch
Post by: HitmanVere on June 05, 2017, 12:26:14 pm
You're getting an unresolved variable, which probably means the .gsh file in which PAP_WEAPON_KNUCKLE_CRACK is defined isn't getting parsed or included somewhere. Or simply that PAP_WEAPON_KNUCKLE_CRACK isn't defined. In my script I did it differently, like this
Code Snippet
Plaintext
	weapon = GetWeapon("zombie_builder");

and in that script at the top I put
Code Snippet
Plaintext
#precache("weapon", "zombie_builder");

I may be wrong, but good luck.

You are somewhat right, but the real reason is that he didn't follow the guide properly:
(http://i.imgur.com/7jDn8xZ.png)
Title: Re: [Tutorial] Buildable power switch
Post by: Archaicvirus on June 05, 2017, 05:40:30 pm
That's cool, how did you crop that part of his tutorial in your reply?
Title: Re: [Tutorial] Buildable power switch
Post by: Scobalula on June 05, 2017, 07:08:27 pm
That's cool, how did you crop that part of his tutorial in your reply?

It's a screenshot.
Title: Re: [Tutorial] Buildable power switch
Post by: GAMERMANRAF on June 26, 2018, 02:35:45 pm
Does this work for Call of Duty World at War??

I really need this for my cod waw custom map  :-\
Title: Re: [Tutorial] Buildable power switch
Post by: IceGrenade on January 31, 2020, 02:28:58 pm
Hello 👋