Jump to content
Unluckymonster

Custom kit randomize script & how to use eventHandlers properly in sqf-files?

Recommended Posts

So what kind of script I'm creating/ searching for is to have certain kits from which each unit's equippement is randomly selected from like kit2 is ACP2 and kit6 is revolver etc. for each unit which will have

[] exec "Class_randomize_script.sqf"; in their Init-field (or some other way?).

 

I already asked help from great scripter George Floros GR in private and he have helped me very openly already but it hasn't been enough to me get through with this problem.

 

Here's how far I have got this far:

 

Spoiler

Class_randomize_simplest.sqf

 

//Randomise unit with one of created kits.
// Customised from _Custom Ammo Crates with Random Loadout_ script from _NotASemiPro_ user plus with George Floros GR assist
//    - Unluckymonster

 

//generates random number, I actually managed to get this work, such talented scripter wow

 

_number = selectRandom [1,2,3,4,5,6];


//Based on the random number, it adds the kit which is numbered. Example four-five pistol is 1 and Taurus revolver is 6.


// These kit's won't be used in my ArmA Far Cry-missions but I created these so it's easy for both of test/ customize the script without any mods.

 

 

// 6 Pistol classes

if (_number == 1) then {Paul addMagazines ["11Rnd_45ACP_Mag", 3]; Paul addWeapon "hgun_Pistol_heavy_01_F";};
if (_number == 2) then {Paul addMagazines ["9Rnd_45ACP_Mag", 3]; Paul addWeapon "hgun_ACPC2_F";};
if (_number == 3) then {Paul addMagazines ["16Rnd_9x21_Mag", 3]; Paul addWeapon "hgun_P07_F";};
if (_number == 4) then {Paul addMagazines ["10Rnd_9x21_Mag", 3]; Paul addWeapon "hgun_Pistol_01_F";};
if (_number == 5) then {Paul addMagazines ["16Rnd_9x21_Mag", 3]; Paul addWeapon "hgun_Rook40_F";};
if (_number == 6) then {Paul addMagazines ["6Rnd_45ACP_Cylinder", 3]; Paul addWeapon "hgun_Pistol_heavy_02_F";};

 

And here's what I'm aiming for:

 

Spoiler

Class_randomize_simple.sqf

 

//Randomise unit with one of created kits.


// Customised from _Custom Ammo Crates with Random Loadout_ script from _NotASemiPro_ user.
//    - Unluckymonster

 

//I'm not even sure does the _unit statement work or does it need to be enterily something else?

 

_unit = _this select 0;

 

//generates random number

 

_number = selectRandom [1,2,3,4,5,6];


//Based on the random number, it adds the kit which is numbered. Example four-five pistol is 0 and Taurus revolver is 5.
// End of each kit have KILLED eventHandler which removes all Magazines except 1 magazine.
// These kit's won't be used ArmA Far Cry-missions but I created these so it's easy for both of test/ customize the script without any mods.

 

 

// 6 Pistol classes

if (_number == 1) then {_unit addMagazines ["11Rnd_45ACP_Mag", 3]; _unit addWeapon "hgun_Pistol_heavy_01_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""11Rnd_45ACP_Mag"]; _unit addEventHandler ["KILLED", "this removeMagazine ""11Rnd_45ACP_Mag"];};
if (_number == 2) then {_unit addMagazines ["9Rnd_45ACP_Mag", 3]; _unit addWeapon "hgun_ACPC2_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""9Rnd_45ACP_Mag"]; _unit addEventHandler ["KILLED", "this removeMagazine ""9Rnd_45ACP_Mag"];};
if (_number == 3) then {_unit addMagazines ["16Rnd_9x21_Mag", 3]; _unit addWeapon "hgun_P07_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""16Rnd_9x21_Mag"]; _unit addEventHandler ["KILLED", "this removeMagazine ""16Rnd_9x21_Mag"];};
if (_number == 4) then {_unit addMagazines ["10Rnd_9x21_Mag", 3]; _unit addWeapon "hgun_Pistol_01_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""10Rnd_9x21_Mag"]; _unit addEventHandler ["KILLED", "this removeMagazine ""10Rnd_9x21_Mag"];};
if (_number == 5) then {_unit addMagazines ["16Rnd_9x21_Mag", 3]; _unit addWeapon "hgun_Rook40_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""16Rnd_9x21_Mag"]; _unit addEventHandler ["KILLED", "this removeMagazine ""16Rnd_9x21_Mag"];};
if (_number == 6) then {_unit addMagazines ["6Rnd_45ACP_Cylinder", 3]; _unit addWeapon "hgun_Pistol_heavy_02_F"; _unit addEventHandler ["KILLED", "this removeMagazine ""6Rnd_45ACP_Cylinder"]; _unit addEventHandler ["KILLED", "this removeMagazine ""6Rnd_45ACP_Cylinder"];};

 


