Home   Help Search Login Register  

Author Topic: Mod related - disableable effects.  (Read 934 times)

0 Members and 2 Guests are viewing this topic.

Offline Nemesis6

  • Members
  • *
Mod related - disableable effects.
« on: 05 Sep 2004, 03:40:00 »
Maybe you guys can help me with this -

I'm trying to make the scripts in my mod disableable(is that even a word?)... I've checked how you guys(ECP) do it, but I can't seem to figure it out. My latest thought was adding an init.sqs in the mod folder, containing a lot of global variables that the scripts check right when they are executed. How would you guys do it? Any help appriciated!
I am actually flying into a star... this is incredible!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Mod related - disableable effects.
« Reply #1 on: 05 Sep 2004, 08:47:00 »
Yes, it's done by using global variables...

The easiest way (the only way??) is to put that init.sqs in the mod and execute it with an init eventHandler. The init.sqs defined all the needed global variables to true or false, in which way you would like to do it...

Then, if you have some global variable for say 'hugeSmoke&&Explosion' called TAG_hugeSmoke&&ExplosionOff.
In the init.sqs you have it turned on by having the variable set to false.
Then in the start of the script, before anyhting is passed into it you have
? TAG_hugeSmoke&&ExplosionOff: exit
So when the mission maker sputs TAG_hugeSMoke&&ExplosionOff = true somewhere it prevents that script from running...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
The ECP initialisation system
« Reply #2 on: 05 Sep 2004, 13:00:01 »
First off all go get some coffee, this is gonna be a long post.

MachoMan starts looking for snYpirs extensive ECP guide, which he got when he joined
...... Damned can't find it / don't have it anymore :(

Please keep in mind that I did not design the system, most of the credit has to go to snYpir and some other big brains, so I won't take any credit for it. ;)

First of a History lesson :D

ECP started as a small mod containing something like 20 (I'm just guessing here) scripts.  The system developed for calling these scripts was perfectly sensable, although somewhat complicated and cumbersome. But then again it where only a few scripts, so you were still able to oversee it. Today ECP contains over 100 scripts, when I show u the system u will see it will become huge.
An added problem is that the system draws a lot of pc power when starting missions, because many scripts are loaded. Some pc's are unable to handle this and will crash. Also Savegames will become unusable, because Flashpoint will crash when calling all the scripts again.

The history lesson may become boring, so i'll get to my point. If u plan to use a lot of scripts, I would advise you not to use this system, and if you do, do what every good coder does ......
WRITE GOOD COMMENTS

But back to the system, first off the "filesystem"

Filesystem
ECP uses a lot of map for every script has its own map inside the mod's pbos. In the root ECP map u can find the scripts which create the global variables and even some global scripts, wich are avaible as variables.  (using call)
so this creates a situation that looks like this:
\@ECP\ECP_settings.sqs
\@ECP\etc.sqs

@ECP\Addons\ECP_Blood\
@ECP\Addons\ECP_Effects\


The maps I will be focussing on are the ECP_Effects and the root directory, which contain the global variable setting scripts and the init scripts, which excecute and ready the effect scripts.
 
ECP_Setting.sqs
I will focus on the parts which I worked on, because I'm sure I fully understand those.

I will now show u a part of the IR missile jamming scripts
Code: [Select]
; Jamming system settings
; =======================

;ECP_jam_enable:
;   enable jamming system script? (bool)
? [ECP_jam_enable] call ECP_is_null: ECP_jam_enable = true

;ECP_jam_classes:
   ; List of additional classes that jamming script is init-ed for.
   ; ("Helicopter" and "Plane" defined Automagicly ;) by ECP )
? [ECP_jam_classes] call ECP_is_scalar: ECP_jam_classes = []

; ECP_jam_exempt
   ; list of additional subclasses of those superclasses defined above that are
   ; prohibited from having jamming system effects
? [ECP_jam_exempt] call ECP_is_scalar : ECP_jam_exempt =[]

? [ECP_jam_ammo] call ECP_is_scalar : ECP_jam_ammo = ["AA","9K32"]
        ; List of ammo considered to be IR guided AA.
As you see this code contains more comments than code, this is very important when trying to understand your or other peoples code.
We will start with the first line of code:
Code: [Select]
? [ECP_jam_enable] call ECP_is_null: ECP_jam_enable = trueNow what does this do?
It says, if ECP_jam_enable has not been set (ECP hasn't started yet and/or user hasn't changed it), then turn IR jamming on, in other words: ECP_jam_enable=true

init_once.sqs
So why the hack does it call ECP_is_null?
ECP_is_null is defined in init_once.sqs as:
Code: [Select]
ECP_is_null = {private["_v","_r"]; _v = _this select 0; _r = true; if (format["%1",_v] != "scalar bool array string 0xfcffffef") then {_r = false}; _r}So basicly if u get "scalar bool array string 0xfcffffef" back then ECP is null.

Init.sqs
init_once.sqs is one of the first things excecuted in init.sqs:
Code: [Select]
; =====================
; OBJECT INITIALISATION
; =====================

_veh = (_this select 0)

_assign_ehs = false
? count _this > 1 : _assign_ehs = _this select 1

_null = "scalar bool array string 0xfcffffef"

; path to ECP_Effects scripts
;ECP_path = "\@ECP\Addons\ECP_Effects\"
ECP_path = "\ECP_Effects\"

; launch seperate scripts for vehicle crew
_is_man = true
? "Man" counttype [_veh] == 0 : {[_x] exec format["%1init.sqs",ECP_path]} foreach (crew _veh); _is_man = false

; count the number of units initialised
? format["%1",ECP_num_units] == _null : ECP_num_units = 0; ECP_num_units_initialised = 0
? _is_man : ECP_num_units = ECP_num_units + 1

; initialise ECP
? format["%1",ECP_system_initialised] == _null : ECP_system_initialised = false; ECP_initialised = false; [] exec format["%1init_once.sqs",ECP_path]

; wait until initialisation is complete

@ECP_system_initialised

Now we go to the actual script launching, which is also done in init.sqs:
I have switched to the altitude warning, because it uses a more standart script calling mechanism ;) (the IR jamming uses event handlers)
Code: [Select]
_arr = ECP_alt_classes; _arr_exempt = ECP_alt_exempt; _rtn = 14; goto "is_class"
#lbl_14
? _is_class : [_veh] exec format["%1altitude\altitude.sqs",ECP_path]

