PDA

View Full Version : SP Scripting - Problem with trigger



the_law
3rd September 2015, 16:52
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:


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.

vanfreddy
3rd September 2015, 17:21
hi ur problem is u get an array level.visibleplaces = getentarray("getseen","targetname");


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[i] notify("patrol_passed");
level.visibleplaces[i] triggerOff();
}
}

checkvisibility()
{
for(i=0;i<level.visibleplaces;i++)
level.visibleplaces[i] thread 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
}

Mitch
3rd September 2015, 17:29
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.

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):

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.

the_law
3rd September 2015, 21:49
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?

Ni3ls
4th September 2015, 10:55
Test with developer 1. It will tells you where the error is

vanfreddy
4th September 2015, 13:35
hi
ya sorry i saw the error but couldnt find a edit button so i hoped u see it.
u have to change the
for(i=0;i<level.visibleplaces;i++) to
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

checkvisibility()
{
for(i=0;i<level.visibleplaces.size;i++)
{
level.visibleplaces[i] thread visibleplacefunc();
wait .05;
}
}

IzNoGoD
4th September 2015, 13:55
Theres no need for that wait there, but you should use


for(i=0;i<level.visibleplaces.size;i++)

note the .size addition.

vanfreddy
4th September 2015, 13:57
ups forgot it again^^

the_law
4th September 2015, 16:39
Oh, okay. I think that clears up the use of getentarray a bit more for me. Thanks for the help guys!

Mitch
4th September 2015, 18:09
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.

930
931