OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Cold on 08 Jun 2007, 17:34:07

Title: Slow death
Post by: Cold on 08 Jun 2007, 17:34:07
    Not exactly breaking the mold on mission ideas here; I'm making a special operations mission where a SF team rides in via Blackhawk on some rough-rainy seas... the UH60 drops their zodiak, then the squad. If they manage to clamber onboard in time, they won't lose their loadouts. Enough about that - it's not my issue. The main task they are set with is rescuing a hostage - but it's a tad different this time. The hostage is being interrogated, violently.
     I need a way to decrease the hostages health by 0.1 about every 5-10 minutes. I know I can use setdammage on this, but I don't exactly know how to set a timer for it via a script. Any ideas? Do you need more details?
     
Title: Re: Slow death
Post by: Mandoble on 08 Jun 2007, 18:27:00
Code: [Select]
;hostage.sqs
_hostage = _this select 0

#hostageishit
_hostage setDamage (damage _hostage) + 0.1
~300 + random 300

?player distance _hostage < 10: exit
?!alive _hostage:exit

goto "hostageishit"
Title: Re: Slow death
Post by: Cold on 08 Jun 2007, 21:21:50
Pardon my ignorance please, but am I to name my unit that is to be the hostage anything in particular... or do I call the script from the unit's init line, or from a trigger. I've been through this before, a long time ago.
Title: Re: Slow death
Post by: DucusSumus on 08 Jun 2007, 21:57:37
You need to pass the hostage's name to the script.  One option is in the hostage's init line, write:

Code: [Select]
[this] exec "hostage.sqs"
Title: Re: Slow death
Post by: Cold on 08 Jun 2007, 22:04:12
I should be banging my head into my desk right now... I had tried "this exec "hostage.sqs"; - I forgot that in the script _hostage is an array... Thank you guys very much for helping me with this... maybe I'll actually publish a mission for once when I get it to my satisfaction!
Title: Re: Slow death
Post by: Mandoble on 08 Jun 2007, 22:56:39
In the script, _hostage is not an array, it is a unit.

Lets say your hostage is named peter:
Code: [Select]
[peter]exec"hostage.sqs"
You may also do it from the init line of the hostage unit:
Code: [Select]
[this]exec"hostage.sqs"
Title: Re: Slow death
Post by: Cold on 09 Jun 2007, 00:44:27
I understand now Mandoble. Thank you. I always thought that when units names went in brackets it was called an array. ex. [man1, man2] exec "hostage.sqs".... :dunno: if that would work. Glad it's all clear now though.
Title: Re: Slow death
Post by: h- on 09 Jun 2007, 08:19:08
You never understood anything wrong, things inside brackets are an array.

However, _hostage is not an array but the first element from the array passed into the script, the unit (this/peter) is in the array.
What actually is an array in the script is _this.

_this in scripts references to what is passed into the script when executing it.
[blah] exec "script.sqs", _this would be [blah].
"blah" exec "script.sqs", _this would be "blah", and so on..

Elements in an array start from 0, [element0,element1,element2,...elementN], and thus the line _this select 0 selects the first element of an array.
So, _hostage = _this select 0 picks the first element from the array passed into the script and 'saves' it 'in' the local variable _hostage..


Thought I'd try to explain the situation to avoid any misconceptions..
However my skills to do that are a bit limited so I may have just poured fuel for the fire  :dunno:
Title: Re: Slow death
Post by: Carroll on 19 Jul 2007, 13:38:50
Im doing something similar in that i have 29 civilians in a city, however if any of them are killed damage is given to the player.

the civilians are not grouped and are named Z1 - Z29, and thought to put an exec line in each Civilians INIT line

I've been trying to learn how to script but am not sure where to go from here

_Unit = _this select 0
_Player = _this select 1

?!Alive _Unit
_Player setDamage +0.1

i know it's primitive but i am just learning, and i would be thankful for any help
Title: Re: Slow death
Post by: Mandoble on 19 Jul 2007, 14:16:36
Code: [Select]
// check_civs_damage.sqf
_civs = [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14,Z15,Z16,Z17,Z18,Z19,Z20,Z21,Z22,Z23,Z24,Z25,Z26,Z27,Z28,Z29];

_remove = [];
while {(count _civs > 0) && (alive player)} do
{
   for {[_i=0],[_i < count _civs],[_i = _i + 1]} do
   {
      if (! alive (_civs select _i)) then
      {
         _remove = _remove + [_civs select _i];
         player setDamage ((damage player) + 0.1);
      };
   };
   _civs = _civs - _remove;
   Sleep 2;
};

and into the init.sqs of your mission:
Code: [Select]
[]execVM "check_civs_damage.sqf";
Title: Re: Slow death
Post by: Carroll on 19 Jul 2007, 14:25:41
Jesus, i've got a mountain and a half to climb if i'm to learn what all this is about :blink:
But you don't learn nothin if you don't try, i thought i was doing well with triggers, WP's & chopped up scripts, but this is quite different

Cheers Mandoble, you're a champ, i'll give your script ago  :good: 
Title: Re: Slow death
Post by: Mandoble on 19 Jul 2007, 15:08:17
It is not so hard at all  ;)

Ups, I forgot a _remove = []; in the previous post, check it here.

commented:
Code: [Select]
// check_civs_damage.sqf

// Our initial array with all the civilians
_civs = [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14,Z15,Z16,Z17,Z18,Z19,Z20,Z21,Z22,Z23,Z24,Z25,Z26,Z27,Z28,Z29];

// Temporal array to extract from initial civs array those who are dead, so we will not check them in the next loop iteration
_remove = [];

// While there are civs and player is still alive
while {(count _civs > 0) && (alive player)} do
{
   // Remove is empty here, before checking which civs should be removed from civilian list
   _remove = [];

   // For each civilian still inside _civs array
   for {[_i=0],[_i < count _civs],[_i = _i + 1]} do
   {
      // Is alive?
      if (! alive (_civs select _i)) then
      {
         // If not, it is added to the temporal array to remove civs from _civs array
         _remove = _remove + [_civs select _i];รง

         // Player addes 0.1 to his current damage level
         player setDamage ((damage player) + 0.1);
      };
   };
   // Now we remove from _civs these civs that were marked as dead
   _civs = _civs - _remove;

   // Wait two seconds before next iteration.
   Sleep 2;
};
Title: Re: Slow death
Post by: macguba on 19 Jul 2007, 15:29:12
Quote
i've got a mountain and a half to climb if i'm to learn what all this is about

When you start mission making there is indeed a lot to learn.   That's why OFPEC exists, so we can help each other.   But don't worry - it's worth it.   :)
Title: Re: Slow death
Post by: Carroll on 20 Jul 2007, 09:11:21
_civs = [Z1,Z2,Z3,Z4,Z5,Z6,Z7,Z8,Z9,Z10,Z11,Z12,Z13,Z14,Z15,Z16,Z17,Z18,Z19,Z20,Z21,Z22,Z23,Z24,Z25,Z26,Z27,Z28,Z29];

_remove = [];
while {(count _civs > 0) && (alive player)} do
{
_remove = [];
for {[_i |#| =0],[_i < count _civs],[_i = _i + 1]} do
   {
if (!alive (_civs select _i)) then
   {
_remove = _remove + [_civs select _i];
player setDamage ((damage player) + 0.1);
   };
};
_civs = _civs - _remove;
Sleep 2;
};

*testing the script i get an error telling me there is a missing ] at line 7
Title: Re: Slow death
Post by: h- on 20 Jul 2007, 10:09:34
It should be
Code: [Select]
for [{_i = 0},{_i < count _civs},{_i = _i + 1}]