I searched the forum and hadn't found a tutorial for a flashlight... but based on the information I did find, I messed around with the Behaviors and triggers, and I was able to create a flashlight which turns on and off by pressing the spacebar. Keep in mind I am by no means an expert, and there are probably far more efficient ways of doing this, but as a rudimentary flashlight, it works.
First:
You must be creating a map with Campaign units
In the Data Editor, click the Behaviors tab and search "Flashlight", click Raynor - Flashlight, right-click and duplicate object, make sure to copy both Actors and Models data
Click your new duplicate, change the Editor - Editor Prefix to whatever unit you're using (ie: Marine -) and change the Behavior - Name to "Flashlight" or whatever.
You now have a flashlight for your unit.
--
Second: Triggers! (This is what I did... if you can think of an easier way, please feel free)
First, create a Variable (Boolean) and call it Flashlight, leave it off.
Next, in your Map Initialization actions, you need to create two events: under UI > Allow/Disallow Behavior for Player ... here you want to DISALLOW the Behavior (Marine - Flashlight or whatever you called it) for Player 1 (or whatever player you're using)
Now, under Unit > Add Behavior (Player) ... Add 1 Marine - Flashlight to Unit from Player 1
This initializes the behavior for your unit, but the reason you disallow it is so that upon map initialization, it doesn't flash.
--
Now we can assign keys or mouse-clicks to the flashlight. So:
Create 2 Triggers. I used the Spacebar to turn the flashlight ON, when pressed, and OFF when depressed... so name the two triggers SPACE_On and SPACE_Off
In SPACE_On, create an Event: UI > Key Pressed ... Player 1 presses Spacebar down with shift Allow, control Allow, alt Allow ; now under Actions, create a new Action > Set Variable ... Set Flashlight = True (this turns our Boolean Flashlight variable ON)
Copy/paste this into SPACE_Off
Change the Event to Spacebar UP and the Variable to FALSE
Now, when the spacebar is pressed, it will initialize the Flashlight behavior, and when depressed, will cancel it.
--
Finally:
Create a new trigger called Flashlight Trigger (or whatever you want)
Create a new Event ... Timer > Periodic Event ... Every 0.01 seconds of Game Time (means this trigger constantly repeats to check conditions)
Create a new Action ... General > If Then Else ... Create a new Condition > Comparison ... Flashlight == True (if the Flashlight Boolean is ON, Then...)
Create a new Action under Then ... (again) UI > Allow/Disallow Behavior for Player, Allow the Marine - Flashlight behavior for Player 1
Create another Action under Then ... General > Skip remaining actions
Now, copy/paste this OUTSIDE this event, make sure to click the Actions tree and paste.
In the duplication, change Flashlight == FALSE and DISALLOW the Marine - Flashlight for Player 1
-
DONE! Your Marine, or whatever unit should now have a flashlight which turns ON when the spacebar is pressed and OFF when depressed. I hope this was easy to follow, I tried to make it as clear as possible. If you have any issues or questions, feel free.
I'm also interested in knowing whether or not this works for other units, particularly other races. I'm sure it should, but please let me know if you try it.
Good one. It doesnt seem like you need a periodic trigger for that. Just add more condition checking in the trigger with space bar event. Might prevent some lag
When space is down, check if variable is false (light off). If so then proceed to turn behavior on and then set the variable to true. Else ( var= true, light on) turn the behavior off and set the var to false. just 1 trigger is enough
I think you could cut out a lot of this scripting if you attaached the behavior to a pair of abilities on say... the "f" key if you're not using it... and then you could simply use the ability to "turn (f)lashlight on" and "turn (f)lashlight off" to add/remove the behavior (or just make it an upgrade, or a buff if yo udon't want to worry about attaching/removing the behavior)
Also note, while Droganis's solution is very sound programming wise, the event Player presses a Key is VERY VERY laggy and slow... because it allows for your computer to detect key presses from other players, every key pressed triggers the event check. (wasd style games are having problems with this).
I don't think there's any pre-set triggers to change the flashlight behavior of any units. Not that I'm aware of anyway... with a little tweaking this trigger is simple anyway.
I made a more efficient one on a new map... without the actual code, from memory it looks something like this:
Flashlight (Boolean) = false
Event: (key) is pressed down
Condition: If-Then-Else ... IF: NA, THEN: Set Flashlight = true, Play sound "click", Set Behavior (Raynor - Flashlight) for Unit ON. ELSE: Set Flashlight = false, Play sound "click", Set Behavior for Unit OFF.
...this should work, very minimal lag, at least on my map. (programmer's idea - see above posts)
I'll update later with the coding for it.
In SPACE_On, create an Event: UI > Key Pressed ... Player 1 presses Spacebar down with shift Allow, control Allow, alt Allow ; now under Actions, create a new Action > Set Variable ... Set Flashlight = True (this turns our Boolean Flashlight variable ON)
I don't have the "Set Flashlight" or "True" options.
In SPACE_On, create an Event: UI > Key Pressed ... Player 1 presses Spacebar down with shift Allow, control Allow, alt Allow ; now under Actions, create a new Action > Set Variable ... Set Flashlight = True (this turns our Boolean Flashlight variable ON)
I don't have the "Set Flashlight" or "True" options.
Flashlight would be a global boolean variable. You gotta make it first. The action is then called "Set variable".
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
I searched the forum and hadn't found a tutorial for a flashlight... but based on the information I did find, I messed around with the Behaviors and triggers, and I was able to create a flashlight which turns on and off by pressing the spacebar. Keep in mind I am by no means an expert, and there are probably far more efficient ways of doing this, but as a rudimentary flashlight, it works.
First:
You now have a flashlight for your unit.
--
Second: Triggers! (This is what I did... if you can think of an easier way, please feel free)
This initializes the behavior for your unit, but the reason you disallow it is so that upon map initialization, it doesn't flash.
--
Now we can assign keys or mouse-clicks to the flashlight. So:
Now, when the spacebar is pressed, it will initialize the Flashlight behavior, and when depressed, will cancel it.
--
Finally:
-DONE! Your Marine, or whatever unit should now have a flashlight which turns ON when the spacebar is pressed and OFF when depressed. I hope this was easy to follow, I tried to make it as clear as possible. If you have any issues or questions, feel free.
I'm also interested in knowing whether or not this works for other units, particularly other races. I'm sure it should, but please let me know if you try it.
Good one. It doesnt seem like you need a periodic trigger for that. Just add more condition checking in the trigger with space bar event. Might prevent some lag
@progammer: Go
It actually does create a fair amount of lag... what conditions would you suggest?
@QMJ3: Go
When space is down, check if variable is false (light off). If so then proceed to turn behavior on and then set the variable to true. Else ( var= true, light on) turn the behavior off and set the var to false. just 1 trigger is enough
Oh, sweet... I still ended up having to use two triggers, Space down and then the opposite for Space up.
Works the same and saves the FPS. Thanks!
I was able to get it working with one trigger outside the initial, but I wanted it set to be on like a regular flashlight.
Course that would be just for 1 player would just need to fiddle with it for multi player use I would think
I think you could cut out a lot of this scripting if you attaached the behavior to a pair of abilities on say... the "f" key if you're not using it... and then you could simply use the ability to "turn (f)lashlight on" and "turn (f)lashlight off" to add/remove the behavior (or just make it an upgrade, or a buff if yo udon't want to worry about attaching/removing the behavior)
Also note, while Droganis's solution is very sound programming wise, the event Player presses a Key is VERY VERY laggy and slow... because it allows for your computer to detect key presses from other players, every key pressed triggers the event check. (wasd style games are having problems with this).
A couple of units (Tychus, Egon) seem to have flashlights already, I don't suppose it's possible to turn them off?
@KratsAU: Go
I don't think there's any pre-set triggers to change the flashlight behavior of any units. Not that I'm aware of anyway... with a little tweaking this trigger is simple anyway.
I made a more efficient one on a new map... without the actual code, from memory it looks something like this:
Flashlight (Boolean) = false
Event: (key) is pressed down
Condition: If-Then-Else ... IF: NA, THEN: Set Flashlight = true, Play sound "click", Set Behavior (Raynor - Flashlight) for Unit ON. ELSE: Set Flashlight = false, Play sound "click", Set Behavior for Unit OFF.
...this should work, very minimal lag, at least on my map. (programmer's idea - see above posts) I'll update later with the coding for it.
Sorry I mean is it possible to remove them.
Tychus seems to have a built in flashlight, I want to replace it with the behaviour one which I have control over.
@QMJ3: Go
I cant get this part to work
In SPACE_On, create an Event: UI > Key Pressed ... Player 1 presses Spacebar down with shift Allow, control Allow, alt Allow ; now under Actions, create a new Action > Set Variable ... Set Flashlight = True (this turns our Boolean Flashlight variable ON)
I don't have the "Set Flashlight" or "True" options.
Those models such as Tychus that have built-in flashlights would have to have the model edited itself to remove them.
Flashlight would be a global boolean variable. You gotta make it first. The action is then called "Set variable".