U must be thinking by now, oooow nooooo more variables ;), but it gets quite easy right now.
I'll get back to those later, so bare with me, while i explane, _is_class:
Code: [Select]
#is_class

   _is_class = false

   _i = 0
   #is_class_l1
      ? (_arr select _i) counttype [_veh] == 1 : _is_class = true; goto "break1"
      ~0.001
   ? _i < (count _arr) - 1 : _i = _i + 1; goto "is_class_l1"
   #break1

   ? !_is_class : goto "break2"

      _i = 0
      #is_class_l2
         ? (_arr_exempt select _i) counttype [_veh] == 1 : _is_class = false; goto "break2"
         ~0.001
      ? _i < (count _arr_exempt) - 1 : _i = _i + 1; goto "is_class_l2"

   #break2

goto format["lbl_%1",_rtn]

So as u see this checks if a unit is supposed to have a given script running. This also clears up the _rtn = 14 in the last peace of code, it's just a number refering to this piece of code, and tells is_class where to goto when it's done.

Now back to all those nasty variables, they are defined in database.sqs

database.sqs
if we look back to those previous code pieces, we see that they are actually defined by:
ECP_alt_classes &  ECP_alt_exempt
Code: [Select]
; Altitude warning settings
; =========================

; ECP_alt_enable
  ; enable altitude warning? (bool)

? [ECP_alt_enable] call ECP_is_null: ECP_alt_enable = true

? [ECP_alt_classes] call ECP_is_scalar: ECP_alt_classes = []
ECP_alt_classes = ECP_alt_classes + ["Air"]

? [ECP_alt_exempt] call ECP_is_scalar : ECP_alt_exempt = ["ParachuteEast","ParachuteWest","ParachuteC","ParachuteG"]
Hmm recognize this kind of patern, well u should, let's flash back to the entry in ECP_settings.sqs. This time i'll take the altitude warning peace:
Code: [Select]
; Altitude warning Settings
; =========================

; ECP_alt_enable:
   ; enable altitude warning script? (bool)
? [ECP_alt_enable] call ECP_is_null: ECP_alt_enable = true

; ECP_alt_classes:
   ; List of additional classes that Altitude warning script is init-ed for.
   ; ("Helicopter" and "Plane" defined Automagicly ;) by ECP )

? [ECP_alt_classes] call ECP_is_scalar: ECP_alt_classes = []

; ECP_alt_exempt
 ; list of additional subclasses of those superclasses defined above that are
 ; prohibited from having altitude warning effects

? [ECP_alt_exempt] call ECP_is_scalar : ECP_alt_exempt = []
U see, so using database.sqs the empty variables are filled up with whatever u want. (read the comments)

Now if u want to change the fact weather these scripts run, all you need to do is make the global variables defined here changeable by users. (U can use a dialog, like snYpir/ECP did) That's all there's to it.
« Last Edit: 09 Sep 2004, 21:08:05 by MachoMan »
Get those missions out there you morons!

Offline Nemesis6

  • Members
  • *
Re:Mod related - disableable effects.
« Reply #3 on: 08 Sep 2004, 11:12:22 »
*pokes Machoman*
I am actually flying into a star... this is incredible!

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:Mod related - disableable effects.
« Reply #4 on: 08 Sep 2004, 15:49:57 »
yeah, yeah i'll write some more when i had my dinner :P
Get those missions out there you morons!

Offline MachoMan

  • Honoured
  • Former Staff
  • ****
  • KISS, Keep it Simple Stupid
Re:Mod related - disableable effects.
« Reply #5 on: 09 Sep 2004, 21:10:34 »
Ok, I think it's done :D

Just ask if things aren't clear
Get those missions out there you morons!