Author Topic: [Tutorial] Buildable power switch  (Read 3228 times)

0 Members and 1 Guest are viewing this topic.

Offline shinged

  • - Original Poster (OP) -
  • Rotting Walker
  • Posts: 69
  • Country: us
  • Respect: 49
  • What is broken can be reforged
    • vinny545
    • Matarra_'s Twitch Channel
    • View Profile
  • Skype: Shinged
  • WaW: TheShinged

[Tutorial] Buildable power switch

« on: October 16, 2016, 03:47:20 pm »
Heres the finished result


So to start off, download this prefab [You are not allowed to view external links. Register or Login to see them]
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: [Select]
#using scripts\zm\zm_usermap;
Add this
Code: [Select]
#define PAP_WEAPON_KNUCKLE_CRACK		"zombie_knuckle_crack"


 At the bottom of the main function, add this
Code: [Select]
thread buildableinit();

 And finally at the bottom of your gsc, paste this
Code: [Select]
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
*/
Completed maps:
Kingdom Hearts - World at War Link
Minecraft - Black ops 3 Link

WIP:
~


Offline Blink-420

  • Rotting Walker
  • Posts: 63
  • Country: us
  • Respect: 13
    • Blink-420
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #1 on: October 16, 2016, 06:53:28 pm »
Was hoping for this soon..Thank you very much! Works flawlessly

Offline Warheez

  • Fresh Corpse
  • Posts: 4
  • Country: de
  • Respect: 1
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #2 on: October 17, 2016, 01:26:54 am »
This is beautiful! Going to try it out later  :D

Double Post Merge: October 17, 2016, 07:10:58 am
Works perfectly! I give it 5 out of 5 Slav-Squats  ;)
« Last Edit: October 17, 2016, 07:10:58 am by Warheez »

Offline Archaicvirus

  • *
  • Rotting Walker
  • Posts: 92
  • Country: us
  • Respect: 32
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #3 on: November 19, 2016, 10:44:48 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.
Let he who has not sinned cast the first stone.

Offline reckfullies

  • Perk Hacker
  • Posts: 306
  • Country: us
  • Respect: 68
    • Reckfullies's YouTube Channel
    • View Profile
  • WaW: Reckfullies

Re: [Tutorial] Buildable power switch

« Reply #4 on: November 20, 2016, 01: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.
If anyone needs scripts made for their map contact me.

Offline LingerCustomMap

  • Legless Crawler
  • Posts: 19
  • Country: ma
  • Respect: 4
    • FuryLingerOfficial's YouTube Channel
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #5 on: December 30, 2016, 01:01:05 pm »
I Will try this :D

Offline BarkseyLXIX

  • Fresh Corpse
  • Posts: 1
  • Country: gb
  • Respect: 0
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #6 on: June 03, 2017, 09:25:05 pm »
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?

Offline Archaicvirus

  • *
  • Rotting Walker
  • Posts: 92
  • Country: us
  • Respect: 32
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #7 on: June 04, 2017, 08:01:05 pm »
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: [Select]
	weapon = GetWeapon("zombie_builder");

and in that script at the top I put
Code: [Select]
#precache("weapon", "zombie_builder");

I may be wrong, but good luck.

Offline HitmanVere

  • Eviscerator
  • UGX V.I.P.
  • Posts: 3,901
  • Country: fi
  • Respect: 818
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #8 on: June 05, 2017, 03:26:14 am »
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: [Select]
	weapon = GetWeapon("zombie_builder");

and in that script at the top I put
Code: [Select]
#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:

Offline Archaicvirus

  • *
  • Rotting Walker
  • Posts: 92
  • Country: us
  • Respect: 32
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #9 on: June 05, 2017, 08:40:30 am »
That's cool, how did you crop that part of his tutorial in your reply?

Offline Scobalula

  • *
  • OnionmanVere Bo21
  • Zombie Destroyer
  • Posts: 1,809
  • Country: ie
  • Respect: 292
  • i will fuck u up so bad u will want to go home thx
    • View Profile

Re: [Tutorial] Buildable power switch

« Reply #10 on: June 05, 2017, 10:08:27 am »
That's cool, how did you crop that part of his tutorial in your reply?

It's a screenshot.
Aye mate you don't know me so y don't you shut tf up ok buddy :)