Jump to content
Sign in to follow this  
Norbak

Delete object (name) when player or players disconnect.

Recommended Posts

Hmm interesting. Then a player who can't make a "itemX" will only wait "waituntil {}" for 5 seconds... and a player who can make "Itemx" will wait for "itemx" or not.

Interesting thing. Thanks for this great tip.

I'll test later.

Share this post


Link to post
Share on other sites

It didn't work.. Maybe i did something wrong.

Share this post


Link to post
Share on other sites

I'm doing something wrong.it's not working now for me.do i need to place Onplayerdisconnected in init.sqf or in a trigger in the editor?

Server side is a trigger in the editor ,yes?. Repeatable and local player?

 

And another issue:

 

YourOwnVehicles = [];

onPlayerDisconnected "
    {_x spawn {deleteVehicle _this}} forEach YourOwnVehicles;

    YourOwnVehicles = [];
"
;

"YourOwnVehicle" addPublicVariableEventHandler {
    YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle];

    YourOwnVehicle = nil;
};

 

Every player ( player1 and player2) are able to spawn a "Yourownvehicle". When one of them disconnects the other Yourownvehicle item is deleted aswell, not only the player1's vehicle. Is this correct?. Is there any kind of fix this to delete only our own item?

Share this post


Link to post
Share on other sites

do i need to place Onplayerdisconnected in init.sqf or in a trigger in the editor?

You need place onPlayerDisconnected command only in SQF-file (for example, init.sqf) and only once, because repeated placing onPlayerDisconnected overwrites previous assigned code.

 

Server side is a trigger in the editor ,yes?. Repeatable and local player?

I'm not sure, but I think that triggers placed in editor are server objects, but activation statements, type, etc. are local for each player.

 

Every player ( player1 and player2) are able to spawn a "Yourownvehicle". When one of them disconnects the other Yourownvehicle item is deleted aswell, not only the player1's vehicle. Is this correct?. Is there any kind of fix this to delete only our own item?

Try this (needs Functions module).

Player side:

YourOwnVehicle = "Old_moto_TK_Civ_EP1" createVehicle [(getPos player) select 0, (getPos player) select 1, 0.3];

YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];

publicVariableServer "YourOwnVehicle";

Server side:

YourOwnVehicles = [];

onPlayerDisconnected "
	_indexes = [];

	{
		if ((_x getVariable ['ownerUid', '']) == _uid) then {
			_indexes set [count _indexes, _forEachIndex];

			_scriptHandler = _x spawn {deleteVehicle _this};

			waitUntil {
				sleep 0.1;

				scriptDone _scriptHandler
			};
		};
	}
	forEach YourOwnVehicles;

	YourOwnVehicles = [YourOwnVehicles, _indexes] call BIS_fnc_removeIndex;
";

"YourOwnVehicle" addPublicVariableEventHandler {
	YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle];

	YourOwnVehicle = nil;
};

Share this post


Link to post
Share on other sites

I  see. Using UID is a good idea. I wasn't to know how to do this. So i'll test and i'll reply you,Schaten.

But if we need to delete more than one item while disconnected?. maybe? ====>

 

  • "YourOwnVehicle2" addPublicVariableEventHandler {
  •     YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle2];
  •  
  •     YourOwnVehicle2 = nil;
  • };
    • "YourOwnVehicle3" addPublicVariableEventHandler {
    •     YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle3];
    •  
    •     YourOwnVehicle3 = nil;
    • };

Share this post


Link to post
Share on other sites

But if we need to delete more than one item while disconnected?. maybe? ====>

That is unnecessary to use addPublicVariableEventHandler for each public variable:

 

YourOwnVehicle = "Old_moto_TK_Civ_EP1" createVehicle _position1;

YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];

publicVariableServer "YourOwnVehicle";

YourOwnVehicle = "hilux1_civil_3_open_EP1" createVehicle _position2;

YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];

publicVariableServer "YourOwnVehicle";

...

Server side is without changes.

  • Like 1

Share this post


