UGX-Mods

Call of Duty 5: World at War => Help Desk => Scripting => Topic started by: AlecKeaneDUB on June 13, 2015, 04:19:30 pm

Title: Need help fixing a bug in this script
Post by: AlecKeaneDUB on June 13, 2015, 04:19:30 pm
I released my map (The Outpost - Challenge Map) like a month ago and I've gotten feedback about a major bug in this script that keeps you from completing the easteregg/beating the map when playing Co-op. It works great on solo but i dont know what the problem is on Co-op and I really dont have time to look through every bit of my code to try and test things until i fix it. So any scripters, if you can please help me out I'd really appreciate it

I have not personally played my map on co-op, but people say that you cant pickup certain parts or something? I'm not entirely sure but you can play the map with a friend or two yourself or you can check the comments on the map's thread:
http://ugx-mods.com/forum/index.php?topic=6733.0 (http://ugx-mods.com/forum/index.php?topic=6733.0)

Here's my entire buildables script: (I know its probably very poorly written and sloppy but this was my first large 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();

}

init_shoot_trig()
{
shoot_trig = getent("shoot_trig","targetname");
requiredWeapon = "zombie_thompson_upgraded";

while(1)
{
shoot_trig waittill("trigger", player);
weapon = player getcurrentweapon();

if(requiredWeapon == "zombie_thomspon_upgraded" || weapon==requiredWeapon)
{
shoot_trig delete();
thread init_end_game();
wait 0.1;
break;
}
}
}

init_end_game()
{
level notify ( "energy_shot" );
wait 0.5;
maps\nazi_zombie_114cabin::end_game();
}
Title: Re: Need help fixing a bug in this script
Post by: daedra descent on June 13, 2015, 04:38:07 pm
I'm guessing it has something to do with the fact that you use 3 while loops in the same function. The second or third while loop won't start until the first while loop ends. My suggestion would be to put each loop in its own function and just thread call each function. That should atleast fix the issue with players not being able to grab certain parts until they add the part before it.

Title: Re: Need help fixing a bug in this script
Post by: Dust on June 13, 2015, 04:54:52 pm
I played this map on co-op, and I know you said you had to pick up the first part in the spawn room, before you can pick up the second one, and the second one before the third. But when we played it even after we placed the first part, we couldn't pick up the second part, or the third one. On solo, it worked fine though.
Title: Re: Need help fixing a bug in this script
Post by: AlecKeaneDUB on June 13, 2015, 05:26:51 pm
I played this map on co-op, and I know you said you had to pick up the first part in the spawn room, before you can pick up the second one, and the second one before the third. But when we played it even after we placed the first part, we couldn't pick up the second part, or the third one. On solo, it worked fine though.
Yes thats exactly the problem I want fixed. And like daedra said, the problem of having to pick up and add parts in order is because of the triple while loop. That I can fix but I cant find the issue with co-op :\
Title: Re: Need help fixing a bug in this script
Post by: BluntStuffy on June 13, 2015, 07:36:54 pm
...but i dont know what the problem is on Co-op and I really dont have time to look through every bit of my code to try and test things until i fix it...

...I have not personally played my map on co-op, but people say that you cant pickup certain parts or something?

If you dont even want to spend time fixing your scripts why would we want to? Sounds a bit weird  to me, the way you put it there... But ok, maybe this helps.


This really doesn't make too much sense:
Code Snippet
Plaintext
				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;

Try reading it like this, maybe that clears it up a bit..
Code Snippet
Plaintext
				user = undefined;							

// players = get_players(); // You dont need this
// for(i=0;i<players.size;i++)
// {
wires_trig waittill("trigger",user);

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

else
{
user iprintln( "You picked up the wires" );
user.hasAPart = true;
user.hasWires = true;

wires_trig delete();
wires_part delete();
}
}
// }
wait 0.05;
Title: Re: Need help fixing a bug in this script
Post by: Harry Bo21 on June 13, 2015, 10:04:10 pm
If you dont even want to spend time fixing your scripts why would we want to? Sounds a bit weird  to me, the way you put it there... But ok, maybe this helps.


This really doesn't make too much sense:
Code Snippet
Plaintext
				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;

Try reading it like this, maybe that clears it up a bit..
Code Snippet
Plaintext
				user = undefined;							

// players = get_players(); // You dont need this
// for(i=0;i<players.size;i++)
// {
wires_trig waittill("trigger",user);

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

else
{
user iprintln( "You picked up the wires" );
user.hasAPart = true;
user.hasWires = true;

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

lol yea the way he wrote that wasnt really ideal was it lol

"I cant be assed, so can one of you mugs do it for me, what evs ill be back to pick up my completed homework" lol  :troll:
Title: Re: Need help fixing a bug in this script
Post by: AlecKeaneDUB on June 14, 2015, 10:30:36 pm
If you dont even want to spend time fixing your scripts why would we want to? Sounds a bit weird  to me, the way you put it there...
lol yea the way he wrote that wasnt really ideal was it lol

"I cant be assed, so can one of you mugs do it for me, what evs ill be back to pick up my completed homework" lol  :troll:

I just knew that I'm not good enough at scripting to fix this and I didnt want to admit it :\ I honestly looked at it for a really long time but i still suck so I had no idea where to even look for the problem, so I just said that I didnt have the time to look through it. I didnt mean for it to make me sound like an asshole, so my bad for that
Title: Re: Need help fixing a bug in this script
Post by: Harry Bo21 on June 14, 2015, 11:52:48 pm
I just knew that I'm not good enough at scripting to fix this and I didnt want to admit it :\ I honestly looked at it for a really long time but i still suck so I had no idea where to even look for the problem, so I just said that I didnt have the time to look through it. I didnt mean for it to make me sound like an asshole, so my bad for that
lol its alright, I meant that as a joke ;)  :D

We know what you meant ;)

I have a fully functional craftables script you can use instead if you want, its not the one in the tutorials section here, as I havent released it yet. Hit me up if you want it
Title: Re: Need help fixing a bug in this script
Post by: daedra descent on June 15, 2015, 03:19:05 am
I just knew that I'm not good enough at scripting to fix this and I didnt want to admit it :\ I honestly looked at it for a really long time but i still suck so I had no idea where to even look for the problem, so I just said that I didnt have the time to look through it. I didnt mean for it to make me sound like an asshole, so my bad for that

Did putting each loop into its own function and threading it help any? What about BluntStuffy's suggestion?

There really isn't anything else thats wrong with the script besides optimizations that i can see. It should do the job in both SP and COOP.

Edit: Actually now that i look through the whole script, i do see another issue with your shootable trig function:

Code Snippet
Plaintext
if(requiredWeapon == "zombie_thomspon_upgraded" || weapon==requiredWeapon)

This if statement will always evaluate to true, regardless of what weapon the player actually has. Not sure if you want it like that or not but if you don't you should change the two pipes '||' with '&&'.