Jump to content
  • 0

CreateUnit script is adding 2 units instead of one :(


MatthewK

Question

EDIT: See my second thread.. Maybe an admin can delete this thread as I don't think its of any help to anyone! 

 

Does anyone know why this script would be adding 2 units to my map, when I'm only putting 1 in the number of units field. Even when I do this manually, putting the number into the createunit line , i still get 2 units spawning in the same spot :(

//Original Credits: Created by axeman Edited by TheSzerdi
//Edited for his custom missions by Hayward
private ["_chooseSkin","_aiunit","_xpos","_ypos","_unitpos","_aiGroup","_wppos","_wpradius","_wpnum","_levelnum","_numunits","_rndLOut","_ailoadout","_wp","_aispawnpos","_aiwep1","_aiammo1","_aiwep2","_aiammo2","_buildpos"];
 
    _aiunit = objNull;
    _aiGroup = createGroup resistance;
    _aispawnpos =_this select 0;
    _wpradius = _this select 1;
    _wpnum = _this select 2;
    _numunits = _this select 3;
    _levelnum = _this select 4;
	_buildpos = _this select 5;
 
    _xpos = _aispawnpos select 0;
    _ypos = _aispawnpos select 1;
	
	MYSKIN_fnc_selectRandom = {_this select (floor random (count _this)) };

 
  //  diag_log format ["AIUNIT: Spawn initiated: Centre:%1 | Radius in m:%2 | Waypoint number:%3 | WeaponLevel:%4",_aispawnpos,_wpradius,_wpnum,_levelnum];
 
    for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do
    {
        _unitpos = [_xpos+x,_ypos+x,0];
		_chooseSkin = ["BanditW2_DZ","GUE_Soldier_MG_DZ","GUE_Soldier_Sniper_DZ","Ins_Soldier_GL_DZ","GUE_Soldier_CO_DZ","BanditW1_DZ"] call MYSKIN_fnc_selectRandom;
        if (_levelnum==0) then // in_sityes troops
        {
            if ((x == 1) || (x == 3) || (x == 5)) then //troop soldiers
            {
                _chooseSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"PRIVATE"];
                _rndLOut=floor(random 4);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["M1014","8Rnd_B_Beneli_74Slug","revolver_EP1","6Rnd_45ACP"]};
                  case 1: {["M1014","8Rnd_B_Beneli_Pellets","revolver_EP1","6Rnd_45ACP"]};
                  case 2: {["Remington870_lamp","8Rnd_B_Beneli_74Slug","Colt1911","7Rnd_45ACP_1911"]};
                  case 3: {["Remington870_lamp","8Rnd_B_Beneli_Pellets","Colt1911","7Rnd_45ACP_1911"]};
                };
            };
            if ((x == 2) || (x == 4) || (x >= 6)) then //troops snipers
            {
				_chooseSkin createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"PRIVATE"];
                _rndLOut=floor(random 3);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["LeeEnfield","10x_303","Makarov","8Rnd_9x18_Makarov"]};
                  case 1: {["Huntingrifle","5x_22_LR_17_HMR","Makarov","8Rnd_9x18_Makarov"]};
                  case 2: {["M14_EP1","20Rnd_762x51_DMR","Makarov","8Rnd_9x18_Makarov"]};
                };
            };
        };

    
        diag_log format ["AIUNIT: Creating BAF_Soldier_L_DDPM by %1 at %2. Result:%3 | Loadout:%4 / Num:%5",player,_unitpos,_aiunit,_ailoadout,_rndLOut];
        
		
        _aiunit enableAI "TARGET";
        _aiunit enableAI "AUTOTARGET";
        _aiunit enableAI "MOVE";
        _aiunit enableAI "ANIM";
        _aiunit enableAI "FSM";
        _aiunit allowDammage true;
  	
		_aiunit addEventHandler ['killed',{_this execVM "missions\bodyclean.sqf"}]; //Body disappear time
		
        _aiunit setCombatMode "RED";
        _aiunit setBehaviour "AWARE";
 
        //clear default weapons / ammo
        removeAllWeapons _aiunit;
        //add random selection
        _aiwep1 = _ailoadout select 0;
        _aiammo1 = _ailoadout select 1;
        _aiwep2 = _ailoadout select 2;
        _aiammo2 = _ailoadout select 3;
        _aiunit addweapon _aiwep1;
        _aiunit addMagazine _aiammo1;
        _aiunit addMagazine _aiammo1;
        _aiunit addMagazine _aiammo1;
        _aiunit addweapon _aiwep2;
        _aiunit addMagazine _aiammo2;
        _aiunit addMagazine _aiammo2;
		_aiunit removeWeapon "ItemRadio";
     // Set Skill
        _aiunit setSkill ["aimingAccuracy",0.15];
        _aiunit setSkill ["aimingShake",0.16];
        _aiunit setSkill ["aimingSpeed",0.15];
        _aiunit setSkill ["endurance",0.10];
        _aiunit setSkill ["spotDistance",0.10];
        _aiunit setSkill ["spotTime",0.10];
        _aiunit setSkill ["courage",0.80];
        _aiunit setSkill ["reloadSpeed",0.18];
        _aiunit setSkill ["commanding",0.15];
        _aiunit setSkill ["general",0.65];
        sleep 0.5;
	// _aiunit setPos ((nearestBuilding _aiunit) buildingPos 1);
		
    };
Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0

