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.
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;
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;
players[i] iprintln( "Replacing switch..." ); wait(level.buildTime); players[i] iprintln( "A new switch has been added!" ); level notify( "buildable_complete" );
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.
Last Edit: September 16, 2015, 10:56:30 pm by daedra descent
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");
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
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");
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
Last Edit: September 17, 2015, 04:12:52 pm by AlecKeaneDUB