OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: laggy on 14 Feb 2009, 21:01:53

Title: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 21:01:53
In my detect dead body script I want to make it possible to set a variable (LAGGY_FindBody_checkaccidents) to true or false concerning accepting if the dead unit was killed even by accident or just fire.

My script earlier dealt with checking the config side of the dead unit and the unit that finds a dead body, but since I now want the script to care about the "current" side of the finding unit I have to convert a number into a string or text. This I can't get working.

The "side" of the dead unit still needs to be a number based on config, since all dead units become civilian.

Let's see:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == EAST) AND (LAGGY_BodyAndFinderCombo select 1 == EAST)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
       };

This is the script that checks for different combinations.

Then the eventhandler:

Code: [Select]
_deadguy = _this select 0;
_killer = _this select 1;
_numsidedeadguy = getNumber (configFile >> "CfgVehicles" >> typeOf _deadguy  >> "side");

if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

_killerside = side _killer;

sleep 1;

if (! (LAGGY_FindBody_checkaccidents) AND (_deadguyside == _killerside)) exitWith {};

while { _deadguyside != _killerside AND ! (alive _deadguy) } do
{
_finders = nearestObjects [vehicle _deadguy, ["AllVehicles"], LAGGY_FindBody_searchradius];
   if (count _finders > 1) then
   {
      {
         if (_x != vehicle _deadguy AND (alive _x)) then
         {
            if ((_x knowsAbout vehicle _deadguy > 0) AND (_x knowsAbout vehicle _deadguy >= LAGGY_FindBody_awareness)) then
            {
               _searcherside = side _x; call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside]; publicVariable "LAGGY_BodyAndFinderCombo"; sleep 5;
            };
         };
      } forEach _finders;
   };
sleep 2;
};

It doesn't work and I get NO error messages.

Laggy

Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Planck on 14 Feb 2009, 21:06:20
Does it make a difference if you use quotes or not?

i.e.  "EAST" instead of EAST.


Planck
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 21:11:54
Did tests with a trigger:

Condition: side player == WEST
This works as wanted.

Condition: side player == "WEST"
ArmA says when "okaying the trigger": Generic error in expression.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Planck on 14 Feb 2009, 21:14:13
Never mind the trigger, what about in a script?

Probably no difference, but would be good to check.

EDIT: Ignore me, I forgot they are names of sides in the game, unless you specified a string somewhere.


Planck
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 14 Feb 2009, 21:18:24
Code: [Select]
...
               _searcherside = side _x; call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside]; publicVariable "LAGGY_BodyAndFinderCombo"; sleep 5;...


LAGGY_BodyAndFinderCombo will contain something like [0, "WEST"].
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 21:20:06
So the number "1" converted into "WEST" solution doesnt work?

The reason I ask this question is because of my wanted solution:

if (! (LAGGY_FindBody_checkaccidents) AND (_deadguyside == _killerside)) exitWith {};

I want to solve the == issue and unless I can convert a number into a string that reads as "side", the script will be more complicated and powerhungry.

Laggy
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Planck on 14 Feb 2009, 21:26:35
If it is "1", wouldn't:

if (_numsidedeadguy == 1)

fail?

Unless you converted it to a number first.


Planck
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 21:29:26
I used to have:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == 0) AND (LAGGY_BodyAndFinderCombo select 1 == 0)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
};

This worked perfectly well, now when I want the script to be able to read:

Code: [Select]
if ((LAGGY_BodyAndFinderCombo select 0 == EAST) AND (LAGGY_BodyAndFinderCombo select 1 == EAST)) then
{
   hint "OPFOR corpse detected by OPFOR unit";
};

It doesn't work.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 14 Feb 2009, 22:02:44
Uhm, wait a minute... LAGGY_BodyAndFinderCombo will contain two strings!

So you send two strings ...
Code: [Select]
call compile format ["LAGGY_BodyAndFinderCombo = [%1, %2]",  _deadguyside,_searcherside];
publicVariable "LAGGY_BodyAndFinderCombo";
... but you expect two sides:
Code: [Select]
LAGGY_BodyAndFinderCombo select 0 == EAST
Why do you use call compile format at all? Why don't you simply send two sides?

Code: [Select]
LAGGY_BodyAndFinderCombo = [_deadguyside,_searcherside];
publicVariable "LAGGY_BodyAndFinderCombo";
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 22:35:51
I see your point, but the old script works, regardless.
I'm not sure that this conversion works though.

Code: [Select]
if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

What I want is to convert the config based _numsidedeadguy (which is  a number 0-3) to a variable called _deadguyside (being a string), EAST, WEST etc. Then _killerside is simply based on "side" which is a string.

I then want to be able to check if _deadguyside == _killerside.

Cheers!



Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Rommel92 on 14 Feb 2009, 23:00:28
Code: [Select]
private"_deadguyside";
if (_numsidedeadguy == 0) then {_deadguyside = EAST};
if (_numsidedeadguy == 1) then {_deadguyside = WEST};
if (_numsidedeadguy == 2) then {_deadguyside = GUER};
if (_numsidedeadguy == 3) then {_deadguyside = CIV};

Don't worry, I've spent hours trying to figure this out before, your codes fine. Most people fix this by declaring '_deadguyside' before they go into a seperate scope, but a private works just as well.