Link to post
Share on other sites

I meant a different item.

  • "YourOwnVehicle" addPublicVariableEventHandler {
  •     YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle];
  •  
  •     YourOwnVehicle = nil;
  • };
  • "Anotheritem" addPublicVariableEventHandler {
  •     YourOwnVehicles set [count YourOwnVehicles, anotheritem];
  •  
  •     anotheritem = nil;
  • };
  • "Aflyingcarpet" addPublicVariableEventHandler {
  •     YourOwnVehicles set [count YourOwnVehicles, Aflyingcarpet];
  •  
  •     Aflyingcarpet = nil;
  • };

And so. Because those items are made yet with static names.

Share this post


Link to post
Share on other sites

I meant a different item.

And? You use same code several times!

 

Because those items are made yet with static names.

YourOwnVehicle = "Old_moto_TK_Civ_EP1" createVehicle _position1;
 
YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];
 
publicVariableServer "YourOwnVehicle";
 
Anotheritem = "hilux1_civil_3_open_EP1" createVehicle _position2;

YourOwnVehicle = Anotheritem;
 
YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];
 
publicVariableServer "YourOwnVehicle";

Aflyingcarpet = ...;

YourOwnVehicle = Aflyingcarpet;
 
YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];
 
publicVariableServer "YourOwnVehicle";
  • Like 1

Share this post


Link to post
Share on other sites

Great!. And is that for deleting differents items at the same time when disconnected?. So, it's great!

 

 

Then i use this type of script to delete markers and triggers aswell?

 

-marker-

Mymarker1 = createmarker ["marker1",getpos player1];

     Mymarker1 setmarkerText format ["Myposition",name player];
     Mymarker1 setmarkerType "city";
     Mymarker1 setMarkerColor "ColorRed";
     Mymarker1 setmarkerpos getPos player1;

 

     YourOwnVehicle = Mymarker1;

     Yourownvehicle setVariable ["ownerUid", getPlayerUID player, true];

     publicVariableServer "YourOwnVehicle";

 

 

-trigger-

Mytrigger = createTrigger ["EmptyDetector", [0,0,0]];
Mytrigger setTriggerArea [0, 0, 0, false];
Mytrigger setTriggerActivation ["NONE", "present",true];

 

YourOwnVehicle = Mytrigger;

YourOwnVehicle setVariable ["ownerUid", getPlayerUID player, true];

publicVariableServer "YourOwnVehicle";

 

 

Then those will delete Yourownvehicle at the same time if needed, when Yourownvehicle is: Yourownvehicle,Anotheritem,Aflyingcarpet,Mymarker1,Mytrigger?

Share this post


Link to post
Share on other sites

Then i use this type of script to delete markers and triggers aswell?

Yes, you can.

Share this post


Link to post
Share on other sites

I think i'm really confused with this command. It's working randomly.

Share this post


Link to post
Share on other sites

You simply could use the Schatten's script...:

YourOwnVehicles = [];

onPlayerDisconnected "
	{_x spawn {deleteVehicle _this}} forEach YourOwnVehicles;

	YourOwnVehicles = [];
";

"YourOwnVehicle" addPublicVariableEventHandler {
	YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle];

	YourOwnVehicle = nil;
};

And using a Trigger in the .sqf of the object ("AnotherItem" in this case) to make possible its elimination, just after the object creation line:


AnotherItemTrig = createTrigger ["EmptyDetector", [0,0,0]]; 
AnotherItemTrig setTriggerArea [0, 0, 0, false];
AnotherItemTrig setTriggerActivation ["NONE", "present", false];
AnotherItemTrig setTriggerStatements ["!alive Player", "hint ""Player died and this object should be deleted now.""; deletevehicle AnotherItemTrig; deletevehicle AnotherItem", ""];

(Hint part could be erased. It's only for a debug)

 

All this should work like:

 

1) Player disconnects and reset the player like a dead body.

2) Trigger detects the player and start deleting the trigger and the object.

 

* Add a trigger in every .sqf of every object.

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  

×