Jump to content
Sign in to follow this  
DAP

IsPlayer and Didicated server

Recommended Posts

So... I have problem with IsPlayer command. I use this script-structure:

While {true} do
{
[color="Blue"]WaitUntil {(isPlayer _unit)};[/color]

[b]Action1[/b]

[color="Red"]WaitUntil {!(isPlayer _unit)};[/color]

[b]Action2[/b]
};

When I pick this "_unit" in lobby and join, Action1 is happens, but when I go back in lobby, or even reconnect to the server, and pick another unit, Action2 not happens. Why? And how make it work?

Share this post


Link to post
Share on other sites
So... I have problem with IsPlayer command. I use this script-structure:

While {true} do
{
[color="Blue"]WaitUntil {(isPlayer _unit)};[/color]

[b]Action1[/b]

[color="Red"]WaitUntil {!(isPlayer _unit)};[/color]

[b]Action2[/b]
};

When I pick this "_unit" in lobby and join, Action1 is happens, but when I go back in lobby, or even reconnect to the server, and pick another unit, Action2 not happens. Why? And how make it work?

Need more information, like when is the script run and how is the unit passed to the script. Otherwise there could be multiple reasons.

Share this post


Link to post
Share on other sites
Need more information, like when is the script run and how is the unit passed to the script. Otherwise there could be multiple reasons.

Ok. Here is full script's "work-path". Script MPSquad.sqf running via unit's init.

MPsquad.sqf

_leader =_this select 0;
_group = group _leader;
_squad = units _group;

if (([color="Blue"][b]isServer[/b][/color]) or ([color="Blue"][b]isDedicated[/b][/color])) then 
{

{
if (!(isMultiplayer) and !(isPlayer _x)) then{deleteVehicle _x;};
[b][color="Red"]if (isMultiplayer) then{[_x] execVM "Scripts\SP\PlayerSlotManager.sqf";};[/color][/b]

}ForEach _squad;

};

PlayerSlotManager.sqf

_unit = _this select 0;
_dir = getDir _unit;
_group = group _unit;

_weapons = weapons _unit;
_ammo = magazines _unit;

_startpos = _unit modelToWorld [0,0,0];
_safepos = _unit modelToWorld [0,0,-1000];

private ["_group","_newgroup"];

While {true} do 
{
if (_unit != (leader group _unit)) then 
{
_newgroup = createGroup (side _group);
Hint str(_newgroup);
[_unit] JoinSilent _newgroup;
};

_unit allowDamage false;
_unit setDamage 0;
_unit setHit ["hands",0];
_unit setHit ["legs",0];
_unit switchMove "";

_unit setVehicleInit "this enableSimulation false; this hideObject true;";
processInitCommands;
clearVehicleInit _unit;

removeallWeapons _unit;
{_unit addMagazine _x}ForEach _ammo;
{_unit addWeapon _x}ForEach _weapons;

_unit setPos _safepos;
_unit setDir _dir;

[color="Red"]WaitUntil {([b]isPlayer[/b] _unit);};[/color]---- [i]it's works[/i]

if (isPlayer (leader _group)) then
{
[_unit] JoinSilent _group;
deleteGroup _newgroup;
};

_unit setPos _startpos;
_unit setDir _dir;

_unit setVehicleInit "this enableSimulation true; this hideObject false;";
processInitCommands;
clearVehicleInit _unit;
_unit allowDamage true;

[color="Red"]WaitUntil {([b]![/b]([b]isPlayer[/b] _unit));};[/color] - [i]It's not works. Even if I disconnect from server and connect again. Whole cycle not works because of this.[/i]
};

Edited by DAP

Share this post


Link to post
Share on other sites

Ok, i think I may know what is going on. I'm not EXACTLY sure because i've never done this, but declaring the group variable private after the variable was already initialized to its first value could re-create the variable to the scope making it nil again. The if statement at the beginning comparing the _unit to the group leader will always be true if the unit has died (should go to that condition after a DC or respawn). It will pass through that if statement and try to createGroup using the side of a variable that is nil. That would definitely cause a problem.

Share this post


Link to post
Share on other sites
Ok, i think I may know what is going on. I'm not EXACTLY sure because i've never done this, but declaring the group variable private after the variable was already initialized to its first value could re-create the variable to the scope making it nil again. The if statement at the beginning comparing the _unit to the group leader will always be true if the unit has died (should go to that condition after a DC or respawn). It will pass through that if statement and try to createGroup using the side of a variable that is nil. That would definitely cause a problem.

Thanks. Very helpful. Main problem was in groups joins-rejoins and locality. When player pick leader of group, then whole group change locality from server to player's client. This is cause to mismatch of variable "_unit" and soldier (interesting why?). But I still have no idea how fix this. Sometimes even without groups changes, condition WaitUntil not works when you change your soldier in same group.

Share this post


Link to post
Share on other sites
Thanks. Very helpful. Main problem was in groups joins-rejoins and locality. When player pick leader of group, then whole group change locality from server to player's client. This is cause to mismatch of variable "_unit" and soldier (interesting why?). But I still have no idea how fix this. Sometimes even without groups changes, condition WaitUntil not works when you change your soldier in same group.

EDIT: Nvm, hmm. I think this script needs to be re-written. Its difficult to maintain.

Also, this script will just pile up everytime someone dies. Not a very good situation.

Edited by tacticalnuggets

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
Sign in to follow this  

×