Sahrani Electrical Grids
by LoyalguardUPDATED: 08 January 2008 - Version 1.05 has been released. Download package (including demo mission) in this post has been updated.
The Sahrani Electrical Grids (SEG) is a package of scripts that simulate electrical power grids on Sahrani by turning off street lamps when the substation that they are "connected to" by the simulation receives more than 50% damage. It also includes an option for mission makers to enable players to manually turn power off and on.
Demo Video at YouTube: Sahrani Electrical Grids DemoNOTE:
You may need headphones in order to hear the substation hum in the video.-Release version and Date: v1.05 - 08 Jan 2008
-No Addons required
-Version 1.08 or later required (compatibility with previous versions not tested)
-Fully SP, MP and JIP compatible
-Demo Mission included
-No known bugs, errors, or issuesDevelopmental Change LogVersion 1.05 (Additional Minor Setup Fix)
-Adjusted how JIP updates are conducted for newly joining players so that the SEG JIP update will not prevent other JIP code required for the mission from running.Version 1.01 (Minor Setup Fix)
-Adjusted how custom sounds for SEG are included in the mission maker's Description.ext file to avoid conflict with other potential custom sounds. See "Mission Maker Instructions" Step 3 in SEG_README.txt.v1.0 (First Final Release)v0.9.3 (Fifth Beta Release)
-Substations emit a humming noise when energized via an additional script (only runs locally while player is near substation to reduce CPU stress)
-Simplified Description.ext implementation instructions by defining sounds via a .hpp #include instead of editing of class CfgSounds in the Description.ext file.v0.9.2 (Fourth Beta Release)
-Added mission maker option to have a buzzer alarm sound at a substation when power is manually turned off/on.
-Simplified and removed unnecessary code for off/on actions. v0.9.1 (Third Beta Release)
-Added three additional scripts (now four in total) to provide added functionality and placed them all in a sub-folder named "SEG" for ease of locating.
-Added easy to use customization options for mission makers to determine which substation grids are created and whether or not to enable players to power off/on substations without having to damage them.
-Adjusted damage requirement routine for Corazol West and East to better conform with the 50% damage threshold model.
-Converted a smaller number of large grid zones to a larger number of small grid zones to reduce CPU stress and network traffic.
-Full MP/JIP Compatibility.
-Removed the ability to repair/rebuild substations due to ArmA engine limitations with JIP.v0.8 (Second Beta Release)
-When power is restored, street lamps are now switched to "auto" instead of "on" so they are only on at night
-Damage requirements for the substation at Corazol West have been adjusted to more closely follow the 50% damage requirement
-Demo Mission is now multiplayer with three player positions for better MP/JIP compatibility testing (must be made a .pbo and loaded to a dedicated server for MP use) First Beta Release was v0.7Demo Mission Only Changes
-Added hint at beginning of mission to orient and instruct new players.
-Added grid zone map to demo mission to better show grid coverage.
-Added playable positions at each substation (in addition to the three already at Dolores) to test each substation grid as desired.
-Added AH-6 to initial spawn point (Dolores) to allow for transportation to other parts of the island to test individual grids.
Switching off street lamps as a result of "power" or "electrical system" events is not a new concept, but to my knowledge this is the first island-wide simulation of electrical power grids in ArmA. This script package simulates seven different electrical power grids on Sahrani by turning off street lamps when the substation that they are "connected to" by the simulation receives more than 50% damage or is manually controlled by a player. The scripts are not complicated, but it took a lot of work to make sure the code syntax was correct (lots of strings within strings and coordinate issues). As such, I spent several weeks making sure it looked clean before posting. Here are the specific features, requirements and notes:Specific Testing Objectives
I have tested this in SP, MP LAN, and on a dedicated server and in all my tests the scripts work as they should (all players, even newly joined, see lights on or off as appropriate). However, I want to make sure it is completely compatible with all game modes before final release.
I am also interested in validation of the features that I have included in the script as well as ease of use regarding changing of custom options to suit mission maker desires. I would also like input on additional features that mission makers might like to make use of in the simulation if feasible.
Lastly, as a new scripter, I am always looking for ways of writing more efficient code. If you find any ways for me to improve the structure or content of my scripts please do let me know! Possible Applications for this Resource
Coop Missions: There are some existing missions by various authors that include "cutting power" to substation as objectives. This script provides a framework for easily creating these types of objectives.
Team vs. Team Missions: In addition to the possibility for TvT objectives, the script also provides for "blackout scenarios" for night ops or persistent missions.
Realistic Game Immersion: For all gametypes; Coop, TvT, Rolepaying; this script makes ArmA more realistic and increases immersion by giving the power substations and the street lights across the island actual functionality.
For more information on how to incorporate SEG into objectives in your mission see "Special Notes and Considerations" in the readme file. How SEG Works
SEG is a package of four scripts located in a sub folder that is placed inside the mission folder.
The primary script, SEG_Init.sqf, creates a game logic and multiple triggers for each of the substations on the island that work in concert to simulate an electrical power grid as follows:
A game logic is placed within the perimeter of each substation and through the nearestObject command it finds one of the two possible type of transformer class objects in ArmA ("Land_trafostanica_velka") which are present at all substations.
One trigger monitors the current damage level of every large transformer within the 50m range of the game logic. When damage exceeds 50% it activates and broadcasts publicly they change in power status to the server and all game clients. Mission makers also have the option to enable the creation of two additional triggers that give nearby players an action menu option to turn power off and on (one trigger for each) without having to damage the substation. If used, they also broadcast publicly the change in power status.
When a change in power status is broadcasted (either by damage or manual action), another trigger that controls the power to the street lamps is activated and it in turn executes the second script: SEG_Events.sqf. Instead of a separate script for each trigger event, they are combined in a single .sqf and and only the pertinent code is executed each time using a switch-do statement bock. When executed, every street lamp within a specific radius of the trigger using the nearObjects command is located and turned off by the switchLight command. Because some substations "supply" power to more than one zone, additional commands may be included.
All the possible manual off/on actions for the substations are created by the addAction command in the appropriate trigger and execute the corresponding code in the third script: SEG_Actions.sqf. Instead of a separate script for each AddAction, they are combined in a single .sqf and and only the pertinent code is executed each time using a switch-do statement bock.
The fourth script in the folder is SEG_JIPUpdate.sqf. This script is executed by SEG_Init.sqf after all pertinent substations (and their corresponding global variables) have been created. The script broadcasts publicly the current condition of each variable so that all players in-game see the same lights on or off as appropriate.
The fifth script, SEG_SubHum.sqf, is activated by a trigger at each substation that makes the substation emit an electrical humming noise while the player is close enough to hear it.
The scripts are fully commented for ease of review. Since the code creating the variables, logic, and triggers for each substation is so similar, only the code for the first substation (Paraiso) is commented (but all subsequent substations use near identical code except for positions, logic, trigger, and variable names).
The Readme contains full details on how the script pack works.
These are just a few of the various scenarios that can be developed using this script as a framework. There are many more possibilities depending on how creative and/or complicated the mission designer wants to get.
I gathered snippets and found relevant advice for making of this script from Mandoble and bardosy; Balschoiw, pauld, and lebon506th at the BIS Forums; and Strag and Shiner at the TacticalGamer.com Forums. Full acknowledgments and relevant threads are listed in the readme.