Forum Jump :

Author Message


Posts: 28
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#1 Posted at 2016-02-16 19:18        
     
I am making a script that, depending on the parameter you put in, will randomly equip and dress any unit into the given type. for example, a 1 is civil unrest, 2 is civilian with pcked up wepon, 3 is civilian irregular, and 4 is an all out rebel. The script is still very WIP, and one line in particular is causing me problems:
if (_Facewear > 0.25) Then {if (_Headgear > 0.5) Then {_unit addHeadgear _Headgear;} Else{_unit addGoggles _Goggles;}; } Else{}; } Else{};
If you want to see the entire script, this is it:
_unit = _this select 0;
_type = _this select 1;
//_weapon = _this select 1;
_Facewear = random 1;
_Headgear = random 1;

_Weapon = ["rhs_weap_ak74m", "rhs_weap_ak74m_camo",
"rhs_weap_ak74m_desert", "rhs_weap_ak74m_folded",
"rhs_weap_ak74m_camo_folded", "rhs_weap_ak74m_desert_folded",
"rhs_weap_ak74m_2mag", "rhs_weap_ak74m_2mag_camo"] call BIS_fnc_selectRandom;

_Magazine = ["rhs_30Rnd_545x39_AK", "rhs_30Rnd_545x39_AK_no_tracers",
"rhs_30Rnd_545x39_7N10_AK", "rhs_30Rnd_545x39_7N22_AK",
"rhs_45Rnd_545x39_AK", "rhs_45Rnd_545x39_7N10_AK", "rhs_45Rnd_545x39_7N22_AK"] call BIS_fnc_selectRandom;

_Vest = ["V_BandollierB_cbr", "V_BandollierB_blk",
"V_BandollierB_oli", "rhs_vydra_3m", "rhs_6sh46", "V_HarnessOGL_brn"] call BIS_fnc_selectRandom;

_Goggles = ["rhs_balaclava1_olive", "G_Balaclava_oli",
"G_Bandanna_blk", "rhs_scarf", "G_Bandanna_oli"] call BIS_fnc_selectRandom;

_Headgear = ["H_Bandanna_khk", "H_Bandanna_mcamo",
"rhs_beanie_green", "rhs_Booniehat_flora", "H_Booniehat_mcamo",
"H_Booniehat_tan", "H_Booniehat_dgtl", "rhs_Booniehat_marpatd"] call BIS_fnc_selectRandom;

if (_type == 1) Then{
removeAllWeapons _unit;
_unit addMagazine _Magazine;
_unit addWeapon _Weapon;
  
for "_i" from 1 to 3 do {

_Magazine = ["rhs_30Rnd_545x39_AK", "rhs_30Rnd_545x39_AK_no_tracers",
"rhs_30Rnd_545x39_7N10_AK", "rhs_30Rnd_545x39_7N22_AK",
"rhs_45Rnd_545x39_AK", "rhs_45Rnd_545x39_7N10_AK", "rhs_45Rnd_545x39_7N22_AK"] call BIS_fnc_selectRandom;

_unit addItem _Magazine;};
} Else{};

if (_type == 2) Then{
removeAllWeapons _unit;
removeHeadgear _unit:
removeGoggles _unit;
_unit addMagazine _Magazine;
_unit addWeapon _Weapon;
_unit addVest _Vest;

for "_i" from 1 to 3 do {
_Magazine = ["rhs_30Rnd_545x39_AK", "rhs_30Rnd_545x39_AK_no_tracers",
"rhs_30Rnd_545x39_7N10_AK", "rhs_30Rnd_545x39_7N22_AK",
"rhs_45Rnd_545x39_AK", "rhs_45Rnd_545x39_7N10_AK", "rhs_45Rnd_545x39_7N22_AK"] call BIS_fnc_selectRandom;
_unit addItem _Magazine;};


if (_Facewear > 0.25) Then {if (_Headgear > 0.5) Then {_unit addHeadgear _Headgear;} Else{_unit addGoggles _Goggles;}; } Else{}; } Else{};
Just to clarify, i am calling the script with:
0 = [this, 2] execVM "Scripts\Random.sqf";
Any help would be greatly appreciated and just ask if you need me to explain anything.


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#2 Posted at 2016-02-16 19:25        
     
Before looking in to the script and writing the rest of my answer, I just want to mention that you do not have to end your ifs with elses. You can just close them with a semicolon, like this:
if (_condition) then {};

Also start your variable and command names with lower case letters. Use then and not Then, or name your variable _weapon.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Advertisement


Author Message


Posts: 28
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#3 Posted at 2016-02-16 19:27        
     
Just to ask, is the then not Then convention or actual syntax?


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#4 Posted at 2016-02-16 19:43        
     
I really don't know what you mean by that.

Anyways, your problem is that _headgear is a String, you first define it as a number but then you turn it in to a string by using the same variable name for the actual headgear classname too. Maybe consider replacing one of them to _headgearPossibility or _headgearClass. This migth sound crazy, but may I suggest you replace both?

I also trimmed your script a bit, it could be made waaay smaller but I kept the changes small so you can still go wherever you wanted to go with your script. Use it if you want.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 28
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#5 Posted at 2016-02-16 19:48        
     
Thanks for taking the time to look at my script. I did not even notice that i had used _Headgear twice, and also thanks for cleaning up the script as i was wondering how i should do it. If i ever do publish the script i will list you in the credits. What i meant by that is if you used 'Then' in an if statment, is that wrong syntax, or just unconventional.


Author Message


Posts: 1189
Rank:


Level: Member

Country: tr
Location:
Occupation: Computer Science student
Age: 20
In-game name: Wak

 
#6 Posted at 2016-02-16 19:51        
     
It whould still be technically correct I guess, since Arma is less case-sensitive than a 6 year old.

But just don't.

Please.

Sometimes I like to think as I started the whole "earplugs" thing.

W0lle: The only advice I can give you is: Do not try to understand BI. You will not succeed and it only makes your brain go boom. I would even go so far and say that not even they understand their own actions :-D.

#define getDamage getDammage

Author Message


Posts: 28
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#7 Posted at 2016-02-16 20:37        
     
Just tested it, and have tried to solve this myself, but basically the script does not work properly, as it will equip them with the weapons and vests, but still does not do the headwear or goggles. I have instead made the nessercery modifications to my code after taking your advice and it works, plus i am in the process of tyiding it up and also putting my variables and 'thens' and 'elses' into lowercase.


Author Message


Posts: 635
Rank:


Level: Member

Country: uk
Location: N.W.
Occupation:
Age: 29
In-game name: big_wilk

 
#8 Posted at 2016-02-17 13:11        
     
Cant check it out right now, but the problem will be most likely one of two things, test the following possible solutions:

1. A Scope Issue, if it is placeing this line at the top of the script will fix it:
private["_headgear","_goggles"];

2. A conditional issue your one or more of your conditions may be wrong. To check this, place a hint where the problem might be to see if condition is correct for example:
if (_facewear > 0.25) then {
    if (_headgear > 0.5) then {_unit addHeadgear _headgear} else {_unit addGoggles _goggles};
   hint "here"; 
};

This post was edited by big_wilk (2016-02-17 14:35, 611 days ago)


Author Message


Posts: 28
Rank:


Level: Member

Country: uk
Location:
Occupation:
Age:
In-game name:

 
#9 Posted at 2016-02-17 15:43        
     
It is fine now. I have fixed it, as it was simply that, as 654wak654 pointed out on my script, that the script uses _headgear twice. I am now well into the script, and will probably be finished in the next few days.
Thanks for looking at the script.