Above code (obviously?) doesn't work and I have taken parts of it from _NotASemiPro_ user's "_Custom Ammo Crates with Random Loadout_ script" but since he hasn't visited BI-forum in 5 years I didn't even try to ask his help. :sarcasm:

 

 

So what I still need help with?:

1) How I get _unit or whatever work so that it works for any unit seperatly? Creating sqf-file for each enemy unit doesn't sound wise way to do it :icon_confused:

 

2) How to get eventHandlers work in .sqf form? In-game I get it work like this

Spoiler

this addEventHandler ["KILLED", "this removeMagazine ""11Rnd_45ACP_Mag"];

 

but in sqf it doesn't work and I have tried many different " ] } ; placements without getting it to work.


Those who have opened my earlier published missions and campaigns at Eden editor might have realized I'm not very good with .sqf-codes. I tried to check George's "Drop Loot Script", "Set Custom Loadout Script" and "Auto random loadout script" but don't been able to understand if I could customize those scripts the way I want to and if I could, how?

 

 

What I'm asking for your help is to either customize my Class_randomize_simple or simplest so that it would work like I have intended, customize one George's great scripts so that I can use it the way I intend or either create totally new script that would work like intended.


If you manage to help me you will be absolutly credited in the missions credits-scenes and in the download-page like I have done in my earlier missions and campaigns when people have helped me in various obstacles.


- Unluckymonster

Share this post


Link to post
Share on other sites

I'm not sure George let you with such bad code with evident errors:

this addEventHandler ["KILLED", "this removeMagazine ""11Rnd_45ACP_Mag"];

You can apply your EH to this in editor or Paul, if it's the unit name in editor.

But you need to read how EH works:

this addEventHandler ["Killed", {
  params ["_unit", "_killer", "_instigator", "_useEffects"];
  _unit removeMagazine "11Rnd_45ACP_Mag";
}];

Note: use removeMagazineGlobal in MP.

You can optimize your code, not testing each value 1,2...6.

 

  • Like 1

Share this post


Link to post
Share on other sites
43 minutes ago, pierremgi said:

I'm not sure George let you with such bad code with evident errors:

this addEventHandler ["KILLED", "this removeMagazine ""11Rnd_45ACP_Mag"];

 

Indeed !

I gave him as well a working example .

 

Unluckymonster ,

generally what you want to achive is to have like a number of certain loadouts and aply one of them on random , to all units.

 

Since you asked for help ,

i will add a code here , in order to help , because as i'm always saying , this is why the forum is !

Helping and sharing information.

 

But if you want to ask a question for a certain thing , as now with my scripts , you can add your question to the current topic , in order everyone to get benefit from.

 

  • Like 4

Share this post


Link to post
Share on other sites

Not yet published

+GF_Exported_Loadouts_Script.VR.zip

Expires in: 4 Weeks   |   Size: 12.5 KB   |

https://ufile.io/w5ubz

 

7 hours ago, Unluckymonster said:

eventHandlers

_this addEventHandler ["Killed",{
    params ["_unit"];
    _mag = primaryWeaponMagazine _unit select 0;
    removeAllWeapons _unit;
    _unit addMagazines [_mag,1];
}]; 

 

  • Like 2

Share this post


Link to post
Share on other sites
21 hours ago, pierremgi said:

I'm not sure George let you with such bad code with evident errors

20 hours ago, GEORGE FLOROS GR said:

 

Indeed !

I gave him as well a working example .

 

Unluckymonster ,

generally what you want to achive is to have like a number of certain loadouts and aply one of them on random , to all units.

 

Since you asked for help ,

i will add a code here , in order to help , because as i'm always saying , this is why the forum is !

Helping and sharing information.

 

But if you want to ask a question for a certain thing , as now with my scripts , you can add your question to the current topic , in order everyone to get benefit from.

 

 

 

Yes you are both fully right, I apologize for my miscorrect writing. :shrug:

 

16 hours ago, GEORGE FLOROS GR said:

Not yet published

+GF_Exported_Loadouts_Script.VR.zip

Expires in: 4 Weeks   |   Size: 12.5 KB   |

https://ufile.io/w5ubz

 


