Jump to content
pSiKO

How to create player unit from pure script

Recommended Posts

Hello dear community,

 

I would like to know if is it possible to create player unit from pure script ??

I mean without by placing a playable unit with Eden Editor.

 

I want to be able to create the unit class by myself (B_medic_f / O_medic_f)

how will the lobby work in this case?

 

if anyone has a doc or a demo mission to explain to me. it will be super nice!

 

Best regards,

Share this post


Link to post
Share on other sites

It determines the number of players which can join the mission. Therefore this should not be possible.

Share this post


Link to post
Share on other sites
2 hours ago, sarogahtyp said:

It determines the number of players which can join the mission. Therefore this should not be possible.

 

aaaargh ! dammit !

 

thanks a lot for your reply, it save me lot of time !
 

Share this post


Link to post
Share on other sites

There is a workaround, not saying it's perfect solution:
- Place a unique player unit (presence set to 0 is useless, show model unticked, disable simulation), just to make the mission starts

- in description.ext:   skipLobby = 1;   // the lobby is skipped

- from any script you want, I tested with a simple logic (init field), run something like that:
 

0 = this spawn {
  waitUntil {getClientState == "BRIEFING READ"};
  private _plyr = createGroup WEST createUnit ["B_soldier_F", _this getpos [300 * sqrt random 1,random 360],[],0,"none"];
  selectPlayer _plyr;
  waitUntil {!isNull findDisplay 314};
  findDisplay 314 closeDisplay 0;
};

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites
23 hours ago, pSiKO said:

Hello dear community,

 

I would like to know if is it possible to create player unit from pure script ??

I mean without by placing a playable unit with Eden Editor.

 

I want to be able to create the unit class by myself (B_medic_f / O_medic_f)

how will the lobby work in this case?

 

if anyone has a doc or a demo mission to explain to me. it will be super nice!

 

Best regards,

You can have player joining into some default unit then create whatever unit and selectPlayer into it

  • Thanks 1

Share this post


Link to post
Share on other sites
42 minutes ago, killzone_kid said:

You can have player joining into some default unit then create whatever unit and selectPlayer into it

hi killzone_kid,

 

first of all, thanks you!, I've read so many of your code/advice, that help me a lot !

 

 

Let's say, a playable unit placed with eden is "B_medic_F" and I want to spawn as "O_medic_F".

 

so, I' do in  initPlayerLocal.sqf  and onPlayerRespawn.sqf

 

_player = player;
_group = createGroup [EAST, true];

"O_medic_F" createUnit [position player, _group, ""];
sleep 2;

selectPlayer (units _group select 0);
deleteVehicle _player;

 

that work, but after several respawns the Arma3 client  CTD. (memory violation)

maybe it's not related,  but I read many warnings on "selectPlayer".

of course I see your comment that help me. but as I was not sure, so I'll try to find an alternative.

 

can you tell me:

is "selectPlayer" can lead to a CTD ?

is this the right way to do it ?

 

Best regards,

Thanks

 

Share this post


Link to post
Share on other sites
27 minutes ago, killzone_kid said:

You can have player joining into some default unit then create whatever unit and selectPlayer into it

It seems to me that's the aim of the code I wrote... no?

 

Share this post


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

It seems to me that's the aim of the code I wrote... no?

 

 

hi PierreMGI,

 

(the same greeting as for killzone_kid, you already help me so much)

 

I don't see your post when I was replying.  thanks for the snippet.

I'll try your approach !

 

because of issue with sides (create B_xx unit in EAST side),  I need to use the alternative call to ''createUnit"


Thanks you all

 

Share this post


Link to post
Share on other sites

In fact, that works, even changing side of the unit.

Don't delete the edited player, just hide it, disable anim on it. It's the "entry point" for all players.

You can add a little delay just after creating the unit, and do not hesitate to join the group (again, even the same!) if you experience wrong side in MP.

 

So, still based on a logic init field:

0 = this spawn {
  waitUntil {getClientState == "BRIEFING READ" or !isMultiplayer};
  private _grp = createGroup WEST;
  private _plyr = _grp createUnit ["O_medic_F", _this getpos [300 * sqrt random 1,random 360],[],0,"none"];
  uiSleep 0.3;
  [_plyr] joinSilent _grp;
  selectPlayer _plyr;
  waitUntil {!isNull findDisplay 314};
  findDisplay 314 closeDisplay 0;
 };

 

As this code is common for all players, You can add an array of arrays [unit class, side,position] for example.
This array can be updated by deleteAt command each time a player joins and pick an element above.
So the best place is initPlayerLocal.sqf. The logic is a simple example.
Note: you should respawn as any player. No need to script something special if you want to get back in same class/same side.

Share this post


Link to post
Share on other sites
Quote

Don't delete the edited player, just hide it

 

hahaaaa, that do the tricks !

 

I keep all your ideas,  [unit class, side,position] and deleteAt

I update my mission with this logic, so I can freely spawn the player as the class/side I want.

 

the player respawn with the same class as startup so it will be fine!

 

Thanks you guys!

 

Share this post


Link to post
Share on other sites

update:

 

I've just tested, everything work as expected !

 

I notice that the 'addscore' method not work any more, not a big issue !

Share this post


Link to post
Share on other sites
7 minutes ago, pSiKO said:

I notice that the 'addscore' method not work any more, not a big issue !

 

Probably significant for other problems linked to the switch. You should add some lines for running some sqf. IMHO, It's an initialization issue as you play in a new unit.

The teamSwitch EH doesn't work in this case. You must run what you need after this switch.
PS: addScore must run on server. So, also think about some delayed codes for server also.

Share this post


Link to post
Share on other sites

yep, I think so !

 

but since the hard part is done, I can deal with the rest !

 

I will manage the score by myself.

 

again, thank for your help.

 

 

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

×