UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: AlecKeaneDUB on September 16, 2015, 10:10:49 pm

Title: Co-Op glitch with this script - Please help
Post by: AlecKeaneDUB on September 16, 2015, 10:10:49 pm
I made this buildables script for my first map release: The Outpost. This script works great on solo (with one exception which I'll explain soon), but on Co-Op it does not work, ruling the map broken and unbeatable.

The issue people have had is that they can pick up the first buildable part and add it to the work bench, but then they(or any of the other players) aren't able to pick up either of the other two. Now, the one exception when playing on solo, is that you must pick up the three parts in a certain order. I'm not sure why this happens, but this was all scripted by me so it doesn't surprise me that it has bugs.

I didn't want to use others' pre-made buildable scripts, because I wanted to take on the challenge of making my own, and not waste time failing at trying to figure out others'. I believe that when I made it, I both succeeded and failed. So I'd love someone to tell me where I went wrong, and maybe help me fix this.

I already know that there are probably things that don't need to be in there, don't make sense, or in the wrong place. So I'd really love help on what I can do to make my map enjoyable to play on Co-Op.

Here's the script:
Code Snippet
Plaintext
#include common_scripts\utility;
#include maps\_utility;
#include maps\_zombiemode_utility;
#include maps\_hud_util;

Precache_buildables()
{
PrecacheModel( "zombie_sumpf_zipcage_switch" );
PrecacheModel( "zombie_sumpf_zipcage_box" );
PrecacheModel( "zombie_modular_wires_single" );
}

main()
{
players = get_players();
for(i=0;i<players.size;i++)
{
players[i].hasAPart = false;
players[i].hasSwitch = false;
players[i].hasWires = false;
players[i].hasBox = false;
}

level.buildTime = 2.5;
level.buildCompleted = false;
level.switchAdded = false;
level.wiresAdded = false;
level.boxAdded = false;

thread init_parts();
thread init_work_bench();
thread init_end_trigger();
}

init_parts(part)
{
//sets up the switch part and trigger
switch_part = getent("switch_part","targetname");
switch_trig = getent("switch_trig","targetname");

switch_trig SetCursorHint("HINT_NOICON");
switch_trig UseTriggerRequireLookAt();
switch_trig SetHintString("Press &&1 To Pick Up Switch");

//sets up the wires part and trigger
wires_part = getent("wires_part","targetname");
wires_trig = getent("wires_trig","targetname");

wires_trig SetCursorHint("HINT_NOICON");
wires_trig UseTriggerRequireLookAt();
wires_trig SetHintString("Press &&1 To Pick Up Wires");

//sets up the box part and trigger
box_part = getent("box_part","targetname");
box_trig = getent("box_trig","targetname");

box_trig SetCursorHint("HINT_NOICON");
box_trig UseTriggerRequireLookAt();
box_trig SetHintString("Press &&1 To Pick Up Electrical Box");

while(isDefined(wires_trig))
{
players = get_players(); // Get all player entities
for(i=0;i<players.size;i++)
{
wires_trig waittill("trigger",player);

if(!players[i] maps\_laststand::player_is_in_laststand() && !players[i].being_revived)
{
if(players[i].hasAPart == true)
{
players[i] iprintln( "You are already carrying a part" );
}

else
{
players[i] iprintln( "You picked up the wires" );
players[i].hasAPart = true;
players[i].hasWires = true;

wires_trig delete();
wires_part delete();
}
}
}
wait 0.05;
}

while(isDefined(switch_trig))
{
players = get_players(); // Get all player entities
for(i=0;i<players.size;i++)
{
switch_trig waittill("trigger",player);

if(!players[i] maps\_laststand::player_is_in_laststand() && !players[i].being_revived)
{
if(players[i].hasAPart == true)
{
players[i] iprintln( "You are already carrying a part" );
}

else
{
players[i] iprintln( "You picked up the switch" );
players[i].hasAPart = true;
players[i].hasSwitch = true;

switch_trig delete();
switch_part delete();
}
}
}
wait 0.05;
}

while(isDefined(box_trig))
{
players = get_players(); // Get all player entities
for(i=0;i<players.size;i++)
{
box_trig waittill("trigger",player);

if(!players[i] maps\_laststand::player_is_in_laststand() && !players[i].being_revived)
{
if(players[i].hasAPart == true)
{
players[i] iprintln( "You are already carrying a part" );
}

else
{
players[i] iprintln( "You picked up the electric box" );
players[i].hasAPart = true;
players[i].hasBox = true;

box_trig delete();
box_part delete();
}
}
}
wait 0.05;
}
}

init_work_bench()
{
bench_trig = getent("add_part_trig","targetname");

bench_trig SetCursorHint("HINT_NOICON");
bench_trig UseTriggerRequireLookAt();
bench_trig SetHintString("Press &&1 To Replace Part");

while(level.buildCompleted == false)
{
players = get_players();
for(i=0;i<players.size;i++)
{
bench_trig waittill("trigger",player);

if(players[i].hasAPart == true && players[i].hasSwitch == true && level.switchAdded == false)
{
players[i] thread do_knuckle_crack();

players[i] iprintln( "Replacing switch..." );
wait(level.buildTime);
players[i] iprintln( "A new switch has been added!" );
level notify( "buildable_complete" );

players[i].hasAPart = false;
players[i].hasSwitch = false;
level.switchAdded = true;
wait 0.1;
continue;
}

if(players[i].hasAPart == true && players[i].hasWires == true && level.wiresAdded == false)
{
players[i] thread do_knuckle_crack();

players[i] iprintln( "Replacing wires..." );
wait(level.buildTime);
players[i] iprintln( "Some new wires have been added!" );
level notify( "buildable_complete" );

players[i].hasAPart = false;
players[i].hasWires = false;
level.wiresAdded = true;
wait 0.1;
continue;
}

if(players[i].hasAPart == true && players[i].hasBox == true && level.boxAdded == false)
{
players[i] thread do_knuckle_crack();

players[i] iprintln( "Replacing electrical box..." );
wait(level.buildTime);
players[i] iprintln( "A new electrical box has been added!" );
level notify( "buildable_complete" );

players[i].hasAPart = false;
players[i].hasbox = false;
level.boxAdded = true;
wait 0.1;
continue;
}

if(players[i].hasAPart == false)
{
players[i] iprintln( "You don't have a part..." );
}
}

if(level.switchAdded == true && level.wiresAdded == true && level.boxAdded == true)
{
bench_trig delete();
level.buildCompleted = true;
level notify( "all_parts_added" );
wait 0.2;
iprintlnbold( "All parts fixed" );
}
}
}

do_knuckle_crack()
{
self DisableOffhandWeapons();
self DisableWeaponCycling();

self AllowLean(false);
self AllowAds(false);
self AllowSprint(false);
self AllowProne(false);
self AllowMelee(false);

if( self GetStance() == "prone" )
self SetStance("crouch");

gun = self GetCurrentWeapon();
self GiveWeapon( "zombie_knuckle_crack" );
self SwitchToWeapon( "zombie_knuckle_crack" );
self waittill_any( "fake_death", "death", "player_downed", "weapon_change_complete", "buildable_complete" );

self EnableOffhandWeapons();
self EnableWeaponCycling();
self TakeWeapon( "zombie_knuckle_crack" );
self SwitchToWeapon( gun );

self AllowLean(true);
self AllowAds(true);
self AllowSprint(true);
self AllowProne(true);
self AllowMelee(true);
self notify("knuckle_crack_done");
}

init_end_trigger()
{
end_game = getent("end_game","targetname");
end_game SetCursorHint("HINT_NOICON");
end_game UseTriggerRequireLookAt();
end_game SetHintString("This switch seems to be broken...");

self waittill( "all_parts_added" );

end_game SetHintString("You need a source of energy...");
//thread init_shoot_trig();

}

I really hope someone can help me, so thanks in advance.
Title: Re: Co-Op glitch with this script - Please help
Post by: daedra descent on September 16, 2015, 10:55:59 pm
Wait, didn't you already ask this before? I definitely remember someone having this issue with this exact script.

Ah well. Your issue is caused by having a while loop that never ends, so the script won't continue. Unfortunately i don't see a way to really fix it without rewriting the function.
Title: Re: Co-Op glitch with this script - Please help
Post by: buttkicker845 on September 17, 2015, 12:34:54 am
this should help with the co-op but im not 100% positive if it will fix the issue. it will for sure help with the having to pick up items in a certain order in solo.
replace your init_parts() method with this method
Code Snippet
Plaintext
init_parts()
{
//sets up the switch part and trigger
switch_part = getent("switch_part","targetname");
switch_trig = getent("switch_trig","targetname");

switch_trig SetCursorHint("HINT_NOICON");
switch_trig UseTriggerRequireLookAt();
switch_trig SetHintString("Press &&1 To Pick Up Switch");

//sets up the wires part and trigger
wires_part = getent("wires_part","targetname");
wires_trig = getent("wires_trig","targetname");

wires_trig SetCursorHint("HINT_NOICON");
wires_trig UseTriggerRequireLookAt();
wires_trig SetHintString("Press &&1 To Pick Up Wires");

//sets up the box part and trigger
box_part = getent("box_part","targetname");
box_trig = getent("box_trig","targetname");

box_trig SetCursorHint("HINT_NOICON");
box_trig UseTriggerRequireLookAt();
box_trig SetHintString("Press &&1 To Pick Up Electrical Box");

box_trig thread part_trig_wait(box_part);
wires_trig thread part_trig_wait(wires_part);
switch_trig thread part_trig_wait(switch_part);

}
and then add this method somewhere in your file
Code Snippet
Plaintext
part_trig_wait(part)
{
while(isDefined(self))
{
self waittill("trigger",player);

if(!player maps\_laststand::player_is_in_laststand() && !player.being_revived)
{
if(player.hasAPart)
{
player iprintln( "You are already carrying a part" );
}

else
{
player.hasAPart = true;
switch(part.targetname)
{
case "box_part" :
player.hasBox = true;
player iprintln( "You picked up the electric box" );
break;
case "wires_part" :
player.hasWires = true;
player iprintln( "You picked up the switch" );
break;
case "switch_part" :
player.hasSwitch = true;
iprintln( "You picked up the wires" );
break;
}

player.hasAPart = true;
player.hasBox = true;

self delete();
part delete();
}
}

wait 0.05;
}
}

beyond this is point is just a few programming tips:
1 when using the
Code Snippet
Plaintext
waittill("trigger",player);

there is no need to fun a for loop for the players since the waittill returns the player that used the trigger
for instance instead of doing this after the trigger waittill("trigger",player);
Code Snippet
Plaintext
				if(players[i].hasAPart == true)
{
players[i] iprintln( "You are already carrying a part" );
}
you can do this(player is no defined as the player that triggered the trigger)
Code Snippet
Plaintext
				if(player.hasAPart == true)
{
player iprintln( "You are already carrying a part" );
}
2. instead of checking if a boolean value is == true such as in your if statment here
Code Snippet
Plaintext
if(players[i].hasAPart == true)
you can do this instead
Code Snippet
Plaintext
if(players[i].hasAPart)
and for false values use
Code Snippet
Plaintext
if(!players[i].hasAPart)
theres a couple of pointers and hopefully helps with your code :)
Title: Re: Co-Op glitch with this script - Please help
Post by: ProGamerzFTW on September 17, 2015, 02:48:25 am
Wait, didn't you already ask this before? I definitely remember someone having this issue with this exact script.