_this addEventHandler ["Killed",{
    params ["_unit"];
    _mag = primaryWeaponMagazine _unit select 0;
    removeAllWeapons _unit;
    _unit addMagazines [_mag,1];
}]; 

 

 

Yes, this script is very close of what I'm  searching for! :icon_biggrin:

However instead of randomizing all EAST or other side units, what I'm searching is to put like [] exec "Var_GF_Exported_Loadouts.sqf"; or something like that to each unit's Init-field. That way I could randomize sniper and ground forces-weaponneries seperately with own script-entities. :scratchchin: Right now I try to figure out which parts of code can be removed/ customised so that it would work like I'm searching for.

 

- Unluckymonster

 

  • Like 1

Share this post


Link to post
Share on other sites
52 minutes ago, Unluckymonster said:

However instead of randomizing all EAST or other side units,

 

There is an exclude list inside the code .

So you can just remove the ! from the code , in order to reverse this and have only the certain units to change their loadout.

 

&& (!((typeOf _x) in GF_Exported_Loadouts_Exclude_List)) 

 

the script will work in a loop , so it will change the loadouts also for the spawned unit.

 

If your mission doesn't have any spawned units, you can remove the loop :

while {true} do {       

You can even copy the whole script as it is and just change all the global variables like :

GF_Exported_Loadouts_1 = {

so that you can run more than one script.

  • Like 1

Share this post


Link to post
Share on other sites
On 9/1/2019 at 2:56 AM, GEORGE FLOROS GR said:

Not yet published

+GF_Exported_Loadouts_Script.VR.zip

 

Here is the script published :

 

Thanks !

 

  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, GEORGE FLOROS GR said:

 

There is an exclude list inside the code .

So you can just remove the ! from the code , in order to reverse this and have only the certain units to change their loadout.

 

 

Think I got now mostly figured it out the way I intended at the start! :icon_biggrin:

 

22 hours ago, GEORGE FLOROS GR said:

 


&& (!((typeOf _x) in GF_Exported_Loadouts_Exclude_List)) 

You can even copy the whole script as it is and just change all the global variables like :


GF_Exported_Loadouts_1 = {

so that you can run more than one script.

 

Though this part I still fail to do. Do you mean to create seperate SQF-file or add new part to already existing sqf-file?

 

I created new GF_Exported_Loadouts_Sniper.sqf, Loadout_Sniper_1.sqf and Loadout_Sniper_2.sqf files but it didn't work. 

 

GF_Exported_Loadouts_Sniper.sqf (It's in the same folder as GF_Exported_Loadouts.sqf, is that a problem?)

Spoiler


//________________  Author : GEORGE FLOROS [GR] ___________ 09.01.19 _____________

/*
________________ GF Exported Loadouts Script ________________

Please keep the Credits or add them to your Diary

https://community.bistudio.com/wiki/SQF_syntax
Don't try to open this with the simple notepad.
For everything that is with comment  //  in front  or between /*
means that it is disabled , so there is no need to delete the extra lines.

You can open this ex:
with notepad++
https://notepad-plus-plus.org/

and also use the extra pluggins
(this way will be better , it will give also some certain colors to be able to detect ex. problems )
http://www.armaholic.com/page.php?id=8680

or use any other program for editing .

For the Compilation List of my GF Scripts , you can search in:
https://forums.bohemia.net/forums/topic/215850-compilation-list-of-my-gf-scripts/
*/


//________________    You can add in the init of a unit to exclude     ________________    
//    this setVariable ["Var_GF_Exported_Loadouts_Sniper", true];


//________________ Settings ________________
//________________ Set true or false  ________________

//these are set false as normal weapons kit randomize already does this message. - Unluckymonster


_Systemchat_info                    = false;
_diag_log_info                        = false;    


if(_Systemchat_info) then {
systemchat "GF Exported Loadouts Script Initializing";
};

if(_diag_log_info) then {
diag_log "//________________    GF Exported Loadouts Script Initializing    _____________";
diag_log "//________________    GF_Exported_Loadouts.sqf    _____________";
};


//________________ add your sqf names of the exported loadouts ________________

GF_Exported_Loadouts_array_Sniper = [
    "Loadout_Sniper_1",
    "Loadout_Sniper_2",
];


//________________ You can add an Exclude List  ________________

GF_Exported_Loadouts_Exclude_List_Sniper = [
    "O_sniper_F",
    ];


GF_Exported_Loadouts_Sniper = {
    
_List = selectRandom GF_Exported_Loadouts_array_Sniper;
[_this] execVM format ["GF_Exported_Loadouts_Sniper\Loadouts\%1.sqf", _List];

};


[] spawn {
    while {true} do {        
        {        
        if (
        ((alive _x))
        && (!(_x getVariable ["Var_GF_Exported_Loadouts_Sniper",false]))
        && (((typeOf _x) in GF_Exported_Loadouts_Exclude_List_Sniper))
        
        /*
        //________________    You can filter the side here    ________________    
        && {((side group _x) == west ||
            (side group _x) == east ||
            (side group _x) == independent ||
            (side group _x) == civilian)}
        */
        
        //    && (side group _x == playerSide)
        //    && (!(side group _x == playerSide))
        
        ) then {
            
            _x spawn GF_Exported_Loadouts_Sniper;
            
            };                        
            _x setVariable ["Var_GF_Exported_Loadouts_Sniper",true];
            {waitUntil {!alive _x};
            _x setVariable ["Var_GF_Exported_Loadouts_Sniper",false];        
            };
        }forEach allUnits;
        sleep 5;
    };
};        


if(_Systemchat_info) then {
systemchat "GF Exported Loadouts Script Initialized";
};

if(_diag_log_info) then {
diag_log "//________________    GF Exported Loadouts Script Initialized    _____________";
};

 

And here's Loadout_Sniper_1.sqf, (It's in the same Loadouts-folder as GF_Exported_Loadouts.sqf, is that a problem?)

 

Spoiler


//________________  Author : GEORGE FLOROS [GR] ___________ 09.01.19 _____________

/*
________________ GF Exported Loadouts Script ________________


Please keep the Credits or add them to your Diary

https://community.bistudio.com/wiki/SQF_syntax
Don't try to open _unit with the simple notepad.
For everything that is with comment  //  in front  or between /*
means that it is disabled , so there is no need to delete the extra lines.

You can open _unit ex:
with notepad++
https://notepad-plus-plus.org/

and also use the extra pluggins
(_unit way will be better , it will give also some certain colors to be able to detect ex. problems )
http://www.armaholic.com/page.php?id=8680

or use any other program for editing .

For the Compilation List of my GF Scripts , you can search in:
https://forums.bohemia.net/forums/topic/215850-compilation-list-of-my-gf-scripts/
*/


_unit = _this select 0;


//    Paste your exported loadout and change this to _unit

//________________ Paste here : ________________

comment "Exported from Arsenal by Unluckymonster";

comment "Remove existing items";
removeAllWeapons this;
removeAllItems this;
removeAllAssignedItems this;
removeUniform this;
removeVest this;
removeBackpack this;
removeHeadgear this;
removeGoggles this;

comment "Add containers";
this forceAddUniform "U_B_GhillieSuit";
this addItemToUniform "FirstAidKit";
for "_i" from 1 to 2 do {this addItemToUniform "7Rnd_408_Mag";};
this addItemToUniform "SmokeShell";
this addVest "V_Chestrig_rgr";
for "_i" from 1 to 3 do {this addItemToVest "7Rnd_408_Mag";};
for "_i" from 1 to 2 do {this addItemToVest "16Rnd_9x21_Mag";};
this addItemToVest "ClaymoreDirectionalMine_Remote_Mag";
this addItemToVest "APERSTripMine_Wire_Mag";
this addItemToVest "SmokeShellGreen";
this addItemToVest "SmokeShellBlue";
this addItemToVest "SmokeShellOrange";
for "_i" from 1 to 2 do {this addItemToVest "Chemlight_green";};

comment "Add weapons";
this addWeapon "srifle_LRR_camo_F";
this addPrimaryWeaponItem "optic_LRPS";
this addWeapon "hgun_P07_F";
this addHandgunItem "muzzle_snds_L";
this addWeapon "Rangefinder";

comment "Add items";
this linkItem "ItemMap";
this linkItem "ItemCompass";
this linkItem "ItemWatch";
this linkItem "ItemRadio";
this linkItem "ItemGPS";
this linkItem "NVGoggles";

comment "Set identity";
this setFace "WhiteHead_04";
this setSpeaker "male07eng";

 

  • Like 1

Share this post


Link to post
Share on other sites
4 hours ago, Unluckymonster said:

Think I got now mostly figured it out the way I intended at the start! :icon_biggrin:

 

Let's move the discussion in the script's topic :

Spoiler
4 hours ago, GEORGE FLOROS GR said:

Here is the script published :

 

 

20 minutes ago, GEORGE FLOROS GR said:

Changelog:

 

v2.0
Added an option to change certain loadouts , or random to certain type of unit.
Added three examples , rifleman , sniper and every other unit.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×