Jump to content
Sign in to follow this  
Norbak

Delete object (name) when player or players disconnect.

Recommended Posts

how could i make to work a script to delete a vehicle or object when a specific (or not) player disconnects?

 

i tried:

 

 

if (isNull player) then {deletevehicle Cube4};

and...

If (!local player) then {deletevehicle Cube4};

 

but didn't work. Object "Cube4" is still alive when the player disconnects.

Any idea?.

 

Share this post


Link to post
Share on other sites


onPlayerDisconnected "deleteVehicle cube4";

Share this post


Link to post
Share on other sites

Thanks, but how to make it inside a trigger?

Share this post


Link to post
Share on other sites
onPlayerDisconnected "deleteVehicle cube4";

 

Should i put this inside the init of the unit?, or could it work inside init.sqf making something like:

 

if (player == Soldier2)  then  {onPlayerDisconnected "deleteVehicle Cube4";};

If (player == Soldier9)  then {onPlayerDisconnected "deleteVehicle Flash2";};

....

 

Share this post


Link to post
Share on other sites

Thanks, but how to make it inside a trigger?

Should i put this inside the init of the unit?, or could it work inside init.sqf making something like:

 

This scripting command must be executed on the server to work properly in multiplayer!

Share this post


Link to post
Share on other sites

I'm trying to to something like this but didn't work:

 

 

onPlayerDisconnected = "if (!isPlayer player) then {deletevehicle House1}";

Share this post


Link to post
Share on other sites

player variable is undefined on server.

onPlayerDisconnected "deletevehicle House1";
  • Like 1

Share this post


Link to post
Share on other sites

hmm i see. and does onplayerdisconnected accept more than 1 action?

Share this post


Link to post
Share on other sites

Sure! See examples.

Those examples are not telling me great things. I can't understand its funtion.

Share this post


Link to post
Share on other sites

 

onPlayerDisconnected = "deletevehicle House1; deletevehicle House2; deletemarker "marker1";"; ??? .

It's not working for me. Am i doing anything wrong?

Share this post


Link to post
Share on other sites


onPlayerDisconnected "deletevehicle House1; deletevehicle House2; deletemarker 'marker1';";

  • Like 1

Share this post


Link to post
Share on other sites

It's not working for me.

 

I need to delete an object made using a local script with a global effect.

 

 

If local player then {

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

};

 

* When he dies his "YourOwnVehicle" is deleted but...

 

when he disconnects "YourOwnVehicle" is still alive.

Share this post


Link to post
Share on other sites

Player side:

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

publicVariableServer "YourOwnVehicle";

Server side:

YourOwnVehicles = [];

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

	YourOwnVehicles = [];
";

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

	YourOwnVehicle = nil;
};

Share this post


Link to post
Share on other sites

I tested it. It works. But i need to make some addons. Thank you, Schatten

Share this post


Link to post
Share on other sites

I'm learning to use these commands. Thank you.

 

Next level. More than one array inside ONDISCONNECTED?

 

 

 

Server Side:

 

YourOwnVehicles = [];

ArraysToDelete = _this nearObjects [["Thing","Car","Static"], 20];

 

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

    {_x spawn {deleteVehicle _this}} forEach ArraysToDelete;

    YourOwnVehicle = [];
    ArraysToDelete = [];
";
 

"YourOwnVehicle" addPublicVariableEventHandler {

    YourOwnVehicles set [count YourOwnVehicles, YourOwnVehicle];

    YourOwnVehicle = nil;
};

 

 

"BASE" addPublicVariableEventHandler {

   ArraysToDelete set [count ArraysToDelete, BASE];

   BASE = nil;
};

 

 

CLIENT SIDE 1:

 

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

publicVariableServer "YourOwnVehicle";

 

CLIENT SIDE 2:

 

BASE = [getPos Player, random 360, "smallbase_EP1"] call (compile (preprocessFileLineNumbers "ca\modules\dyno\data\scripts\objectMapper.sqf"));

publicVariableServer "BASE";

Share this post


Link to post
Share on other sites

But that "_this" in "ArraysToDelete = _this nearObjects [["Thing","Car","Static"], 20];" shouldn't be the player but something inside BASE..

 

Maybe using this in Client Side 2? :

 

CLIENT SIDE 2:

itemx = createVehicle ["Baseball", [(getpos player) select 0,(getpos player) select 1,0], [], 0, "NONE"];    // Spawning that base creates ITEMX aswell.

And changing Server Side to:

 

ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20];

Share this post


Link to post
Share on other sites

More than one array inside ONDISCONNECTED?

onPlayerDisconnected "
	{_x spawn {deleteVehicle _this}} forEach (YourOwnVehicles + ArraysToDelete);

	YourOwnVehicles = [];
	ArraysToDelete = [];
";

And changing Server Side to:

ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20];

itemx is undefined on server side. You can broadcast it from client before.

Share this post


Link to post
Share on other sites

itemx = createVehicle ["Baseball", [(getpos player) select 0,(getpos player) select 1,0], [], 0, "NONE"];

 

 

Publicvariableserver "ITEMX";

 

 

Then... ??

 

ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20];

Share this post


Link to post
Share on other sites


waitUntil {

sleep 0.1;

!(isNil "itemx")

};

ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20];

Share this post


Link to post
Share on other sites
waitUntil {
	sleep 0.1;

	!(isNil "itemx")
};

ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20];

Not sure if that could work. It will using the unit which makes "BASE" but not sure for the rest of units. Waituntil {!(isNil "Itemx"} if's forcing to make an ITEMX every time.

Share this post


Link to post
Share on other sites

itemx is undefined on server. waitUntil needs to wait until itemx will be broadcasted from client.

Share this post


Link to post
Share on other sites

itemx is undefined on server. waitUntil needs to wait until itemx will be broadcasted from client.

Then if the cleint doesn't create "Itemx", Waituntil will never end and will never start "OnPlayerDisconnected"?. Is that right?. So it's a big problem.

Share this post


Link to post
Share on other sites

Then if the cleint doesn't create "Itemx", Waituntil will never end and will never start "OnPlayerDisconnected"?. Is that right?. So it's a big problem.

Yes. But you can wait some seconds:

_time = time + 5;

waitUntil {
	sleep 0.1;

	!(isNil "itemx") or {time > _time}
};

if (!(isNil "itemx")) then {ArraysToDelete = itemx nearObjects [["Thing","Car","Static"], 20]};

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  

×