Good night, all right? I'm doing a puzzle on my map, which will have five objects that should be activated in an order, otherwise the order is reset... Just like the map Malibu Drive makes for hulk... I need to know if the correct object was activated in the same way that the waittill("trigger") does, but need to use in an if/else... Any ideas? Thank you!
Hold all the triggers in order in an array and thread all of them to a secondary function (with array_thread()). In that function waittill (inside a while loop) for the trigger to be triggered and notify something on the level, passing the trigger in the notify, like this:
Code Snippet
Plaintext
self waittill( "trigger" ); // can get also the player if you want and pass it to the other function level notify( "ANY_STRING_YOU_WANT", self );
Then make a loop in the main function that will waittill that level notify and check if the trigger is the next, like:
Code Snippet
Plaintext
// triggers is your array with all the puzzle triggers in order for( i = 0; i < triggers.size; i++ ) { level waittill( "ANY_STRING_YOU_WANT", trig ); if( trig == triggers[ i ] ) { // it's the correct trigger; do whatever you want here } else { i = -1; level notify( "puzzle_reset" ); // so you can make the secondary function wait after a trig has been triggered } } // every trigger has been activated when we're here
RandomizeTriggerOrder(){ //script to randomize the order of triggers to be hit in //thread RandomizeTriggerOrder();//thread this ptrigs = GetEntArray( "ptrigs","targetname" );//all trigger use with same kvp ptrigs ptrigs = array_randomize( ptrigs ); level.lastPuzzleTrig = 0; for( i=0;i<ptrigs.size;i++ ){ ptrigs[i] thread HitMeInOrder(i,ptrigs.size); } } HitMeInOrder(order,done){ self SetCursorHint( "HINT_NOICON" ); // self SetHintString( "" ); while(level.lastPuzzleTrig<done){ self waittill( "trigger", player ); if(int(order) == level.lastPuzzleTrig) level.lastPuzzleTrig++;//might not need int(order), just order (i swear it passes as a string sometimes. Maybe just when it is an attribute...) else level.lastPuzzleTrig = 0; wait(.1);//no spam button } if(order==0) thread PuzzleReward(); } PuzzleReward(){ //replace the following with your reward IPrintLnBold( "You go the right order, here's your reward!" ); }
To test, put as many trigger_use's as you like with targetname ptrigs in radiant
Last Edit: February 16, 2016, 07:07:24 pm by MakeCents
Hold all the triggers in order in an array and thread all of them to a secondary function (with array_thread()). In that function waittill (inside a while loop) for the trigger to be triggered and notify something on the level, passing the trigger in the notify, like this:
Code Snippet
Plaintext
self waittill( "trigger" ); // can get also the player if you want and pass it to the other function level notify( "ANY_STRING_YOU_WANT", self );
Then make a loop in the main function that will waittill that level notify and check if the trigger is the next, like:
Code Snippet
Plaintext
// triggers is your array with all the puzzle triggers in order for( i = 0; i < triggers.size; i++ ) { level waittill( "ANY_STRING_YOU_WANT", trig ); if( trig == triggers[ i ] ) { // it's the correct trigger; do whatever you want here } else { i = -1; level notify( "puzzle_reset" ); // so you can make the secondary function wait after a trig has been triggered } } // every trigger has been activated when we're here
RandomizeTriggerOrder(){ //script to randomize the order of triggers to be hit in //thread RandomizeTriggerOrder();//thread this ptrigs = GetEntArray( "ptrigs","targetname" );//all trigger use with same kvp ptrigs ptrigs = array_randomize( ptrigs ); level.lastPuzzleTrig = 0; for( i=0;i<ptrigs.size;i++ ){ ptrigs[i] thread HitMeInOrder(i,ptrigs.size); } } HitMeInOrder(order,done){ self SetCursorHint( "HINT_NOICON" ); // self SetHintString( "" ); while(level.lastPuzzleTrig<done){ self waittill( "trigger", player ); if(int(order) == level.lastPuzzleTrig) level.lastPuzzleTrig++;//might not need int(order), just order (i swear it passes as a string sometimes. Maybe just when it is an attribute...) else level.lastPuzzleTrig = 0; wait(.1);//no spam button } if(order==0) thread PuzzleReward(); } PuzzleReward(){ //replace the following with your reward IPrintLnBold( "You go the right order, here's your reward!" ); }
To test, put as many trigger_use's as you like with targetname ptrigs in radiant
Thank you! Both ways work fine! A single detail: The script MakeCents, had to change the line:
Sure thing. But... that line I had was only so it thread the reward only once. Your change would thread it for each trigger use you have, which may not be what you want. I'm not sure why it wouldn't thread with my line, but it was just meant to keep it from threading multiple times. you could change it to 1, or maybe you modified something? Doesn't really matter if you got it working, I just didn't want you to thread that reward once per trig is all.
Sure thing. But... that line I had was only so it thread the reward only once. Your change would thread it for each trigger use you have, which may not be what you want. I'm not sure why it wouldn't thread with my line, but it was just meant to keep it from threading multiple times. you could change it to 1, or maybe you modified something? Doesn't really matter if you got it working, I just didn't want you to thread that reward once per trig is all.
I understand... But this way, I can not make the script work properly ...: \ I have a question that arose changing some code... I had to make some changes to when the puzzle is finished, change the trigger does... And for that I used flag, but when active the flag through flag_set (""), the game crashes by some 2 seconds... what could be happening? I tested put flag_set in various places in the script and keeps crashing...
I understand... But this way, I can not make the script work properly ...: \ I have a question that arose changing some code... I had to make some changes to when the puzzle is finished, change the trigger does... And for that I used flag, but when active the flag through flag_set (""), the game crashes by some 2 seconds... what could be happening? I tested put flag_set in various places in the script and keeps crashing...
Did you ever flag_init("flagname");
also, I think the prob with my script was it needed the int like this:
Code Snippet
Plaintext
RandomizeTriggerOrder(){ //script to randomize the order of triggers to be hit in //thread RandomizeTriggerOrder();//thread this ptrigs = GetEntArray( "ptrigs","targetname" );//all trigger use with same kvp ptrigs ptrigs = array_randomize( ptrigs ); level.lastPuzzleTrig = 0; for( i=0;i<ptrigs.size;i++ ){ ptrigs[i] thread HitMeInOrder(i,ptrigs.size); } } HitMeInOrder(order,done){ self SetCursorHint( "HINT_NOICON" ); // self SetHintString( "" ); while(level.lastPuzzleTrig<done){ self waittill( "trigger", player ); if(int(order) == level.lastPuzzleTrig) level.lastPuzzleTrig++;//might not need int(order), just order (i swear it passes as a string sometimes. Maybe just when it is an attribute...) else level.lastPuzzleTrig = 0; wait(.1);//no spam button } if(int(order)==0) thread PuzzleReward();//added int } PuzzleReward(){ //replace the following with your reward IPrintLnBold( "You go the right order, here's your reward!" ); }
also, I think the prob with my script was it needed the int like this:
Code Snippet
Plaintext
RandomizeTriggerOrder(){ //script to randomize the order of triggers to be hit in //thread RandomizeTriggerOrder();//thread this ptrigs = GetEntArray( "ptrigs","targetname" );//all trigger use with same kvp ptrigs ptrigs = array_randomize( ptrigs ); level.lastPuzzleTrig = 0; for( i=0;i<ptrigs.size;i++ ){ ptrigs[i] thread HitMeInOrder(i,ptrigs.size); } } HitMeInOrder(order,done){ self SetCursorHint( "HINT_NOICON" ); // self SetHintString( "" ); while(level.lastPuzzleTrig<done){ self waittill( "trigger", player ); if(int(order) == level.lastPuzzleTrig) level.lastPuzzleTrig++;//might not need int(order), just order (i swear it passes as a string sometimes. Maybe just when it is an attribute...) else level.lastPuzzleTrig = 0; wait(.1);//no spam button } if(int(order)==0) thread PuzzleReward();//added int } PuzzleReward(){ //replace the following with your reward IPrintLnBold( "You go the right order, here's your reward!" ); }
Oh yeah, it worked perfectly now! Thank you! About flag_init ("flagname"), I have not used... I did not know it was necessary to use... Should I use the script from the beginning, or shortly before flag_set?
Oh yeah, it worked perfectly now! Thank you! About flag_init ("flagname"), I have not used... I did not know it was necessary to use... Should I use the script from the beginning, or shortly before flag_set?
To set a flag, it needs to have it init. I'm not following you on the last part. I would init your flag either via kvp, or just manually in your function.
To set a flag, it needs to have it init. I'm not following you on the last part. I would init your flag either via kvp, or just manually in your function.
Ah yes... Thank you for all the information! I understand better now (: