Jump to content
beastxjason

please help me out with a script?

Recommended Posts

ok I have far too many hrs invested in this. What I want to do.

Spawn 6 guys

I want them to wear my loadout and look the same (gang)

How I want this to work-Trigger. I want the player to trigger an ambush. What I have from my lack of knowledge.

This is what I did might be completely wrong but I get a blank error in editor so I have no idea what I am doing wrong

 

_my_group = [getMarkerPos "gang", EAST, 5] call BIS_fnc_spawnGroup;
{removeAllWeapons _x;
removeAllItems _x;
...
_x addHandgunItem "muzzle_snds_L";
_x addWeapon "Laserdesignator_02";
_x addWeapon "srifle_LRR_camo_F";
_x addPrimaryWeaponItem "optic_DMS";
_x addWeapon "hgun_Rook40_F";
_x addHandgunItem "muzzle_snds_L";
_x addWeapon "Laserdesignator_02";
_x forceAddUniform "U_C_Poor_1";
_x addItemToUniform "FirstAidKit";
_x linkItem "ItemMa_x linkItem "ItemCompa_x linkItem "I_UavTerminal";
_x addVest "V_PlateCarrierGL_rgr";
_x addHeadgear "H_Bandanna_blu";
_x addGoggles "G_Bandanna_beast";
... } foreach units _my_group; // _x is a local variable in {...} forEach array code

_wp = _my_group addWaypoint [getpos player,0];
_wp setWaypointType "MOVE"; // or "SAD"
_wp setWaypointBehaviour "COMBAT"; // see all possibilities on BIKI, behavior, combat mode, speed...

0 = [_wp,_my_group] spawn {while {alive player && (count units (_this select 1)) >0} do {
sleep 2;
(_this select 0) setWaypointPosition [getpos player,0]}};

 

So to my understanding I am spawning a group and telling them to attack player. What I do not understand is why this doesnt work. this a 3 player co-op mission. I am really losing my hair on this. I know I can simply place units down and put the loadout in the init but i am going to need so many of these guys they would bog server down.

 

So bottom line is

1: how should this code look and will it even work or should I abandon all hope

2: Can you illustrate where i went wrong and show me the correct layout in the trigger init so I can move onto the next hurdle?

 

Thanks for your time. This is pretty hard at first and I know one of you is just laughing at my feeble attempt haha

Share this post


Link to post
Share on other sites

Whats with this line..

_x linkItem "ItemMa_x linkItem "ItemCompa_x linkItem "I_UavTerminal";
Is that just a forum formatting mistake?

Share this post


Link to post
Share on other sites

that shouldnt be ike that odd paste maybe? was from

this linkItem "ItemMap";
this linkItem "ItemCompass";
this linkItem "I_UavTerminal";

was changing to the _x linkitem "itemMap"

 

I got my loadout using arsenal which was

comment "Enemy Gang";

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_C_Poor_1";
this addItemToUniform "FirstAidKit";
this addVest "V_PlateCarrierGL_rgr";
for "_i" from 1 to 2 do {this addItemToVest "HandGrenade";};
this addItemToVest "Chemlight_red";
for "_i" from 1 to 3 do {this addItemToVest "7Rnd_408_Mag";};
this addBackpack "B_FieldPack_cbr";
for "_i" from 1 to 2 do {this addItemToBackpack "16Rnd_9x21_Mag";};
this addItemToBackpack "30Rnd_9x21_Mag";
for "_i" from 1 to 14 do {this addItemToBackpack "7Rnd_408_Mag";};
this addHeadgear "H_Bandanna_blu";
this addGoggles "G_Bandanna_beast";

comment "Add weapons";
this addWeapon "srifle_LRR_camo_F";
this addPrimaryWeaponItem "optic_DMS";
this addWeapon "hgun_Rook40_F";
this addHandgunItem "muzzle_snds_L";
this addWeapon "Laserdesignator_02";

comment "Add items";
this linkItem "ItemMap";
this linkItem "ItemCompass";
this linkItem "I_UavTerminal";

comment "Set identity";
this setFace "WhiteHead_16";
this setSpeaker "Male01ENG";
[this,"GryffinRegiment"] call bis_fnc_setUnitInsignia;

Share this post


Link to post
Share on other sites

I suppose all this code is pasted in the "OnAct" box of a presence trigger. Ins't it?

 

