Jump to content

Recommended Posts

Hello everyone,

 

SO basically we have init.sqf, onplayerrespawn.sqf, initserver.sqf and so on. Is there a similar one I can create for AIs. 

The reason I want to do so is instead of definiing the AIs gear every time i spawn the unit I can just place it in the init. this way whenever the AI spawns his gear gets changed to the custom gear I specified

Share this post


Link to post
Share on other sites

If you edit a units gear with the Eden editor and use a respawn script like upmon  for multiple waves of that group the gear should stay as you setup. I am almost positive about that.

Share this post


Link to post
Share on other sites
Just now, Mr. Birdman said:

If you edit a units gear with the Eden editor and use a respawn script like upmon  for multiple waves of that group the gear should stay as you setup. I am almost positive about that.

Thing is Birdman I am creating all the AIs using scripts, i am barely using the eden editor for anything

Share this post


Link to post
Share on other sites
3 minutes ago, BlacKnightBK said:

Thing is Birdman I am creating all the AIs using scripts, i am barely using the eden editor for anything

Then change the gear of the unit inside the script that creates them.

Don't see the problem here.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Grumpy Old Man said:

Then change the gear of the unit inside the script that creates them.

Don't see the problem here.

 

Cheers

There is no problem there, that is already the way i am doing it, however after setting up the gear i decided that i want to twist the gear a bit more. Now I have to go through over 8 files to change the gear for all of them, I am trying to find an easier way.

I want to set the gear for example  of the squad leader in one file.

every time i need to spawn a squad leader i just call this file to change his gear.

Share this post


Link to post
Share on other sites

If you have to edit 8 files manually when wanting to change the gear of a unit then you might want to rethink your approach.

Have one function to spawn units, then another function to assign layouts depending on input parameters.

 

Cheers

Share this post


Link to post
Share on other sites
3 minutes ago, Grumpy Old Man said:

If you have to edit 8 files manually when wanting to change the gear of a single unit then you might want to rethink your approach.

Have one function to spawn units, then another function to assign layouts depending on input parameters.

 

Cheers

How?

Share this post


Link to post
Share on other sites

Like this:


 

BK_fnc_setLoadout = {

	//changes a units loadout
	params ["_unit", "_loadout"];

	if (_loadout isEqualTo "SQUADLEADER") then {
		
		//your gear stuff here

	};

	//add as many outfit types as you want as separate if then statements.

};

BK_fnc_spawnUnit = {

	//params and code to spawn unit here, i.e.:
	params ["_group","_unitType","_position","_loadout"];
	_unit = _group createUnit [_unitType,_position,[],0,"NONE"];
	_loadout = [_unit,_loadout] call BK_fnc_setLoadout;

};

 

You could call it like this:
 

_newGroup = creategroup west;
_unitType = typeOf player;
_position = getPosATL player;
_loadout = "SQUADLEADER";
_spawn = [_newGroup,unitType,position,_loadout] call BK_fnc_spawnUnit;

If you already figured out how to spawn units via script and change their loadouts there's not much to it.

This way you could also spawn units in a loop and pick a random loadout each time, as long as the loadout is defined within BK_fnc_setLoadout:

 

_newGroup = creategroup west;
_unitType = typeOf player;
_position = getPosATL player;
for "_i" from 1 to 12 do {

	_loadout = selectRandom ["Rifleman1","Rifleman2","Rifleman3","Rifleman4"];
	_spawn = [_newGroup,unitType,position,_loadout] call BK_fnc_spawnUnit;

};

Pretty basic,

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

@Grumpy Old Man Thanks mate. I think i kind of get it. However getting late here i will try to work on it tomorrow

 

Hopefully will get it right, if i do you have just opened for me a new world in arma scripting

Share this post


Link to post
Share on other sites

Hey @Grumpy Old Man, i think I got the script done right. I try to spawn a whole squad however only the first unit gets spawned and i get a generic error. 
I have made some twists to the script you gave me above so it would fit my needs and i hope i did them right. So here is exactly what I have done.

 

I created the loadouts for 4 different units (My recon Squad) and called them as follows 

