Results 1 to 10 of 10

Thread: SP Scripting - Problem with trigger

  1. #1
    Private
    Join Date
    Jan 2015
    Posts
    112
    Thanks
    22
    Thanked 32 Times in 17 Posts

    SP Scripting - Problem with trigger

    Hey guys,

    First of all, I'm aware that most of you are more familiar with MP scripting and modding here at Killtube. Either way, I'm officially stumped about this so I thought I could bring it here to find a solution.

    Here's the situation I'm trying to create: You are walking down a straight road when you are warned that a large enemy patrol is about to round the corner. You quickly find one of three hiding spots to hide in until the patrol passes.

    Here's my code for that:

    PHP Code:
    largepatrol() //called from main()
    {
    level.patrolstarter getent("patrol1","target"); //the trigger that spawns the AI (works), I also use it to start the "hiding" objective
    level.visibleplaces getentarray("getseen","targetname"); //If you touch these triggers, you have been "seen"
    level.patrolstarter waittill("trigger"); 
    thread objective_2(); //Some objective stuff, not important for this problem
    wait 7//Give the player time to hide
    thread checkvisibility(); //NOW we check if the player is visible
    wait 15//By this time, the patrol should be gone
    level notify("patrol_passed");
    level.visibleplaces triggerOff();
    }

    checkvisibility()
    {
        
    self endon("patrol_passed");
        
    level.visibleplaces waittill("trigger");
        
    wait 4.0;
        
    level notify("stealth_failed"); //used to give the player a special custom message when he fails the mission

    Now my problem here is that regardless of where I am, I will fail the mission with the message from "stealth_failed". I already checked for mapping mistakes that may have caused this, and I cannot find such a mistake.

  2. #2
    Private
    Join Date
    Jun 2013
    Posts
    70
    Thanks
    20
    Thanked 32 Times in 26 Posts
    hi ur problem is u get an array level.visibleplaces = getentarray("getseen","targetname");

    PHP Code:
    largepatrol() //called from main() 

    level.patrolstarter getent("patrol1","target"); //the trigger that spawns the AI (works), I also use it to start the "hiding" objective 
    level.visibleplaces getentarray("getseen","targetname"); //If you touch these triggers, you have been "seen" 
    level.patrolstarter waittill("trigger");  
    thread objective_2(); //Some objective stuff, not important for this problem 
    wait 7//Give the player time to hide 
    thread checkvisibility(); //NOW we check if the player is visible 
    wait 15//By this time, the patrol should be gone
    for(i=0;i<level.visibleplaces;i++) 
    {
    level.visibleplaces[inotify("patrol_passed"); 
    level.visibleplaces[i]  triggerOff(); 
    }


    checkvisibility() 

        for(
    i=0;i<level.visibleplaces;i++)
        
    level.visibleplaces[ithread visibleplacefunc();


    visibleplacefunc(ent)
    {
        
    self endon("patrol_passed"); 
        
    self waittill("trigger"); 
        
    wait 4.0
        
    level notify("stealth_failed"); //used to give the player a special custom message when he fails the mission 


  3. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by the_law View Post
    Here's the situation I'm trying to create: You are walking down a straight road when you are warned that a large enemy patrol is about to round the corner. You quickly find one of three hiding spots to hide in until the patrol passes.

    Now my problem here is that regardless of where I am, I will fail the mission with the message from "stealth_failed". I already checked for mapping mistakes that may have caused this, and I cannot find such a mistake.
    The problem is how you manage your triggers.
    PHP Code:
    level.visibleplaces getentarray("getseen","targetname"); //If you touch these triggers, you have been "seen" 
    level.visibleplaces are multiply entities. So the following code doesn't work (you should have gotten error messages while testing this in developer mode):
    PHP Code:
    level.visibleplaces triggerOff();
    level.visibleplaces waittill("trigger"); 
    You could select all those entities and remove the trigger and add them all as one entity. Or if you already have them as one then you only need to change your code to 'getent'.
    Otherwise with multiple entities you need to create a thread for each trigger.

  4. The Following User Says Thank You to Mitch For This Useful Post:

    the_law (4th September 2015)

  5. #4
    Private
    Join Date
    Jan 2015
    Posts
    112
    Thanks
    22
    Thanked 32 Times in 17 Posts
    I tried using vanfreddy's method, but the console throws me an "infinite loop" error. I myself can't really figure out the problem there, as I'm still not experienced with handling multiple entities like that.

    Mitch: You said I could "select all those entities and remove the trigger and add them all as one entity". To be honest, I'm not really sure what you meant: do I do this in Radiant or in the script?

  6. #5
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Test with developer 1. It will tells you where the error is

  7. #6
    Private
    Join Date
    Jun 2013
    Posts
    70
    Thanks
    20
    Thanked 32 Times in 26 Posts
    hi
    ya sorry i saw the error but couldnt find a edit button so i hoped u see it.
    u have to change the
    PHP Code:
    for(i=0;i<level.visibleplaces;i++) 
    to
    PHP Code:
    for(i=0;i<level.visibleplaces.size;i++) 
    and u should always do a isdefined(entity) before u try to use it

    if its still say infinity loop wait a frame
    PHP Code:
    checkvisibility()  
    {  
        for(
    i=0;i<level.visibleplaces.size;i++) 
        {
        
    level.visibleplaces[ithread visibleplacefunc(); 
        
    wait .05;
        }

    Last edited by vanfreddy; 4th September 2015 at 15:00.

  8. The Following User Says Thank You to vanfreddy For This Useful Post:

    the_law (4th September 2015)

  9. #7
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    Theres no need for that wait there, but you should use
    Code:
    for(i=0;i<level.visibleplaces.size;i++)
    note the .size addition.
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  10. #8
    Private
    Join Date
    Jun 2013
    Posts
    70
    Thanks
    20
    Thanked 32 Times in 26 Posts
    ups forgot it again^^

  11. #9
    Private
    Join Date
    Jan 2015
    Posts
    112
    Thanks
    22
    Thanked 32 Times in 17 Posts
    Oh, okay. I think that clears up the use of getentarray a bit more for me. Thanks for the help guys!

  12. #10
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by the_law View Post
    Mitch: You said I could "select all those entities and remove the trigger and add them all as one entity". To be honest, I'm not really sure what you meant: do I do this in Radiant or in the script?
    If you have selected both (or multiple) trig blocks then you can create it as one entity.
    Like how you can have one trigger for the same object e.g. an elevator. One trig block is at the bottom of the elevator and other one is at the top.

    Click image for larger version. 

Name:	example.PNG 
Views:	26 
Size:	677.2 KB 
ID:	930
    Click image for larger version. 

Name:	example2.PNG 
Views:	25 
Size:	228.3 KB 
ID:	931

  13. The Following User Says Thank You to Mitch For This Useful Post:

    kung foo man (5th September 2015)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •