Multiple triggers to start an effect at multiple origins.
Moderator: Core Staff
Multiple triggers to start an effect at multiple origins.
Hello everybody,
Working on a level and I want to achieve an effect which isn't working out the way I want to.
Desired effect: Throughout the level are multiple buttons (trigger_use_touch), when one of them is triggered, an effect should be played at multiple origins. To give you an idea: the buttons are fire alarm triggers and I have multiple red lights around the map. I have configured an effect that resembles the flashing light of a fire alarm. I've also defined a sound in a soundalias file that should be played during the effect. Both the FX (flashing light) as well as the sound file are approx 20 secs long and after the 20 seconds the effect should stop (no looped effect). I've put a delay on the trigger_use_touch itself so you can trigger it again after 60 secs.
All script_origins have targetname fire_orig and all triggers have targetname fire_trig so I guess they should both go in an array but my scripting knowledge just isn't sufficient to get it to work.
Have been scavenging forums for some code to get me in the right direction and I've found some but not enough to make it happen. I have a pretty strong feeling that it SHOULD be possible.. now I just need to find out how
If I should different targetnames I would be glad to hear but I kinda went with that because of some other forum posts I read.
Working on a level and I want to achieve an effect which isn't working out the way I want to.
Desired effect: Throughout the level are multiple buttons (trigger_use_touch), when one of them is triggered, an effect should be played at multiple origins. To give you an idea: the buttons are fire alarm triggers and I have multiple red lights around the map. I have configured an effect that resembles the flashing light of a fire alarm. I've also defined a sound in a soundalias file that should be played during the effect. Both the FX (flashing light) as well as the sound file are approx 20 secs long and after the 20 seconds the effect should stop (no looped effect). I've put a delay on the trigger_use_touch itself so you can trigger it again after 60 secs.
All script_origins have targetname fire_orig and all triggers have targetname fire_trig so I guess they should both go in an array but my scripting knowledge just isn't sufficient to get it to work.
Have been scavenging forums for some code to get me in the right direction and I've found some but not enough to make it happen. I have a pretty strong feeling that it SHOULD be possible.. now I just need to find out how
If I should different targetnames I would be glad to hear but I kinda went with that because of some other forum posts I read.
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Multiple triggers to start an effect at multiple origins
Code: Select all
main()
{
level.alarm = false;
thread alarmTrigThink();
thread alarms();
}
alarmTrigThink()
{
fireAlarms = getEntArray("fire_trig","targetname");
for(i=0;i<fireAlarms;i++)
fireAlarms[i] alarmTrig();
}
alarmTrig()
{
while(1)
{
self waittill("trigger"); // Wait for alarm to be touched
level notify("toggleAlarm"); // Send event to turn on/off alarm
thread AutoOff(); // Function to turn off alarm after set time
wait 30; // This alarm is disable for 30 seconds
}
}
alarms()
{
fireAlarmOrigs = getEntArray("fire_orig","targetname");
while(1)
{
level waittill("toggleAlarm"); // Wait for event ON
level.alarm = true;
for(i=0;i<fireAlarmOrigs.size;i++)
fireAlarmOrigs[i] turnOn(); // Turn on the alarm
level waittill("toggleAlarm"); // Wait for event OFF
level.alarm = false;
for(i=0;i<fireAlarmOrigs.size;i++)
fireAlarmOrigs[i] turnOff(); // Turn off the alarm
}
}
autoOff()
{
level endon("toggleAlarm"); // AutoOff stops when alarm is manually triggered
if(level.alarm)
{
wait 60; // auto turn off alarm at 60 seconds
level notify("toggleAlarm");
}
}
turnOn()
{
// Place your 'playFx' and 'soundFx' stuff here for alarms being on.
}
turnOff()
{
// Place your 'playFx' and 'soundFx' stuff here for alarms being off.
}
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Multiple triggers to start an effect at multiple origins
Holy crap.. didn't expect THIS much help this fast Thanks a lot!! I'm on the road right now but as soon as I can position myself behind my computer I'm gonna give this a shot!
Re: Multiple triggers to start an effect at multiple origins
Or, even shorter and without those damn notifies:
Code: Select all
main()
{
level.alarmfx=loadfx("fx goes here");
level.alarmsound="soundalias goes here";
level.armed=true;
thread alarmTrigsetup();
}
alarmTrigsetup()
{
fireAlarms = getEntArray("fire_trig","targetname");
for(i=0;i<fireAlarms;i++)
fireAlarms[i] alarmTrig();
}
alarmTrig()
{
while(true)
{
self waittill("trigger");
if(level.armed)
{
level.armed=false;
turnonalarms();
wait 60;
level.armed=true;
}
}
}
turnonalarms()
{
locations=getentarray("fire_orig","targetname");
for(i=0;i<locations.size;i++)
{
playfx(level.alarmfx,locations[i].origin);
locations[i] playsound(level.alarmsound);
}
}
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Multiple triggers to start an effect at multiple origins
"damn notifies"?
Notify's are the essence of event based programming, why you would discredit their use is beyond me...
My code is also slightly wrong, I must admit, I interpreted the idea as the 'switch' for on and off, so my code would theoretically not work as intended. Use the code provided by IzNoGod (and if you need a manual override switch, feel free to enjoy the easy use notify system )
Notify's are the essence of event based programming, why you would discredit their use is beyond me...
My code is also slightly wrong, I must admit, I interpreted the idea as the 'switch' for on and off, so my code would theoretically not work as intended. Use the code provided by IzNoGod (and if you need a manual override switch, feel free to enjoy the easy use notify system )
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Multiple triggers to start an effect at multiple origins
[offtopic]Drofder2004 wrote:"damn notifies"?
Notify's are the essence of event based programming, why you would discredit their use is beyond me...
I know, I love notifies. It's just that for beginners, it's damn hard to understand how they work. They are also quite a heavy load for the game, so that's why I called them "damn notifies"[/offtopic]
Re: Multiple triggers to start an effect at multiple origins
Something else that you guys are probably able to shed some light on.. I made a new gsc for this script and called it from the mp_mapname.gsc. Now what has struck me before is that it matters in which order you call the scripts (like putting it before the _load or after for instance). I've also used the thread function sometimes in the mp_mapname.gsc and then it also seems to matter. In some forums I read to put all your custom stuff before the _load and on some other I read that it all should be placed after the _load.
Please enlighten me
And to give you an update: I haven't been able to work on it a lot yet.. I went with IzNoGod's code but it hasn't worked so far, tho I must admit I haven't been able to troubleshoot yet (that's also why I asked the question above)..
Anyways, i've put a iprintlnbold in the triggerpart (after level.armed=false) to rule out any fx mistakes on my part but whenever I trigger the buttons nothing happens.
Probably will be able to work on it later today..
Please enlighten me
And to give you an update: I haven't been able to work on it a lot yet.. I went with IzNoGod's code but it hasn't worked so far, tho I must admit I haven't been able to troubleshoot yet (that's also why I asked the question above)..
Anyways, i've put a iprintlnbold in the triggerpart (after level.armed=false) to rule out any fx mistakes on my part but whenever I trigger the buttons nothing happens.
Probably will be able to work on it later today..
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Multiple triggers to start an effect at multiple origins
That doesn't answer the question of 'order of events', that only answers the question of how threading affects the order of events. Simply put, the "_load" is not a threaded function.IzNoGoD wrote:read this
http://modsonline.com/Forums-top-134675.html
Right.megazor wrote:iznogod died
Code: Select all
main()
{
    /* FX Function */
    /* Art Function */
    /* _Load::main */
Â
    /* _compass::setUpMinimap */
Â
    /* *THREAD* YOUR FUNCTION HERE */
Â
    /* setExpFog */
    /* VisionSetNaked */
    /* ambientPlay */
Â
    /* game[] variables */
Â
    /* map specific dvars */
    /* compass range dvar */
}
Stick to the order above, you do not need to put all of them in, but if you do use any, stay in that order. Also, to make you life easier, instead of placing ALL of your 'main' functions in there, place a single function that loads all of your own functions.
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Multiple triggers to start an effect at multiple origins
Well, I'll be damned! Yesterday evening I made an immense reply with al snippets of code I tried, all errors, etc. and the site timed out after clicking submit, Back didn't work so I guess I gotta revert to CTRL-C'ing my posts before posting.
First off I noticed one small mistake in IzNoGod's code: for(i=0;i<fireAlarms;i++) should have fireAlarm.size instead. After I fixed that I stopped getting errors and then the rest of the script seemed to work as well except for the most important thing: the effect and sound did not play.
After trying a whole bunch of things without success I thought it would probably be better to start with ONE trigger and ONE origin and get that to work before starting out with the big guns..
So I made a small testlevel with just one origin, one trigger and customized the script and then it worked!! I put in more origins and switched to getentarray and when using the trigger the effect & sound played at all origins!! Victory is near!! So I figured it wouldn't be a problem to switch to multiple triggers as well but that part still isn't working.
I made two triggers in a level (left & right) and two origins (left & right). When I press either trigger, both origins should play the effect. But it only works on the right trigger. Both triggers have the same targetname (alarm_trig) and target (alarm_orig). When I press the left trigger nothing happens.
This is the code I'm using now:
Any ideas about why only one trigger is working?
First off I noticed one small mistake in IzNoGod's code: for(i=0;i<fireAlarms;i++) should have fireAlarm.size instead. After I fixed that I stopped getting errors and then the rest of the script seemed to work as well except for the most important thing: the effect and sound did not play.
After trying a whole bunch of things without success I thought it would probably be better to start with ONE trigger and ONE origin and get that to work before starting out with the big guns..
So I made a small testlevel with just one origin, one trigger and customized the script and then it worked!! I put in more origins and switched to getentarray and when using the trigger the effect & sound played at all origins!! Victory is near!! So I figured it wouldn't be a problem to switch to multiple triggers as well but that part still isn't working.
I made two triggers in a level (left & right) and two origins (left & right). When I press either trigger, both origins should play the effect. But it only works on the right trigger. Both triggers have the same targetname (alarm_trig) and target (alarm_orig). When I press the left trigger nothing happens.
This is the code I'm using now:
Code: Select all
main()
{
level.alarmfx = loadfx("misc/fire_alarm_light");
level.alarm_sound = "jb_fire_alarm";
level.armed=true;
thread alarmTrigsetup();
}
alarmTrigsetup()
{
fireAlarms = getEntArray("alarm_trig","targetname");
for(i=0;i<fireAlarms.size;i++)
fireAlarms[i] alarmTrig();
}
alarmTrig()
{
while(true)
{
self waittill("trigger");
if(level.armed)
{
level.armed=false;
turnonalarms();
wait 45;
level.armed=true;
}
}
}
turnonalarms()
{
o = getEntArray("alarm_orig","targetname");
for(i=0;i<o.size;i++)
{
playfx(level.alarmfx, o[i].origin);
o[i] playsound (level.alarm_sound);
}
}
-
- Core Staff
- Posts: 2030
- Joined: July 24th, 2006, 11:21 am
- Location: Cramped in a small cubicle/making another jump map
Re: Multiple triggers to start an effect at multiple origins
Just making sure, but you do realize you have to wait 45 seconds(in your case) before you can use either trigger again right? I would also suggest printing debugging lines in all of your functions so you know exactly where the problem is.
Drofder2004: Drofder's rules for reviewing a map
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
[...]
#5 If your name is Rezil, minimum 5/5.
---
<LT>YosemiteSam[NL]:
I heard somewhere that the best way to start is juggling 2 balls with one hand, so you will get a feel for it.
Re: Multiple triggers to start an effect at multiple origins
Yeah those 45 secs were put in deliberately to prevent someone from flooding the alarm. So after 45 secs I can trigger the right trigger again but the left one doesn't do anything. It's also not an "order-thing" cuz if I try the left one just after the level starts nothing happens either, while the right one works perfectly.. I guess only the one with the lowest entity number is working but that's only an assumption, haven't checked that out yet..
Signatures? We don't need no steenking signatures!!
-
- Core Staff
- Posts: 13313
- Joined: April 13th, 2005, 8:22 pm
- Location: UK, London
Re: Multiple triggers to start an effect at multiple origins
Code: Select all
alarmTrigsetup()
{
    fireAlarms = getEntArray("alarm_trig","targetname");
    for(i=0;i<fireAlarms.size;i++)
        fireAlarms[i] thread alarmTrig();
}
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010
Re: Multiple triggers to start an effect at multiple origins
Megazor, Doctor of Scripts, agrees.
Who is online
Users browsing this forum: No registered users and 7 guests