Only seems to happen MOSTLY when I manually change the random loadout settings (in my missions file that choose a mission at random, not the random loadout in the createunit file) .... This: 

_rndLOut= floor(random 30);
		
			switch (_rndLOut) do
                {

TO

_rndLOut= 4; //floor(random 30);
		
			switch (_rndLOut) do
                {
Link to comment
Share on other sites

  • 0

I'm running this through the single player map option, so the log doesn't work. Running this on a dedicated server would kill my time.  Its driving me nuts though! I've even laid down 5 helipads all 10m away from each other, called the locations into an array and made sure that I only spawn 5 AI's all with a location taken from 1 of the helipads, all different locations, but somehow the AI are spawning in two at a time, with that script above.. I'm not creating more than one group.. :(

Link to comment
Share on other sites

  • 0

Can confirm this only happens in Single Player editing.. Which sucks, because I like to use the 3d Editor.  

 

Oh well, mystery solved at least. 

 

Would anyone be able to tell me why this happens? I've searched the bis website but can't find anything to explain the weirdness :)

Link to comment
Share on other sites

  • 0

I dont have any experience using the arma2 editor preview (i work on arma3 scripts)

 

But, the script is probably executed both server as clientsided.

 

you can use the isServer statement in the init.sqf to make sure your script only run serversided.

 

the client also generates an rpt log

 

for Arma3 its located in %appdata%\..\local\Arma 3\

 

maybe arma2 puts it in %appdata%\..\local\Arma 2 Operation Arrowhead\

Link to comment
Share on other sites

  • 0

Cheers JoSchaap. I'll remember that for future reference. Meanwhile, I got the AI missions working just dandy, all I need to do now is the code to fill the loot boxes and 30 building fortified missions await!! Trying to get AI to spawn in buildings is tough , for me :D

15f3vy8.png

Link to comment
Share on other sites

  • 0

Running a dedi server is the most reliable way but being able to load into the 3d editor would be the quickest.

I did look into it briefly when I started, didn't pursue it that far.

Would be so much easier to test and debug sections of script before putting them all together and then firing up the server, am going to have to give it some more attention :)

On that note, download squint for checking syntax before testing..

Link to comment
Share on other sites

  • 0

Try:

If(!isServer)then{[]execVM "script.sqf"};

 without the ! though. spawning of units should be serversided, adding a ! reverses the functionality of isserver to isnotserver :P

 

 

 

example of something to run on clients and NOT the server

 

https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/Development_main/init.sqf#L27-L32

 

example of something to only run on the server and not the clients

 

https://github.com/A3Wasteland/ArmA3_Wasteland.Altis/blob/Development_main/init.sqf#L54-L59

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...