diff --git a/scripts/zm/_zm_reimagined.gsc b/scripts/zm/_zm_reimagined.gsc index 3a48a616..df64e654 100644 --- a/scripts/zm/_zm_reimagined.gsc +++ b/scripts/zm/_zm_reimagined.gsc @@ -185,8 +185,6 @@ onplayerspawned() self thread weapon_locker_give_ammo_after_rounds(); - self thread buildable_piece_remove_on_last_stand(); - self thread war_machine_explode_on_impact(); self thread jetgun_heatval_changes(); @@ -2671,15 +2669,9 @@ buildbuildable( buildable, craft = 0, solo_pool = 0, onuse ) level.zombie_buildables[stub.equipname].hint = "Hold ^3[{+activate}]^7 to craft " + stub get_equipment_display_name(); } - i = 0; foreach (piece in stub.buildablezone.pieces) { piece maps\mp\zombies\_zm_buildables::piece_unspawn(); - if (!craft && i > 0) - { - stub.buildablezone maps\mp\zombies\_zm_buildables::buildable_set_piece_built(piece); - } - i++; } return; @@ -2809,38 +2801,6 @@ removebuildable( buildable, poolname ) } } -buildable_piece_remove_on_last_stand() -{ - self endon( "disconnect" ); - - self thread buildable_get_last_piece(); - - while (1) - { - self waittill("entering_last_stand"); - - if (isDefined(self.last_piece)) - { - self.last_piece maps\mp\zombies\_zm_buildables::piece_unspawn(); - } - } -} - -buildable_get_last_piece() -{ - self endon( "disconnect" ); - - while (1) - { - if (!self maps\mp\zombies\_zm_laststand::player_is_in_laststand()) - { - self.last_piece = maps\mp\zombies\_zm_buildables::player_get_buildable_piece(0); - } - - wait 0.05; - } -} - onuseplantobject_mtower( player ) { level setclientfield( "sq_gl_b_vt", 1 ); @@ -2852,14 +2812,6 @@ onuseplantobject_mtower( player ) self maps\mp\zombies\_zm_buildables::buildablestub_finish_build( player ); player playsound( "zmb_buildable_complete" ); - players = get_players(); - foreach (other_player in players) - { - slot = self.buildablestruct.buildable_slot; - piece = other_player player_get_buildable_piece( slot ); - other_player player_destroy_piece( piece ); - } - level thread unregister_tower_unitriggers(); } @@ -2875,14 +2827,6 @@ onuseplantobject_rtower( player ) self maps\mp\zombies\_zm_buildables::buildablestub_finish_build( player ); player playsound( "zmb_buildable_complete" ); - players = get_players(); - foreach (other_player in players) - { - slot = self.buildablestruct.buildable_slot; - piece = other_player player_get_buildable_piece( slot ); - other_player player_destroy_piece( piece ); - } - level thread unregister_tower_unitriggers(); } diff --git a/scripts/zm/replaced/_zm_buildables.gsc b/scripts/zm/replaced/_zm_buildables.gsc index f5ef1de3..c168cd84 100644 --- a/scripts/zm/replaced/_zm_buildables.gsc +++ b/scripts/zm/replaced/_zm_buildables.gsc @@ -18,8 +18,7 @@ buildable_place_think() { self waittill( "trigger", player ); - slot = self.stub.buildablestruct.buildable_slot; - bind_to = self.stub.buildable_pool scripts\zm\replaced\_zm_buildables_pooled::pooledbuildable_stub_for_piece( player player_get_buildable_piece( slot ) ); + bind_to = self.stub.buildable_pool scripts\zm\replaced\_zm_buildables_pooled::pooledbuildable_stub_for_equipname( self.stub ); if ( player != self.parent_player ) { @@ -34,7 +33,7 @@ buildable_place_think() player thread ignore_triggers( 0.5 ); } - status = player maps\mp\zombies\_zm_buildables::player_can_build( self.stub.buildablezone ); + status = player player_can_build( self.stub.buildablezone ); if ( !status ) { self.stub.hint_string = ""; @@ -51,7 +50,7 @@ buildable_place_think() { self.stub [[ self.stub.onbeginuse ]]( player ); } - result = self maps\mp\zombies\_zm_buildables::buildable_use_hold_think( player ); + result = self buildable_use_hold_think( player ); team = player.pers[ "team" ]; if ( isDefined( self.stub.onenduse ) ) { @@ -309,6 +308,203 @@ buildable_place_think() } } +player_can_build( buildable, continuing ) +{ + if ( !isdefined( buildable ) ) + return false; + + if ( isdefined( continuing ) && continuing ) + { + if ( buildable buildable_is_piece_built( buildable.pieces[0] ) ) + return false; + } + else if ( buildable buildable_is_piece_built_or_building( buildable.pieces[0] ) ) + return false; + + if ( isdefined( buildable.stub ) && isdefined( buildable.stub.custom_buildablestub_update_prompt ) && isdefined( buildable.stub.playertrigger[0] ) && isdefined( buildable.stub.playertrigger[0].stub ) && !buildable.stub.playertrigger[0].stub [[ buildable.stub.custom_buildablestub_update_prompt ]]( self, 1, buildable.stub.playertrigger[0] ) ) + return false; + + return true; +} + +buildable_use_hold_think( player, bind_stub = self.stub ) +{ + self thread buildable_play_build_fx( player ); + self thread buildable_use_hold_think_internal( player, bind_stub ); + retval = self waittill_any_return( "build_succeed", "build_failed" ); + + if ( retval == "build_succeed" ) + return true; + + return false; +} + +buildable_use_hold_think_internal( player, bind_stub = self.stub ) +{ + wait 0.01; + + if ( !isdefined( self ) ) + { + self notify( "build_failed" ); + + if ( isdefined( player.buildableaudio ) ) + { + player.buildableaudio delete(); + player.buildableaudio = undefined; + } + + return; + } + + if ( !isdefined( self.usetime ) ) + self.usetime = int( 3000 ); + + self.build_time = self.usetime; + self.build_start_time = gettime(); + build_time = self.build_time; + build_start_time = self.build_start_time; + player disable_player_move_states( 1 ); + player increment_is_drinking(); + orgweapon = player getcurrentweapon(); + build_weapon = "zombie_builder_zm"; + + if ( isdefined( bind_stub.build_weapon ) ) + build_weapon = bind_stub.build_weapon; + + player giveweapon( build_weapon ); + player switchtoweapon( build_weapon ); + bind_stub.buildablezone buildable_set_piece_building( bind_stub.buildablezone.pieces[0] ); + player thread player_progress_bar( build_start_time, build_time, bind_stub.building_prompt ); + + if ( isdefined( level.buildable_build_custom_func ) ) + player thread [[ level.buildable_build_custom_func ]]( self.stub ); + + while ( isdefined( self ) && player player_continue_building( bind_stub.buildablezone, self.stub ) && gettime() - self.build_start_time < self.build_time ) + wait 0.05; + + player notify( "buildable_progress_end" ); + player maps\mp\zombies\_zm_weapons::switch_back_primary_weapon( orgweapon ); + player takeweapon( "zombie_builder_zm" ); + + if ( isdefined( player.is_drinking ) && player.is_drinking ) + player decrement_is_drinking(); + + player enable_player_move_states(); + + if ( isdefined( self ) && player player_continue_building( bind_stub.buildablezone, self.stub ) && gettime() - self.build_start_time >= self.build_time ) + { + buildable_clear_piece_building( bind_stub.buildablezone.pieces[0] ); + self notify( "build_succeed" ); + } + else + { + if ( isdefined( player.buildableaudio ) ) + { + player.buildableaudio delete(); + player.buildableaudio = undefined; + } + + buildable_clear_piece_building( bind_stub.buildablezone.pieces[0] ); + self notify( "build_failed" ); + } +} + +player_continue_building( buildablezone, build_stub = buildablezone.stub ) +{ + if ( self maps\mp\zombies\_zm_laststand::player_is_in_laststand() || self in_revive_trigger() ) + return false; + + if ( self isthrowinggrenade() ) + return false; + + if ( !self player_can_build( buildablezone, 1 ) ) + return false; + + if ( isdefined( self.screecher ) ) + return false; + + if ( !self usebuttonpressed() ) + return false; + + if ( !buildablezone buildable_is_piece_building( buildablezone.pieces[0] ) ) + return false; + + trigger = build_stub maps\mp\zombies\_zm_unitrigger::unitrigger_trigger( self ); + + if ( build_stub.script_unitrigger_type == "unitrigger_radius_use" ) + { + torigin = build_stub unitrigger_origin(); + porigin = self geteye(); + radius_sq = 2.25 * build_stub.test_radius_sq; + + if ( distance2dsquared( torigin, porigin ) > radius_sq ) + return false; + } + else if ( !isdefined( trigger ) || !trigger istouching( self ) ) + return false; + + if ( isdefined( build_stub.require_look_at ) && build_stub.require_look_at && !self is_player_looking_at( trigger.origin, 0.4 ) ) + return false; + + return true; +} + +player_build( buildable, pieces ) +{ + foreach ( piece in buildable.pieces ) + { + buildable buildable_set_piece_built( piece ); + } + + if ( isdefined( buildable.stub.model ) ) + { + for ( i = 0; i < buildable.pieces.size; i++ ) + { + if ( isdefined( buildable.pieces[i].part_name ) ) + { + buildable.stub.model notsolid(); + + if ( !( isdefined( buildable.pieces[i].built ) && buildable.pieces[i].built ) ) + { + buildable.stub.model hidepart( buildable.pieces[i].part_name ); + continue; + } + + buildable.stub.model show(); + buildable.stub.model showpart( buildable.pieces[i].part_name ); + } + } + } + + if ( isplayer( self ) ) + self track_buildable_pieces_built( buildable ); + + if ( buildable buildable_all_built() ) + { + self player_finish_buildable( buildable ); + buildable.stub buildablestub_finish_build( self ); + + if ( isplayer( self ) ) + self track_buildables_built( buildable ); + + if ( isdefined( level.buildable_built_custom_func ) ) + self thread [[ level.buildable_built_custom_func ]]( buildable ); + + alias = sndbuildablecompletealias( buildable.buildable_name ); + self playsound( alias ); + } + else + { + self playsound( "zmb_buildable_piece_add" ); + assert( isdefined( level.zombie_buildables[buildable.buildable_name].building ), "Missing builing hint" ); + + if ( isdefined( level.zombie_buildables[buildable.buildable_name].building ) ) + return level.zombie_buildables[buildable.buildable_name].building; + } + + return ""; +} + model_go_away(weaponname) { self hide(); diff --git a/scripts/zm/replaced/_zm_buildables_pooled.gsc b/scripts/zm/replaced/_zm_buildables_pooled.gsc index e5746fb5..7db611c6 100644 --- a/scripts/zm/replaced/_zm_buildables_pooled.gsc +++ b/scripts/zm/replaced/_zm_buildables_pooled.gsc @@ -66,25 +66,6 @@ randomize_pooled_buildables( poolname ) } } -pooledbuildable_has_piece( piece ) -{ - return isdefined( self pooledbuildable_stub_for_piece( piece ) ); -} - -pooledbuildable_stub_for_piece( piece ) -{ - foreach ( stub in self.stubs ) - { - if ( isdefined( stub.bound_to_buildable ) ) - continue; - - if ( stub.buildablezone buildable_has_piece( piece ) ) - return stub; - } - - return undefined; -} - pooledbuildabletrigger_update_prompt( player ) { can_use = self.stub pooledbuildablestub_update_prompt( player, self ); @@ -129,18 +110,7 @@ pooledbuildablestub_update_prompt( player, trigger ) if ( !( isdefined( self.built ) && self.built ) ) { - if (is_true(self.solo_pool)) - { - foreach (stub in level.buildable_stubs) - { - if (stub.buildablezone.buildable_name == self.equipname) - { - piece = stub.buildablezone.pieces[0]; - break; - } - } - } - else + if (!is_true(self.solo_pool)) { if (level.buildables_available.size > 1) { @@ -169,71 +139,12 @@ pooledbuildablestub_update_prompt( player, trigger ) { self.buildables_available_index = 0; } - - foreach (stub in level.buildable_stubs) - { - if (stub.buildablezone.buildable_name == level.buildables_available[self.buildables_available_index]) - { - piece = stub.buildablezone.pieces[0]; - break; - } - } } - slot = self.buildablestruct.buildable_slot; - player maps\mp\zombies\_zm_buildables::player_set_buildable_piece(piece, slot); - - if ( !isdefined( player player_get_buildable_piece( slot ) ) ) - { - if ( isdefined( level.zombie_buildables[self.equipname].hint_more ) ) - self.hint_string = level.zombie_buildables[self.equipname].hint_more; - else - self.hint_string = &"ZOMBIE_BUILD_PIECE_MORE"; - - if ( isdefined( level.custom_buildable_need_part_vo ) ) - player thread [[ level.custom_buildable_need_part_vo ]](); - - return 0; - } - else if ( isdefined( self.bound_to_buildable ) && !self.bound_to_buildable.buildablezone buildable_has_piece( player player_get_buildable_piece( slot ) ) ) - { - if ( isdefined( level.zombie_buildables[self.bound_to_buildable.equipname].hint_wrong ) ) - self.hint_string = level.zombie_buildables[self.bound_to_buildable.equipname].hint_wrong; - else - self.hint_string = &"ZOMBIE_BUILD_PIECE_WRONG"; - - if ( isdefined( level.custom_buildable_wrong_part_vo ) ) - player thread [[ level.custom_buildable_wrong_part_vo ]](); - - return 0; - } - else if ( !isdefined( self.bound_to_buildable ) && !self.buildable_pool pooledbuildable_has_piece( player player_get_buildable_piece( slot ) ) ) - { - if ( isdefined( level.zombie_buildables[self.equipname].hint_wrong ) ) - self.hint_string = level.zombie_buildables[self.equipname].hint_wrong; - else - self.hint_string = &"ZOMBIE_BUILD_PIECE_WRONG"; - - return 0; - } - else if ( isdefined( self.bound_to_buildable ) ) - { - assert( isdefined( level.zombie_buildables[self.equipname].hint ), "Missing buildable hint" ); - - if ( isdefined( level.zombie_buildables[self.equipname].hint ) ) - self.hint_string = level.zombie_buildables[self.equipname].hint; - else - self.hint_string = "Missing buildable hint"; - } - else - { - assert( isdefined( level.zombie_buildables[self.equipname].hint ), "Missing buildable hint" ); - - if ( isdefined( level.zombie_buildables[self.equipname].hint ) ) - self.hint_string = level.zombie_buildables[self.equipname].hint; - else - self.hint_string = "Missing buildable hint"; - } + if ( isdefined( level.zombie_buildables[self.equipname].hint ) ) + self.hint_string = level.zombie_buildables[self.equipname].hint; + else + self.hint_string = "Missing buildable hint"; } else return trigger [[ self.original_prompt_and_visibility_func ]]( player ); @@ -517,8 +428,7 @@ pooled_buildable_place_think() continue; } - slot = bind_to.buildablestruct.buildable_slot; - bind_to = self.stub.buildable_pool pooledbuildable_stub_for_piece( player player_get_buildable_piece( slot ) ); + bind_to = self.stub.buildable_pool pooledbuildable_stub_for_equipname( level.buildables_available[self.stub.buildables_available_index] ); if ( !isdefined( bind_to ) || isdefined( self.stub.bound_to_buildable ) && self.stub.bound_to_buildable != bind_to || isdefined( bind_to.bound_to_buildable ) && self.stub != bind_to.bound_to_buildable ) { @@ -531,7 +441,7 @@ pooled_buildable_place_think() continue; } - status = player player_can_build( bind_to.buildablezone ); + status = player scripts\zm\replaced\_zm_buildables::player_can_build( bind_to.buildablezone ); if ( !status ) { @@ -546,7 +456,7 @@ pooled_buildable_place_think() if ( isdefined( bind_to.onbeginuse ) ) self.stub [[ bind_to.onbeginuse ]]( player ); - result = self buildable_use_hold_think( player, bind_to ); + result = self scripts\zm\replaced\_zm_buildables::buildable_use_hold_think( player, bind_to ); team = player.pers["team"]; if ( result ) @@ -572,12 +482,9 @@ pooled_buildable_place_think() if ( isdefined( self.stub.onuse ) ) self.stub [[ self.stub.onuse ]]( player ); - if ( isdefined( player player_get_buildable_piece( slot ) ) ) - { - prompt = player player_build( self.stub.buildablezone ); - self.stub.hint_string = self.stub.trigger_hintstring; - self pooledbuildabletrigger_update_prompt( player ); - } + prompt = player scripts\zm\replaced\_zm_buildables::player_build( self.stub.buildablezone ); + self.stub.hint_string = self.stub.trigger_hintstring; + self pooledbuildabletrigger_update_prompt( player ); } } @@ -598,6 +505,20 @@ pooled_buildable_place_think() scripts\zm\replaced\_zm_buildables::buildable_place_think(); } +pooledbuildable_stub_for_equipname( equipname ) +{ + foreach ( stub in self.stubs ) + { + if ( isdefined( stub.bound_to_buildable ) ) + continue; + + if ( stub.equipname == equipname ) + return stub; + } + + return undefined; +} + choose_open_buildable( player ) { self endon( "kill_choose_open_buildable" ); @@ -658,19 +579,6 @@ choose_open_buildable( player ) if ( got_input ) { - piece = undefined; - foreach (stub in level.buildable_stubs) - { - if (stub.buildablezone.buildable_name == level.buildables_available[self.buildables_available_index]) - { - piece = stub.buildablezone.pieces[0]; - break; - } - } - - slot = self.buildablestruct.buildable_slot; - player maps\mp\zombies\_zm_buildables::player_set_buildable_piece(piece, slot); - equipname = level.buildables_available[self.buildables_available_index]; self.hint_string = level.zombie_buildables[equipname].hint; self.playertrigger[num] sethintstring(self.hint_string);