Home   Help Search Login Register  

Author Topic: Radiological Hazard  (Read 3314 times)

0 Members and 1 Guest are viewing this topic.

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Radiological Hazard
« on: 26 Dec 2008, 07:01:56 »
How would one go about creating a radioactivity effect that damages infantry,
both in and out of vehicles?

Luke
Pesky Human!!
Wort Wort Wort.

Offline Ext3rmin4tor

  • Members
  • *
Re: Radiological Hazard
« Reply #1 on: 26 Dec 2008, 15:21:54 »
You can do that in this way:

First create a trigger as large as the area affected by radiological hazard (you can choose any of the two available shapes, I would go for the circle shape and not the rectangular one since it's more realistic, usually radiation level decreases with the distance from the center of the radiation source):

Set the trigger parameters like this:

ACTIVATED BY: Anyone, Repeatedly
TYPE: None
CONDITION: this
ON ACTIVATION: call{[thisList, 0.01, []] execVM "radiationSource.sqf"}

then use the following script (call it radiationSource.sqf or change the name in the trigger field if you use another name)

Code: [Select]
/* SYNTAX: [unitArray, radiationLevel, shieldedVehicleArray] execVM "radiationSource.sqf"


VARIABLES: unitArray: Array - Array of units affected by the radiation source

radiationLevel: Number - damage each units will suffer while staying nearby the radiation source
(damage is added every second, so 0.1 means the unit will lose 0.1 of health each second, 1 means
instant death)

shieldedVehicleParam: Matrix - Matrix containing a couple of values [className, damageScale] which
represents the damage reduction in percentage for the units inside the given vehicle
(for example modern tanks are shielded against radiation sources, so you can use this to reduce
the damage for units inside a vehicle).
If you are not interested in vehicle damage reduction just pass the script an empty array [].


NOTES: You should call this script from a trigger with a certain area, so you can pass the thisList array to the
script. For example a call could be

call{[thisList, 0.1, []] execVM "radiationSource.sqf"}

*/



//local function used to check how many units are alive in an array
_areAlive =
{
_count = 0;
{
if (alive _x) then {_count = _count + 1};
}
forEach _this;

_count
};


//initializing local variables
_unitArray = _this select 0;
_damage = _this select 1;
_vArray = _this select 2;

//number of units who activated the trigger
_currentAliveUnits = _unitArray call _areAlive;

while {_currentAliveUnits > 0} do
{

//compute and apply the damage factor for each unit in unitArray
{
_damageRed = 0;

//triggering unit is in a vehicle
if (count crew vehicle _x > 0) then
{
_v = vehicle _x;
//check if the vehicle in which the unit is mounted is radiation shielded
{
if ((_x select 0) == (typeOf _v)) then {_damageRed = _x select 1};
}
forEach _vArray;
};

_totalDamage = _damage - (_damage / 100 * _damageRed);

if (_totalDamage <= 0.001 and _x == player) then {hint "Warning - Low radiation source detected"}
else
{
if (_totalDamage <= 0.01 and _x == player) then {hint "Warning - Medium radiation source detected"}
else
{
if (_x == player) then {hint "Warning - Strong radiation source detected"};
};
};

//set the current damage for the unit
if (count crew _x > 0) then
{
{_x setDamage ((damage _x) + _totalDamage)}  forEach crew _x;
}
else {_x setDamage ((damage _x) + _totalDamage)};

//DEBUG
player sidechat format["%1 health is %2", player, 1 - (damage player)];
}
forEach _unitArray;

sleep(1);
_currentAliveUnits = _unitArray call _areAlive;
};

The script works like this: the first parameter is a unit array containing the units affected by the radiation source. In this case you pass the thisList variables since the radiation source is an area represented by the trigger area. The third parameter is a matrix, that is an array of arrays. Each element contains a couple made of a vehicle classname and a percentage of damage reduction. I made this because certain tanks and armored vehicles are partially shielded against radiations. If you're not interested in damage reduction you can pass the script an empty array.

EXAMPLE: You want to create a radiation source which damage the health of the units by 10% each second and no vehicle is shielded against it. You create a trigger just as I told you before then in the activation field write

call{[thisList, 0.1, []] execVM "radiationSource.sqf"}

EXAMPLE: You want to create a radiation source which damage the health of the units by 10% each second and you want that both T72 and M1A1 are shielded and reduce the radiation level by 75%, then you write

call{[thisList, 0.1, [["M1Abrams", 75], ["T72", 75]]] execVM "radiationSource.sqf"} (watch the square brackets since you have a lot of arrays!)

You can find all the vehicle classnames here:
http://www.ofpec.com/COMREF/index.php?action=read&id=73


You can also add multilevel radiation source, that is a different scale of damage based on the distance from the center of the source. You just have to place concentric triggers whose area becomes as larger as they are farther from the radiation source. In each trigger put a different value for the radiation damage when you call the script. Remember that the damage is summed among all the trigger that are currently active

EXAMPLE: You want to make a 3-level radiation source, that damages the player by 10% of his health when he's 50m close to it, by 1% when he's between 50m and 100 m and by 0.1% when he's from 100 to 200m close to it.
Create three triggers:

TRIGGER 1:
SIZE: a = 50, b = 50, circle
ACTIVATION: Anyone - Repeatedly
CONDITION: this
ON ACTIVATION: call{[thisList, 0.089, []] execVM "radiationSource.sqf"}

Note that the damage is 0.089 and not 0.1 because when you're inside this trigger you're both inside TRIGGER2 and TRIGGER 3 (see below) and the damage of all the 3 triggers is summed since 3 instances of the script are running at the same time (every second it adds 0.089 + 0.01 + 0.001 damage to the player).

TRIGGER 2:
SIZE: a = 100, b = 100, circle
ACTIVATION: Anyone - Repeatedly
CONDITION: this
ON ACTIVATION: call{[thisList, 0.009, []] execVM "radiationSource.sqf"}

This time we use 0.009 because both TRIGGER2 and TRIGGER3 are active when a unit is inside it so 0.009 + 0.001 = 0.01 damage is added every second.

TRIGGER 3:
SIZE: a = 200, b = 200, circle
ACTIVATION: Anyone - Repeatedly
CONDITION: this
ON ACTIVATION: call{[thisList, 0.001, []] execVM "radiationSource.sqf"}

The last trigger has the normal damage value since it's the only active when the unit is far from the radiation source more than 100m.


Finally you can add some effects to signal that a unit has entered a hazardous location, for example you can add a Geiger counter sound which is played as long as the unit is inside the area (but you have to modify the script and define the class for the sound in the mission description.ext file), or you can add a HUD image displaying the radiation hazard symbol using dialogs but you have to ask Mandobole for a better explanation since I'm not very good at scritping this kind of stuff. In my script I simply put a hint message which changes depending on the level of radiation (Strong, medium and low).

« Last Edit: 26 Dec 2008, 15:40:02 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Luke

  • Members
  • *
  • Thank God! The OFPEC Staff are here!
Re: Radiological Hazard
« Reply #2 on: 26 Dec 2008, 20:54:17 »
This is a fantastic amount of work, and I can see you live up to your name. :D

However, would it be possible to use a source point,
and rather than use triggers,
instead use the distance value?

Code: (Radiation.sqf) [Select]
_sourcepos=_this select 0;
_Distance=_this select 1;
_half_life=_this select 2;

_dt=daytime;

_affect_distance=_distance;

_nearobjects= nearestobjects [_sourcepos,"Men",_distance];

while {affect_distance>5} do
{
   _t=(daytime-_dt)*3600;
   {
   _affect_distance=_distance*(sqrt(_half_life)*.5)^_t;
   _damage=.000001;
   _times_dealt=((_x distance _sourcepos)^2)/(_affect/_distance)^2;
   _x setdammage (getdammage _x + _dammage);
   sleep (1/_times_dealt);
   } foreach _nearobjects;
   _nearobjects= nearestobjects [_sourcepos,"Men",_affect_distance];
};


Would something like that work?

Luke
Pesky Human!!
Wort Wort Wort.

Offline Ext3rmin4tor

  • Members
  • *
Re: Radiological Hazard
« Reply #3 on: 27 Dec 2008, 12:08:09 »
Yes it might work. If I get it well, you basically used the formula for radiation decay and nearestObject. But I don't get why you want to use such a complicated script when you can use triggers.

By the way I read some dialog tutorials and it won't be too difficult to add a HUD radiation display and a Geiger counter sound. I've already found the media, when I'm done with the code I'll post it.

EDIT: I made the HUD interface with the radiation hazard symbol and added a Geiger counter sound

« Last Edit: 31 Dec 2008, 16:35:24 by Ext3rmin4tor »
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline SAF_Biffa

  • Members
  • *
    • New France Old England
Re: Radiological Hazard
« Reply #4 on: 15 Jan 2009, 14:31:44 »
Ext3, was looking for something similiar to this to represent hyperthermia damage.

It's a simple idea but wondered just how much scripting work it would entail?

Hyperthermia damage:

Snow blizzards and minus temperatures (especially at night)- the whole map.

Avoiding or recovering from Hyperthermia damage:

Lighting a fire ( :whistle:), Healing food, Inside a building.

Anything as complicated as above would be beyond my ability, minus temperatures would probably be the easiest to implement via a trigger then recovery through healing food as the most basic representation of exsposure.

Offline Ext3rmin4tor

  • Members
  • *
Re: Radiological Hazard
« Reply #5 on: 16 Jan 2009, 11:59:37 »
It requires more code than mine, because you need to implement a function that checks if you are near special "healing" objects. Besides you should make a temperature decrease system based on the day time (but this is not very difficult). But the code for the main script (the area damage script) is someway similar to this one.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!