Indeed http://ugx-mods.com/forum/index.php/topic,7063.msg76743.html#msg76743 (http://ugx-mods.com/forum/index.php/topic,7063.msg76743.html#msg76743)
Title: Re: Co-Op glitch with this script - Please help
Post by: AlecKeaneDUB on September 17, 2015, 04:10:43 pm
Wait, didn't you already ask this before? I definitely remember someone having this issue with this exact script.

Ah well. Your issue is caused by having a while loop that never ends, so the script won't continue. Unfortunately i don't see a way to really fix it without rewriting the function.
I did. I asked a while back but I never really got the answer I was looking for. Besides, I worded the whole thread completely wrong...and I wanted to fix all that and clean it up with a new thread

Double Post Merge: September 17, 2015, 04:12:52 pm
this should help with the co-op but im not 100% positive if it will fix the issue. it will for sure help with the having to pick up items in a certain order in solo.
replace your init_parts() method with this method
Code Snippet
Plaintext
init_parts()
{
//sets up the switch part and trigger
switch_part = getent("switch_part","targetname");
switch_trig = getent("switch_trig","targetname");

switch_trig SetCursorHint("HINT_NOICON");
switch_trig UseTriggerRequireLookAt();
switch_trig SetHintString("Press &&1 To Pick Up Switch");

//sets up the wires part and trigger
wires_part = getent("wires_part","targetname");
wires_trig = getent("wires_trig","targetname");

wires_trig SetCursorHint("HINT_NOICON");
wires_trig UseTriggerRequireLookAt();
wires_trig SetHintString("Press &&1 To Pick Up Wires");

//sets up the box part and trigger
box_part = getent("box_part","targetname");
box_trig = getent("box_trig","targetname");

box_trig SetCursorHint("HINT_NOICON");
box_trig UseTriggerRequireLookAt();
box_trig SetHintString("Press &&1 To Pick Up Electrical Box");

box_trig thread part_trig_wait(box_part);
wires_trig thread part_trig_wait(wires_part);
switch_trig thread part_trig_wait(switch_part);

}
and then add this method somewhere in your file
Code Snippet
Plaintext
part_trig_wait(part)
{
while(isDefined(self))
{
self waittill("trigger",player);

if(!player maps\_laststand::player_is_in_laststand() && !player.being_revived)
{
if(player.hasAPart)
{
player iprintln( "You are already carrying a part" );
}

else
{
player.hasAPart = true;
switch(part.targetname)
{
case "box_part" :
player.hasBox = true;
player iprintln( "You picked up the electric box" );
break;
case "wires_part" :
player.hasWires = true;
player iprintln( "You picked up the switch" );
break;
case "switch_part" :
player.hasSwitch = true;
iprintln( "You picked up the wires" );
break;
}

player.hasAPart = true;
player.hasBox = true;

self delete();
part delete();
}
}

wait 0.05;
}
}

beyond this is point is just a few programming tips:
1 when using the
Code Snippet
Plaintext
waittill("trigger",player);

there is no need to fun a for loop for the players since the waittill returns the player that used the trigger
for instance instead of doing this after the trigger waittill("trigger",player);
Code Snippet
Plaintext
				if(players[i].hasAPart == true)
{
players[i] iprintln( "You are already carrying a part" );
}
you can do this(player is no defined as the player that triggered the trigger)
Code Snippet
Plaintext
				if(player.hasAPart == true)
{
player iprintln( "You are already carrying a part" );
}
2. instead of checking if a boolean value is == true such as in your if statment here
Code Snippet
Plaintext
if(players[i].hasAPart == true)
you can do this instead
Code Snippet
Plaintext
if(players[i].hasAPart)
and for false values use
Code Snippet
Plaintext
if(!players[i].hasAPart)
theres a couple of pointers and hopefully helps with your code :)
Thanks a lot man. I'm still learning, so I figured some stuff would be totally wrong. I'll give this a try when I get home and I'll let you know how it goes