Jump to content
uncookedzebra

How to createVehicle and then delete when player disconnects?

Recommended Posts

Hi guys! I have been looking for a little bit now and I have been having an issue. I have it so that a player can create one item with a keystroke. If they press the key again it deletes that item and creates a new one. That I have no trouble with. What I have trouble with is getting the server to delete that particular item when that particular players leaves the game on a dedicated server. I been pulling my hair out trying to use publicVariableServer, getVariable, addmissionEventhandle and get everything to jive right. Thank you in advance!

Share this post


Link to post
Share on other sites

Okay this is what I have.

Flag_maker.sqf 
 

_id = clientOwner;
_UID = getplayerUID player;
_id publicVariableClient "Flag_UID_array";

 

flag = createVehicle ["FlagChecked_F", player modeltoworld [0,1,0], [], 0, "can_collide"];

 

_temp_array = [[_UID,flag]]; 
Flag_UID_array = Flag_UID_array + _temp_array;

 

publicVariableServer "Flag_UID_array";
 
 
 
 
Init.sqf
 
 _handler1 = addMissionEventHandler ["HandleDisconnect",{
{
 
UIDlookup = (Flag_UID_array select _x) select 0);
if (UIDlookup == (_this select 1)) then {
 
deleteVehicle (Flag_UID_array select _x) select 1);
deleteVehicle (Flag_UID_array select _x) select 2);
diag_log "Deleted Flag";
};
} foreach Flag_UID_array;
 
};
];

Share this post


Link to post
Share on other sites

That can be done much easier btw.:

 

Flag_maker.sqf

_flag = createVehicle ["FlagChecked_F", player modeltoworld [0,1,0], [], 0, "can_collide"];
player setVariable ["flag",_flag,true];

Init.sqf

if (isServer) then {
    _handler1 = addMissionEventHandler ["HandleDisconnect",{
        _player = _this select 0;
        _flag = _player getVariable ["flag",objNull];
        deleteVehicle _flag;
    }];
};

Share this post


Link to post
Share on other sites

Well, I did exactly that and it didn't work. :/
I also tried replacing isServer with isDedicated since I am running it off dedicated. Still no dice.

Share this post


Link to post
Share on other sites

This looks suspicious.

player setVariable ["flag",flag,true];

Try change to

_flag = createVehicle ["FlagChecked_F", player modeltoworld [0,1,0], [], 0, "can_collide"];
player setVariable ["flag",_flag,true];

Share this post


Link to post
Share on other sites

Well none of my diag_logs are firing. Does it have to do with the isServer?
 

if (isServer) then {
    _handler1 = addMissionEventHandler ["HandleDisconnect",{
        diag_log "DISCONNECT FIRED";
		_player = _this select 0;
		diag_log _player;
		diag_log "DISCONNECTED";
        _flag = _player getVariable ["flag",objNull];
        deleteVehicle _flag;
    }];
};

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

×