_unit1 = [_reconsquad,"O_T_Recon_M_F",_randomspawnpos,"RECON_MARKSMAN"] call YI_fnc_spawnAiUnit;
_unit0 = [_reconsquad,"O_recon_TL_F",_randomspawnpos,"RECON_SQUADLEADER"] call YI_fnc_spawnAiUnit;
_unit2 = [_reconsquad,"O_recon_medic_F",_randomspawnpos,"RECON_MEDIC"] call YI_fnc_spawnAiUnit;
_unit3 = [_reconsquad,"O_recon_F",_randomspawnpos,"RECON_SCOUT"] call YI_fnc_spawnAiUnit;

Now only unit1 spawns and he does spawn with teh correct gear and class name, however i get a generic error for _unit1 and the rest do not spawn.

 

 

Share this post


Link to post
Share on other sites
13 hours ago, BlacKnightBK said:

@Grumpy Old Man Thanks mate. I think i kind of get it. However getting late here i will try to work on it tomorrow

 

Hopefully will get it right, if i do you have just opened for me a new world in arma scripting

Glad to hear.

 

Post the rest of the related scripts, especially the content of YI_fnc_spawnAiUnit, since it's impossible to tell from the snippet you posted.

Also check for the correct unit types, since they're case sensitive.

 

Cheers

Share this post


Link to post
Share on other sites
10 minutes ago, Grumpy Old Man said:

Glad to hear.

 

Post the rest of the related scripts, especially the content of YI_fnc_spawnAiUnit, since it's impossible to tell from the snippet you posted.

Also check for the correct unit types, since they're case sensitive.

 

Cheers

I fixed the issue this way

[_reconsquad,"O_recon_TL_F",_randomspawnpos,"RECON_SQUADLEADER"] call YI_fnc_spawnAiUnit;
[_reconsquad,"O_T_Recon_M_F",_randomspawnpos,"RECON_MARKSMAN"] call YI_fnc_spawnAiUnit;
[_reconsquad,"O_recon_medic_F",_randomspawnpos,"RECON_MEDIC"] call YI_fnc_spawnAiUnit;
[_reconsquad,"O_recon_F",_randomspawnpos,"RECON_SCOUT"] call YI_fnc_spawnAiUnit;

Apparently I cannot assign the units a variable for some reason which is fine by me for now, however i am afraid in the future I will need them to be assigned a variable each depending on what their job is

 

As for my  YI_fnc_spawnAiUnit  here it is:

YI_fnc_spawnAiUnit = {

	params ["_squad","_unitType","_position","_loadout"];
	_unit = _squad createUnit [_unitType,_position,[],0,"NONE"];
	_loadout = [_unit,_loadout] call YI_fnc_setAiLoadout;

};

 

Share this post


Link to post
Share on other sites

Ah, I see.

If you want to refer to something outside of its scope you can simply return it, no matter the data type (Array, string, object, etc.).

In your case simply put _unit at the very end, then it will be the returned value of that function:

 

YI_fnc_spawnAiUnit = {

	params ["_squad","_unitType","_position","_loadout"];
	_unit = _squad createUnit [_unitType,_position,[],0,"NONE"];
	_loadout = [_unit,_loadout] call YI_fnc_setAiLoadout;
	_unit
};

Doing this:

_unit1 = [_reconsquad,"O_recon_TL_F",_randomspawnpos,"RECON_SQUADLEADER"] call YI_fnc_spawnAiUnit;

Should return the unit as _unit1.

 

Cheers

 

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, Grumpy Old Man said:

Ah, I see.

If you want to refer to something outside of its scope you can simply return it, no matter the data type (Array, string, object, etc.).

In your case simply put _unit at the very end, then it will be the returned value of that function:

 


YI_fnc_spawnAiUnit = {

	params ["_squad","_unitType","_position","_loadout"];
	_unit = _squad createUnit [_unitType,_position,[],0,"NONE"];
	_loadout = [_unit,_loadout] call YI_fnc_setAiLoadout;
	_unit
};

Doing this:


_unit1 = [_reconsquad,"O_recon_TL_F",_randomspawnpos,"RECON_SQUADLEADER"] call YI_fnc_spawnAiUnit;

Should return the unit as _unit1.

 

Cheers

 

 

Thanks, I thought that was the issue but tried to fix it wrong.

Tried doing it like I used to in C++ back in my course as

 return _unit;

 

  • Like 1

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

×