Check WorldEaters cleaner code below!
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 14 Feb 2009, 23:02:19
1. If you haven't declared _deadguyside private (http://community.bistudio.com/wiki/private_variableNameList) before it won't work.
2. Since GUER and CIV are no sides (http://community.bistudio.com/wiki/Side) it won't work. [1]
3. It could be written slightly more elegant:

Code: [Select]
_deadguyside = [east,west,resistance,civilian] select _numsidedeadguy;


[1] ArmA thinks GUER and CIV are uninitialized global variables. So _deadguyside might become nil (http://community.bistudio.com/wiki/nil).
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Rommel92 on 14 Feb 2009, 23:07:36
2. Since GUER and CIV are no sides (http://community.bistudio.com/wiki/Side) it won't work. [1]

Sides: "WEST", "EAST", "GUER", "CIV", "LOGIC" or "UNKNOWN".

note: returned as values not strings.

So:

Code: [Select]
_deadguyside = [east,west,guer,civ,logic] select _numsidedeadguy;
 ???

followed from your link: http://community.bistudio.com/wiki/side

edit: Neither of us is wrong: http://community.bistudio.com/wiki/resistance

Both sets of code will work Laggy! (both mine and Worldeaters)

edit2:
[1] ArmA thinks GUER and CIV are uninitialized global variables. So _deadguyside might become nil.

THEORY: This may only happen if the sides haven't been created. Ie you need to create a Civilian, and a Resistance man for the side to become 'initialized'. Hence the commands 'createCenter' etc for sides.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 14 Feb 2009, 23:24:11
1. Again, GUER and CIV are no sides.
2. The units that are checked for sides are provided by the "Killed" EH. When was the last time you shot or got shot by a game logic? ;)
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Rommel92 on 14 Feb 2009, 23:28:56
Hahaha, you'll be surprised...  :dry:

 :P

Well I'll have to take your judgement on this, can't test it so;
But could you maybe explain why GUER and CIV are 'no sides'; eg 'nil' since they are global variables in the form 'civilian' and 'resistance'; which point to 'GUER' and 'CIV' as values.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 14 Feb 2009, 23:54:01
Thanks all for your input,

Thanks especially to Worldeater who's solution worked right away... kind of.

My conclusion:

It seems that if you want to have a Detect Dead Bodies script that checks different combinations of variables, who died and who found the dead body, config based sidechecking works best.

Just like Worldeater indicated it doesn't work so well with checking sides on resistance/independent and civilians.

If you want the script to work even on units that have had their side changed (through mission.sqm or grouped with a leader from another side), you better change the actual script conditions to consider:

if (group finder == myChangedSideGroup ) then blahblah
or if (finder == mySpecialUnit) then blahblah

Think I'll go with the config sidecheck after all, I was wishing to cover everything, but I guess it's not possible.

Cheers,

Laggy
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Planck on 14 Feb 2009, 23:55:32
Well now, according to the biki:

"CIV" is the string returned when using  hint format["%1",civilian]
and
"GUER" is the string returned when using  hint format["%1",resistance]


Planck
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Mandoble on 14 Feb 2009, 23:59:37
In a similar way, "2" is not equal to 2.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 15 Feb 2009, 00:26:31
I think doing the config checks is fine.

Think about it: if I'd find a cold body in a SLA uniform I'd report a dead SLA soldier. How should I know the guy was a US SpecOp in disguise?

As an additional feature you could add all detected units to a global array. So if someone needs to know if his SpecOp in SLA uniform was found he can check the array.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 15 Feb 2009, 00:33:01
Thanks again,

Good thinking  :clap:, will add that array of found dead bodies in the script, then it's hopefully finished.

Laggy
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Sparticus76 on 15 Feb 2009, 01:57:16
I put this in a "west" soldiers init line and then shot him;

Code: [Select]
this addeventhandler ["killed",{hint format ["side of deadman is %1", side (_this select 0)]}]
the hint said "side of deadman is CIV"
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Rommel92 on 15 Feb 2009, 02:23:01
All dead man become side CIV, as they become an object, and all objects/vehicles that aren't claimed are classed as CIV.
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Worldeater on 15 Feb 2009, 03:12:47
 :weeping:

They become side civilian (http://community.bistudio.com/wiki/civilian)! "CIV" is a mere string representation of civilian (http://community.bistudio.com/wiki/civilian).

The string representation of 2 is "2", for False it's "FALSE" and for civilian (http://community.bistudio.com/wiki/civilian) it's "CIV".
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 15 Feb 2009, 15:41:34
The correct sides to check for are:

EAST
WEST
RESISTANCE
CIVILIAN

As in: side _unit == RESISTANCE

If _unit IS on resistance side, result is "true".
Forget all the "" and CIV and GUER, as thay are not the way to check for sides.

Period   :dry:

Laggy
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: Rommel92 on 15 Feb 2009, 21:12:47
:weeping:

They become side civilian (http://community.bistudio.com/wiki/civilian)! "CIV" is a mere string representation of civilian (http://community.bistudio.com/wiki/civilian).

Haha, I'm sorry. I understood you before, just wrote 'CIV' for some reason, yes I get it now, side _eastguy string returns "EAST", and value returns: EAST. And for _civguy it would be : "CIV" and CIVILIAN,  :P.

The correct sides to check for are:

EAST
WEST
RESISTANCE
CIVILIAN

As in: side _unit == RESISTANCE

If _unit IS on resistance side, result is "true".
Forget all the "" and CIV and GUER, as thay are not the way to check for sides.

Period   :dry:

Laggy

So did you end up getting it all fixed and working with your script?  :dunno:
Title: Re: i.e side WEST and a number converted into "WEST"
Post by: laggy on 15 Feb 2009, 21:18:12
Yepp  :D :D :D

Would love to hear your opinion.

http://www.ofpec.com/forum/index.php?topic=32963.msg227187#msg227187

Laggy