Then, the blank error is because you use a local variable: _my_group (it's local because it starts with "_") and a trigger on the main scope does not allow to use local, only global (without the "_").

 

So changing everything to "my_group" should work.

 

Same with other variables, such as _wp.

 

Second: do you have the group declared? I think not because you would have the same error on the declaration. So in the group leader init field put: my_group = group this;

 

Third: You are referring to player. If you are playing MP Hosted, it's ok, but if you play on Dedi, "player" object does not exist. So you will have to refer to, for example, the player group leader. Do the same thing to declare the players group on their leader + in the script say "leader playersGroup" instead of "player"

 

And the last advice, but the most important!!!!

 

To start with scripts which are difficult for you, two main things:

 

- .rpt is your friend. Is the file where scripting errors are exported. Ask google where it is.

 

- Debugging is your best friend! Instead of putting the whole bunch of code, divide it by pieces. Let's say, first, check the units get dressed up the way you want using only the Arsenal export. Then let's check if the waypoints are created (hint format), the position is correct and updated etc.. I allways start coding with some hint messages from time to time to check everything is ok. This way you don't have to know what's happening in 60 lines, but in 5.

Share this post


Link to post
Share on other sites

Ya this is all going onto a trigger's init box. I do not have a group leader on the editor I was under the impression the spawn function would give me 6 random guys and all I had to do was give them all the same loadout to wear. So far all I can do is get the guys to spawn without my loadout using just the example on the bis page. I gave them the attack player wp and they began to move towards the player.

 

Thank you for the simple clear explanation on the "_" The mission is just a mp hosted mission.

Ya I have been using just the error box in editor was not aware there was a log created.

 

This all started because I thought I could make this easily spawn 5 guys wearing my loadout. Not so easy.

[getPos aPos, EAST, 5] call BIS_fnc_spawnGroup

 

 

I only wasted a few days trying to make this work. If I have to define a guy or leader etc this is out of my league and I misunderstood the spawn function command.

Share this post


Link to post
Share on other sites

You are not that far.

 

If you assign a variable to BIS_fnc_spawnGroup it will store the group name. Assuming you are using the right params to the function, if you do:

 

evilGroup = [getPos aPos, EAST, 5] call BIS_fnc_spawnGroup;

 

It will spawn the group with evilGroup as reference, so you can debug the mission like:

 

leader evilGroup globalChat "Am I Evil, yes I am" <--- check if the group has spawned.

leader evilGroup globalChat format ["We have this waypoints: %1", waypoints evilGroup] <--- check if you added those waypoints.

leader evilGroup setPos (wayPointPosition [evilGroup,0] <--- if the leader teleports to where the player is, then you gave him the right direction to the waypoint.

 

See?

 

Anyway, if scripting things is hard and you don't have time or dislike it, the things you are trying to do are more or less doable without any script, just mission editor.

  • Like 1

Share this post


Link to post
Share on other sites

Something is wrong here because without this they spawn and attack etc, this screws it up.
{removeAllWeapons _x;
removeAllItems _x;
...
x addHandgunItem "muzzle_snds_L";
x addWeapon "Laserdesignator_02";
x addItemToBackpack "16Rnd_9x21_Mag";};
x addWeapon "srifle_LRR_camo_F";
x addPrimaryWeaponItem "optic_DMS";
x addWeapon "hgun_Rook40_F";
x addHandgunItem "muzzle_snds_L";
x addWeapon "Laserdesignator_02";
x forceAddUniform "U_C_Poor_1";
x addItemToUniform "FirstAidKit";
x linkItem "ItemMap";
x addVest "V_PlateCarrierGL_rgr";
x addHeadgear "H_Bandanna_blu";
x addGoggles "G_Bandanna_beast";
... }
 

Share this post


Link to post
Share on other sites

You could set it up on a box with a simple neat script. But yea, that's only if that could work for you.

Share this post


Link to post
Share on other sites

You could set it up on a box with a simple neat script. But yea, that's only if that could work for you.

Can you lay it out for me I am going wrong with the loadout. I think I discovered some of my first issue. I was trying to call a local variable at first via the trigger act box and it says that wont work so changing the _x should remedy that.

Ideally a script would be the way to go then simply trigger it via a trigger. Something is wrong with the way I was shown to do loadouts I think. I am not sure if the "..." are suppose to be in there. I also see that everybody tends to type out their code differently. I see some examples with wierd spacing but it looks clean then I see other examples with no spacing. I am determined to get this to work. I have learned a lot.

Share this post


Link to post
Share on other sites

nonono

 

don't change the _x

 

My explanation was the simple one.

 

The complex one: triggers ADMIT local variables if they are outside (or deeper, don't know the right word in english) the main scope. In other words. SOMETIMES, between brackets, you will be able to use the _variable. For example, inside a {} forEach or inside a spawn {}

 

Sorry by giving you an incomplete explanation but I wanted to keep it as simple as I could.

 

So, don't touch the _ in foreach and inside spawn.

Share this post


Link to post
Share on other sites

Heres a quick example that you can place directly in a trigger OnAct.

h = [] spawn {
    _my_group = [getMarkerPos "gang", east, 5] call BIS_fnc_spawnGroup;
    {
        removeAllWeapons _x;
        removeAllItems _x;
        removeAllAssignedItems _x;
        removeUniform _x;
        removeVest _x;
        removeBackpack _x;
        removeHeadgear _x;
        removeGoggles _x;
        
        _x forceAddUniform "U_C_Poor_1";
        _x addItemToUniform "FirstAidKit";
        _x addVest "V_PlateCarrierGL_rgr";
        for "_i" from 1 to 2 do {_x addItemToVest "HandGrenade";};
        _x addItemToVest "Chemlight_red";
        for "_i" from 1 to 3 do {_x addItemToVest "7Rnd_408_Mag";};
        _x addBackpack "B_FieldPack_cbr";
        for "_i" from 1 to 2 do {_x addItemToBackpack "16Rnd_9x21_Mag";};
        _x addItemToBackpack "30Rnd_9x21_Mag";
        for "_i" from 1 to 14 do {_x addItemToBackpack "7Rnd_408_Mag";};
        _x addHeadgear "H_Bandanna_blu";
        _x addGoggles "G_Bandanna_beast";
        
        _x addWeapon "srifle_LRR_camo_F";
        _x addPrimaryWeaponItem "optic_DMS";
        _x addWeapon "hgun_Rook40_F";
        _x addHandgunItem "muzzle_snds_L";
        _x addWeapon "Laserdesignator_02";
        
        _x linkItem "ItemMap";
        _x linkItem "ItemCompass";
        _x linkItem "I_UavTerminal";
        
    }forEach units _my_group;
    
    _wp = _my_group addWaypoint [ getPos player, 0 ];
    _wp setWaypointType "MOVE";
    _wp setWaypointBehaviour "COMBAT";
    
    while { alive player && count units _my_group > 0 } do {
        comment "Wait until group have finished their current waypoint AND the player has moved some distance";
        waitUntil { currentWaypoint _my_group > ( _wp select 1 ) && player distance waypointPosition _wp > 20 };
        _wp setWaypointPosition [ getPos player, 0 ];
        _my_group setCurrentWaypoint _wp;
    };
};
Ive used most of the code as provided by you in previous posts. Ive changed the update while loop slightly so the group only has their waypoint position reset if they have finished their current one and the player has moved.

If you wanted to move this into its own script file you would remove the surrounding

h = [] spawn {
 
};
from the code above and save it as something like ambush.sqf and then replace the OnAct with
nul = [] execVM "ambush.sqf;

 

Hope that helps and gives you something to work from.

Share this post


Link to post
Share on other sites

Or more easy way..

waitUntil {!isnull player};
waitUntil {alive player};
private ["_gangpos", "_ganggroup"];
_gangpos = [getMarkerPos "gang", 300, 400, 10, 0, 0, 0] call BIS_fnc_findSafePos;
_ganggroup = [_gangpos, east, (configfile >> "CfgGroups" >> "EAST" >> "OPF_F" >> "Infantry" >> "OI_reconTeam")] call BIS_fnc_spawnGroup;
waitUntil { sleep 1; {alive _x} count units _ganggroup == 6};

{
removeAllWeapons _x;
removeAllItems _x;
removeAllAssignedItems _x;
removeUniform _x;
removeVest _x;
removeBackpack _x;
removeHeadgear _x;
removeGoggles _x;
_x forceAddUniform "U_C_Poor_1";
_x addItemToUniform "FirstAidKit";
_x addVest "V_PlateCarrierGL_rgr";
for "_i" from 1 to 2 do {_x addItemToVest "HandGrenade";};
_x addItemToVest "Chemlight_red";
for "_i" from 1 to 3 do {_x addItemToVest "7Rnd_408_Mag";};
_x addBackpack "B_FieldPack_cbr";
for "_i" from 1 to 2 do {_x addItemToBackpack "16Rnd_9x21_Mag";};
_x addItemToBackpack "30Rnd_9x21_Mag";
for "_i" from 1 to 14 do {_x addItemToBackpack "7Rnd_408_Mag";};
_x addHeadgear "H_Bandanna_blu";
_x addGoggles "G_Bandanna_beast";
_x addWeapon "srifle_LRR_camo_F";
_x addPrimaryWeaponItem "optic_DMS";
_x addWeapon "hgun_Rook40_F";
_x addHandgunItem "muzzle_snds_L";
_x addWeapon "Laserdesignator_02";
_x linkItem "ItemMap";
_x linkItem "ItemCompass";
_x linkItem "I_UavTerminal";
_x setFace "WhiteHead_16";
_x setSpeaker "Male01ENG";
[_x,"GryffinRegiment"] call bis_fnc_setUnitInsignia;
} foreach units _ganggroup;

while {alive player AND {alive _x} count units _ganggroup > 0} do {

	[_ganggroup, getPos player, 10] call BIS_fnc_taskPatrol;
	
sleep 50;
};

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

×