Home   Help Search Login Register  

Author Topic: Powerstation and Substation scripts  (Read 2110 times)

0 Members and 1 Guest are viewing this topic.

DBR_ONIX

  • Guest
Powerstation and Substation scripts
« on: 06 Jun 2005, 22:14:30 »
Wrote (using code from this thread as a base), that allows you to :
  • Shut down power to whole island (All non-editor placed street lamps)
  • Restore power to whole island
  • Blow up a substation and take all near-by streetlamps out
Code for substation :
Code: [Select]
;[this,100] exec "substation.sqs"
; User defined varibles
_center = _this select 0
_range = _this select 1

;INIT
_maxid = 200000
_i = 0
_lightArray = []

; Start - Wait for desroyed station
#wait
~1
?(alive _center):goto "wait"

; Middle - Get all street lights
#loop
;one line \/
if ((typeof (object _i) in ["StreetLampPanel","StreetLampMetal","StreetLampWood","StreetLampPanelAmpl","StreetLampYellow","StreetLampCut"]) AND (object _i distance _center > _range)) then {object _i switchlight "OFF"}
;one line /\
_i = _i + 1
if (_i <= _maxid) then {goto "loop"}

;End
exit

Basicly, when the _center (substation) is dead, go from 0 to 200000, checking if current object number (I.e object 1234) is a streetlamp (typeof object _i in array of streetlamp types)
If it's < _range, shut it down

It's not very fast, but it gives it a nice effect of not shutting every light down instantly, it wouldn't happen that fast in reality

Power Station Down :
Code: [Select]
_maxid = 200000
_i = 0
#loop
;one line \/
if (typeof (object _i) in ["StreetLampPanel","StreetLampMetal","StreetLampWood","StreetLampPanelAmpl","StreetLampYellow","StreetLampCut"]) then {(object _i)  switchlight "OFF"}

;one line /\
_i = _i + 1
;if this is startup script, uncomment the following line :
~random(0.1)
if (_i <= _maxid) then {goto "loop"}
exit

The startup script is identcal, apart from the switchlight bit is on, instead of off, and the line that's mentioned in script is uncommented (Makes the lights have a bigger delay when starting up, random between 0 and 0.1 makes lights take abour 10 seconds to come back up)

If this is usefull, I will further develop it, current ideas :
  • Multi-thread the script, make the main script launch another, one handling, say, 1 to 5000, another handling 5001 to 10,000 etc. This will speed up the script a lot
  • Make lights within x of desroyed substations not come back up, ever (add them to "disabled array"
  • Substation objects - I don't recall ever seeing them. The power station exists in AGS Industry Pack, and I use the BIS "modern" computer to run the scripts from (Add action). Only thing missing is the substation to blow up
There may be better way of doing this (Killing all lights on map), but nearestobject doesn't work over 50meters, and isn't very easy making it find secondnearestobject :P

I've attached an script that uses the BIS modern computer as the substation and powerplant controler. You can shut down power to poor Nogava, or take out nearby lamps by desroying it (Shoot it a few times)

Anyway, this thread is kinda long for a simple script like this, but it can have many uses, from civillian RPG missions (Power Station owner killing power to island cause they refused to pay electicity bill? :P), to covert assault missions (Take out the substation, and assault the enemy base under the cover of your artifical darkness) :P

Any comments or sugestions.. erm.. guess what I want you to do :P
If you guessed reply here, your correct
- Ben
[Edit : Added in thread link]
« Last Edit: 07 Jun 2005, 18:48:46 by DBR_ONIX »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Powerstation and Substation scripts
« Reply #1 on: 07 Jun 2005, 18:20:52 »
Strange.   That looks like exactly the same as the code I posted on the attached link.  As I said there - it is not practical.  It takes far too long to run.

http://www.ofpec.com/yabbse/index.php?board=6;action=display;threadid=24021

Odd that you couldn't remember the link - it was only a couple of days earlier.
« Last Edit: 07 Jun 2005, 18:24:06 by THobson »

DBR_ONIX

  • Guest
Re:Powerstation and Substation scripts
« Reply #2 on: 07 Jun 2005, 18:47:45 »
Theres a good reason for it looking similar :P
Thanks for the link, was too tired to go search for the thread, sorry

I'll work on speeding the script up soon
- Ben

Offline Blanco

  • Former Staff
  • ****
Re:Powerstation and Substation scripts
« Reply #3 on: 07 Jun 2005, 19:05:05 »
Actually, I've wrote that script  :)

http://www.ofpec.com/yabbse/index.php?board=8;action=display;threadid=20204;start=0

Beuheu.... who cares?  ::)
I like the idea and don't care it's slow cus it won't happen fast in reality as DBR_ONIX already mentioned.
I wonder how you can speed it up because the loop is constant...
*edit* Oops I didn't read your ideas at the end, could work that way...

