Jump to content
  • 0

Duplicate ObjectUID


SmokeyBR

Question

ive recently had some reports of missing vehicles i noticed those specific missing vehicles had duplicate ObjectUID and one them gets deleted after server restart. So i went around and looked for a similiar problem and found that it is a known bug in github dayzepoch.

I made the changes made by @ebaydayz here and then noticed a few changes here, ive made all those changes of course i am not sure if these codes can acctually be used in 1.0.5.1 since on 1.0.6 theres no ObjectUID and ObjectUID3 functions.
the thing is i am unsure if its acctually working, for example every server restart i get these two messages

Spoiler

18:59:23 "Duplicate UID generated by dayz_objectUID2. Automatically corrected to +1= 11. This should rarely happen."
18:59:25 "Duplicate UID generated by dayz_objectUID2. Automatically corrected to +1= 12. This should rarely happen."

 

//These 2 messages are always present on server restart

and i got a db backup which i was sure had duplicates ObjectUID and still one of the duplicate vehicle got deleted, maybe someone could explain how this acctually works or there could be something wrong with my changes.

Changes made:

server_functions.sqf

Spoiler

currentObjectUIDs = [];
keyStartNumber = 10;

dayz_objectUID = {
	private["_position","_dir","_key","_object"];
	_object = _this;
	_position = getPosATL _object;
	_dir = direction _object;
	_key = [_dir,_position] call dayz_objectUID2;
    _key
};

//Vectors
dayz_objectUID2 = {
    private["_position","_dir","_key","_element","_vector","_set","_vecCnt","_usedVec"];
    _dir = _this select 0;
    _key = "";
    _position = _this select 1;

    if((count _this) == 2) then{
        {
            _x = _x * 10;
            if ( _x < 0 ) then { _x = _x * -10 };
            _key = _key + str(round(_x));
        } count _position;
        _key = _key + str(round(_dir));
    }else{
        _vector = [];
        _usedVec = false;
        {
            _element = _x;
            if(typeName _element == "ARRAY") then{
                _vector = _element;
                if((count _vector) == 2)then{
                    if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
                            {
                                _x = _x * 10;
                                if ( _x < 0 ) then { _x = _x * -10 };
                                _key = _key + str(round(_x));
                            } count _position;

                            _vecCnt = 0;
                            {
                                _set = _x;
                                {
                                    _vecCnt = _vecCnt + (round (_x * 100));

                                } foreach _set;

                            } foreach _vector;
                            if(_vecCnt < 0)then{
                                _vecCnt = ((_vecCnt * -1) * 3);
                            };
                            _key = _key + str(_vecCnt);
                            _usedVec = true;
                    };
                };
            };
        } count _this;

        if!(_usedVec) then{
                {
                    _x = _x * 10;
                    if ( _x < 0 ) then { _x = _x * -10 };
                    _key = _key + str(round(_x));
                } count _position;
                _key = _key + str(round(_dir));
        };
	};
	// Make sure the generated key is not a duplicate
	while {true} do {
		if !(_key in currentObjectUIDs) exitWith {currentObjectUIDs set [count currentObjectUIDs,_key];};
		keyStartNumber = keyStartNumber + 1;
		if (keyStartNumber > 40000) exitWith { //Should never fail more times than total number of objects in database
			diag_log format["ERROR: dayz_objectUID2 failed to correct duplicate objectUID: %1. This should not happen.",_key];
		};
		_key = str keyStartNumber;
		diag_log format["Duplicate UID generated by dayz_objectUID2. Automatically corrected to +1= %1. This should rarely happen.",_key];
	};
    _key
};
//VectorsEND

dayz_objectUID3 = {
	private["_position","_dir","_key"];
	_dir = _this select 0;
	_key = "";
	_position = _this select 1;
	{
		_x = _x * 10;
		if ( _x < 0 ) then { _x = _x * -10 };
		_key = _key + str(round(_x));
	} count _position;
	_key = _key + str(round(_dir + time));
	while {true} do {
		if !(_key in currentObjectUIDs) exitWith {currentObjectUIDs set [count currentObjectUIDs,_key];};
		keyStartNumber = keyStartNumber + 1;
		if (keyStartNumber > 40000) exitWith { //Should never fail more times than total number of objects in database
			diag_log format["ERROR: dayz_objectUID3 failed to correct duplicate objectUID: %1. This should not happen.",_key];
		};
		_key = str keyStartNumber;
		diag_log format["Duplicate UID generated by dayz_objectUID3. Automatically corrected to +1= %1. This should rarely happen.",_key];
	};
	_key
};

 

server_monitor.sqf

Spoiler

	// # NOW SPAWN OBJECTS #
	_totalvehicles = 0;
	{
		_idKey = 		_x select 1;
		_type =			_x select 2;
		_ownerID = 		_x select 3;

		_worldspace = 	_x select 4;
		_inventory =	_x select 5;
		_hitPoints =	_x select 6;
		_fuel =			_x select 7;
		_damage = 		_x select 8;
		
		// Set objectUIDs in currentObjectUIDs list to prevent duplicates
		if (_type in dayz_allowedObjects) then {_worldspace call dayz_objectUID2;} else {_worldspace call dayz_objectUID3;};
		
		_dir = 0;
		_pos = [0,0,0];
		_wsDone = false;
		if (count _worldspace >= 2) then
		{
			_dir = _worldspace select 0;
			if (count (_worldspace select 1) == 3) then {
				_pos = _worldspace select 1;
				_wsDone = true;
			}
		};			
		
		if (!_wsDone) then {
			if (count _worldspace >= 1) then { _dir = _worldspace select 0; };
			_pos = [getMarkerPos "center",0,4000,10,0,2000,0] call BIS_fnc_findSafePos;
			if (count _pos < 3) then { _pos = [_pos select 0,_pos select 1,0]; };
			diag_log ("MOVED OBJ: " + str(_idKey) + " of class " + _type + " to pos: " + str(_pos));
		};
		
		//Vectors Start
		_vector = [[0,0,0],[0,0,0]];
		_vecExists = false;
		_ownerPUID = "0";   
		if (count _worldspace >= 3) then{
			if(count _worldspace == 3) then{
					if(typename (_worldspace select 2) == "STRING")then{
						_ownerPUID = _worldspace select 2;
					}else{
						 if(typename (_worldspace select 2) == "ARRAY")then{
							_vector = _worldspace select 2;
							if(count _vector == 2)then{
								if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
									_vecExists = true;
								};
							};
						};                  
					};

			}else{
				//Was not 3 elements, so check if 4 or more
				if(count _worldspace == 4) then{
					if(typename (_worldspace select 3) == "STRING")then{
						_ownerPUID = _worldspace select 3;
					}else{
						if(typename (_worldspace select 2) == "STRING")then{
							_ownerPUID = _worldspace select 2;
						};
					};


					if(typename (_worldspace select 2) == "ARRAY")then{
						_vector = _worldspace select 2;
						if(count _vector == 2)then{
							if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
								_vecExists = true;
							};
						};
					}else{
						if(typename (_worldspace select 3) == "ARRAY")then{
							_vector = _worldspace select 3;
							if(count _vector == 2)then{
								if(((count (_vector select 0)) == 3) && ((count (_vector select 1)) == 3))then{
									_vecExists = true;
								};
							};
						};
					};

				}else{
					//More than 3 or 4 elements found
					//Might add a search for the vector, ownerPUID will equal 0
				};
			};
		}; 		
		//Vectors End

 

 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Discord

×
×
  • Create New...