Jump to content
gc8

Playable units via script

Recommended Posts

Hi

I'm looking for a way to create playable units first with createUnit and then something like setPlayable. But setPlayable is said in the wiki to not work. Is there any other solution for this, or perhaps coming later?

Now I guess the only way is to place those playable units in editor and thus define the max player count. (Or is that maxPlayers in desctiption.ext header)

 

thx!

Share this post


Link to post
Share on other sites

When creating a scenario in A2's 3d Editor, two files get created, the mission.biedi and the mission.sqf.  The setPlayable command can be seen used in the mission.sqf, when a unit is placed and set as playable.

 

So maybe it's a deprecated editor-only command, or maybe it's usable only in 3DEN or 2D setup, I dunno.

  • Like 2

Share this post


Link to post
Share on other sites
16 hours ago, opusfmspol said:

So maybe it's a deprecated editor-only command, or maybe it's usable only in 3DEN or 2D setup, I dunno.

 

That's interesting thought, maybe it could be used in editor script to set all the units playable in the editor. But I haven't got any luck with that, I tried:

 

{ setPlayable _x } foreach (units (group player));

 

In the editor debug console, but that doesn't make the units playable

Share this post


Link to post
Share on other sites

I'd guess that "player" doesn't exist in the editor. Though I'm not really sure exactly what problem you are trying to solve. Are you trying to add units in the editor via script commands? If so, you need to use Eden commands like create3DENEntity and set3DENAttributes. Read more here:

https://community.bistudio.com/wiki/Eden_Editor:_Setting_Attributes

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
6 minutes ago, Harzach said:

Though I'm not really sure exactly what problem you are trying to solve.

 

I'm trying to add the playable units available in the lobby by script - at some point. So I don't have to manually place 64 playable units in the editor to achieve that

Share this post


Link to post
Share on other sites

Pretty sure that's not possible.

Share this post


Link to post
Share on other sites
1 minute ago, Harzach said:

Pretty sure that's not possible.

 

Hmm, well I tried creating soldier in the editor via createUnit command but the soldier is not selectable and moves around to formation...

Share this post


Link to post
Share on other sites
11 minutes ago, gc8 said:

Hmm, well I tried creating soldier in the editor via createUnit command but the soldier is not selectable and moves around to formation...

 

See my previous post.

Share this post


Link to post
Share on other sites
17 minutes ago, Harzach said:

 

See my previous post.

 

Ah create3DENEntity! That obviously works in the editor. Now I can build the script to create those playable characters... Shouldn't eden enchanted already have something like this?

thx guys!

  • Like 1

Share this post


Link to post
Share on other sites

I guess I just don't understand why you need a scripted solution. Not that it matters - if you're getting the results you want, then right on.

Share this post


Link to post
Share on other sites
1 minute ago, Harzach said:

I guess I just don't understand why you need a scripted solution. Not that it matters - if you're getting the results you want, then right on.

 

I just feel like it should be automated process. Otherwise I have to place all the players on every map manually and if I make one mistake.. well it's not cool. With script there's no mistakes :) With single script run I can have all that ready to go

 

  • Like 3

Share this post


Link to post
Share on other sites

dude1 = create3DENEntity ["Object","B_Soldier_F",screenToWorld [0.5,0.5]];   From console in 3D 3den only (due to screentoworld here)
dude2 = create3DENEntity ["Object","B_Soldier_F",getPos dude1 vectorAdd [0,1.5,0]];

set3DENAttributes [[[dude1,dude2],"controlMP",true]];

 

Here "controlMP" is the class for playable attribute.

  • Like 3

Share this post


Link to post
Share on other sites

This was something I too was looking for when I was interested in making missions. I don't want to use the editor to redo the work every time, I just want to make a script that I can reuse and save my time to spend on other aspects of mission making. As far as I could tell there was no way to do it outside of the editor or eden.

Share this post


Link to post
Share on other sites
20 hours ago, Vigil Vindex said:

This was something I too was looking for when I was interested in making missions. I don't want to use the editor to redo the work every time, I just want to make a script that I can reuse and save my time to spend on other aspects of mission making. As far as I could tell there was no way to do it outside of the editor or eden.

 

Well, the ways to run some code in 3den is to create your own module or mod, or the debug console (from 3den). I duno other mean.

The rule is: create scripted 3den entities in 3den via  mod (like module) or console 3den;  and create vehicles or units as objects (classic way) via mission scripts.

 

For the bunch of players like gc8 wants, you can create your composition. Just select the units and create the composition. F2 (group) > custom and at the bottom of assets, save new custom composition. It will be available for any of your scenario. Just mind for addons compatibility.

  • Like 1

Share this post


Link to post
Share on other sites

Well here's the code I come up with. You just point the editor camera where you want them and execute code in the debug console

 

The code will first delete all existing playable objects and player and then create new ones. At default it creates 32 units for west and east side

 

 


scopename "createPlayers";

_objs = all3DENEntities # 0;

{

if((_x get3DENAttribute "ControlMP") # 0 || (_x get3DENAttribute "ControlSP") # 0) then
{
delete3DENEntities [_x];
};

} foreach _objs;



_createSides = [["B_Soldier_F",32],["O_Soldier_F",32]];
_createIndex = 0;



_xpos = 0.5;
_ypos = 0.5;
_ppos = screenToWorld [0.5,0.5];



_numCreated = 0;

_maxPlrsCreated = 0;
{ _maxPlrsCreated = _maxPlrsCreated + (_x # 1) } foreach _createSides;

_maxLine = ceil( sqrt  _maxPlrsCreated / 2 );

for "_yline" from 1 to (_maxLine ) do
{

_typos = _ypos;

for "_ymirror" from 0 to 1 do
{

for "_xline" from 1 to (_maxLine ) do
{

_txpos = _xpos;


for "_xmirror" from 0 to 1 do
{

_cs = _createSides # _createIndex;
_cs params ["_type","_numToCreate"];


_cpos = +_ppos;
_cpos set [0, (_cpos # 0) + _txpos ];
_cpos set [1, (_cpos # 1) + _typos ];
_unit = create3DENEntity ["Object",_type,_cpos];

_unit set3DENAttribute ["ControlMP",true];
_unit set3DENAttribute ["description","Test dude"];

_numCreated = _numCreated + 1;


if(_numCreated >= _numToCreate) then
{
_createIndex = _createIndex + 1;
_numCreated = 0;
if(_createIndex > (count _createSides)) then
{
 breakTo "createPlayers";
};

};


//_typos = _typos * -1;
//};

 _txpos = _txpos * -1;
};

_xpos = _xpos + 1;
};

_xpos = 0.5;

_typos = _typos * -1;
};



_ypos = _ypos + 1;

};

 

  • 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

×