Good job anyway.

 
« Last Edit: 07 Jun 2005, 19:14:43 by Blanco »
Search or search or search before you ask.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Powerstation and Substation scripts
« Reply #4 on: 07 Jun 2005, 21:09:24 »
In deed you did Blanco - and if you play to the end of my Abandoned Armies you will see a personal credit to you for that.

The way I used it and the way I recommend it be used is to run it once for an island and note down the IDs then switch them each off explicitly.  I never expected my 'exercise in scripting' to be taken as a practical suggestion.

DBR_ONIX

  • Guest
Re:Powerstation and Substation scripts
« Reply #5 on: 08 Jun 2005, 13:49:48 »
Almost done the multi-thread script. But I have a problem

substation.sqs
[20000,10,this,100] exec "substation.sqs"
Code: [Select]
_total=_this select 0
_threads =_this select 1
_center=_this select 2
_range=_this select 3

_split=_totoal / _threads

_i=0
#loop
_i=_i+1
_s=_split * _i
_e=_s + _split
; Problem caused by this line \/
[_center,_range,_s,_e] exec "substation_m.sqs"
if(_i >= _threads) then {exit}
goto "loop"

HINTing the total IDs and threads etc in this script works fine, but when it's passed to the next script, it returns scaler bool thingy error...

substation_m.sqs :
Code: [Select]
; User defined varibles
_center = _this select 0
_range = _this select 1
_start=_this select 2
_end=_this select 3

;INIT
_maxid = _end
_i = _start

; Start - Wait for desroyed station
#wait
~1
?(alive _center):goto "wait"
hint "Substation down"

; Middle - Get all street lights
#loop
if ((typeof (object _i) in ["StreetLampPanel","StreetLampMetal","StreetLampWood","StreetLampPanelAmpl","StreetLampYellow","StreetLampCut"]) AND (object _i distance _center > _range)) then {object _i switchlight "OFF"}

_i = _i + 1

if (_i <= _maxid) then {goto "loop"}

;End
exit

- Ben
« Last Edit: 08 Jun 2005, 13:50:19 by DBR_ONIX »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Powerstation and Substation scripts
« Reply #6 on: 08 Jun 2005, 14:04:38 »
I think your problem lies in this line:

Code: [Select]
_split=_totoal / _threadsThe extra o in total is not good.

Have you actually tested this in a real situation.  To use enough multi-threads to reduce the execution time to under a minute or so is likely to seriously impact on lag.  All for barely a dozen lamps.
« Last Edit: 08 Jun 2005, 14:05:09 by THobson »

DBR_ONIX

  • Guest
Re:Powerstation and Substation scripts
« Reply #7 on: 08 Jun 2005, 18:38:32 »
Rewriten scripts :
init.sqs
Code: [Select]
_maxid = 200000
_i = 0
onix_SLA=[]

; Get all street lights
#loop
if ((typeof (object _i) in ["StreetLampPanel","StreetLampMetal","StreetLampWood","StreetLampPanelAmpl","StreetLampYellow","StreetLampCut"])) then {onix_SLA = onix_SLA + [_i]}
_i = _i + 1

if (_i <= _maxid) then {goto "loop"}

_i=0
#off
_current = onix_SLA select _i
object _current switchlight "on"
_i = _i+1
?(_i > count onix_SLA):exit
goto "off"
exit

I've turned the lights on there because OFP seems to remeber if they have been of, in editor, I put the lights of, ended the mission, and previewed it again, and was in darkness..
I ran Powerstation up, restarted mission, lights were on..

[this,100] exec "substation.sqs"
Code: [Select]
_center=_this select 0
_range=_this select 1

; Start - Wait for desroyed station
#wait
~1
?(alive _center):goto "wait"

_i=0
#off
_current = onix_SLA select _i

?(((object _current) distance (_center)) < _range):(object _current) switchlight "off"

_i = _i+1
?(_i > count onix_SLA):exit
~random(1)
goto "off"
exit

this addaction ["Power Off","pstation_d.sqs"]
Code: [Select]
_i=0
#off
_current = onix_SLA select _i
object _current switchlight "off"
_i = _i+1
?(_i > count onix_SLA):exit
~random(0.5)
goto "off"

HINT FORMAT ["Total Objects : %1\nTotal Lights : %2",_i,_Lampcount]
exit
(pstation_u.sqs is same, with switchlight "on" instead of off)

Much faster, just off to try scripts on Ocean Island
Thanks for your help, both of you *Writes down names for thanks list* :)

This will almost certainly be used in an RPG mission that just recently started up.
Anyway, better go test it more..
- Ben
« Last Edit: 08 Jun 2005, 19:03:17 by DBR_ONIX »