Jump to content
  • 0

How do I write damage to object in database?


Darce

Question

Using a default hive child, how would I add damage to a player built object residing in the database? So if a player uses the item it gets damaged through wear and tear, eventually resulting in it being deleted once damage = 1.0

Link to comment
Share on other sites

13 answers to this question

Recommended Posts

  • 0

Appreciate your taking the effort to reply, yet it's not very helpful. Is it a matter of semantics perhaps?

A player built item, or object if you prefer, can be damaged. How does the damage to the item, or object, get written to the hive?

So far I have;
 

_objectID = _item getVariable["ObjectID","0"];
_objectUID = _item getVariable["ObjectUID","0"];
_damage = damage _item;
_damage = _damage + _increment;
_item setDamage _damage;

Now, how would I update the hive so the thing will deteriorate with use?

Link to comment
Share on other sites

  • 0

Bump?

 

Player builds a firebarrel, it publishes to the database with 0 damage

Player lights firebarrel, each time it is lit it does 0.01 damage to the object

After 100 uses, it's damage equals 1, allowing the sql which removes objects with damage = 1.0 from database and the player needs to build another.

 

Happy with writing code for everything aside from publishing the revised damage to the database.  How would i update the hive to reflect the revised damage?

Link to comment
Share on other sites

  • 0

Hi.

Maybe it has something to do with your commas. It is really hard to read that one sentence with all those commas that do not belong there.

A player builds an item (more likely object) that can be damaged.

Sorry but your idea is not well planned. The database has to search the object and then update it that causes a tonns of traffic and loading time.

Link to comment
Share on other sites

  • 0

Just setDamage 0.01 in the firebarrel then use the update call type: "damage" or "all"

 

That sounds like the thing I need, but could you supply more information?

_var = damage _object;  would load _var with the object's damage value but not write/update the hive entry.

Link to comment
Share on other sites

  • 0

Hi.

Maybe it has something to do with your commas. It is really hard to read that one sentence with all those commas that do not belong there.

A player builds an item (more likely object) that can be damaged.

Sorry but your idea is not well planned. The database has to search the object and then update it that causes a tonns of traffic and loading time.

 

Thank you for the valuable lesson in grammar.  As a grammar nazi myself, I am quite comfortable with my use of the comma; perhaps one of those would appease you?

 

Now, where do I find the button to say "Gee whizz, but that fellow was sooooooo helpful!"?

Link to comment
Share on other sites

  • 0

Thank you for the valuable lesson in grammar.  As a grammar nazi myself, I am quite comfortable with my use of the comma; perhaps one of those would appease you?

 

Now, where do I find the button to say "Gee whizz, but that fellow was sooooooo helpful!"?

 

I'm sorry i didn't mean to offend you. I was only trying to point out, that it was hard to understand what exactly you wanted.

Anyway:

Lighting objects is part of dayz_code.pbo. Now, i could not find how or where the object is being set on fire, you might want to ask SchwEde for that, as he is good in digging out that stuff.

 

What i could find is the fire_monitor.sqf. Now, if you go into your compiles.sqf and change this line to something inside your Mission folder.

player_fireMonitor = 		compile preprocessFileLineNumbers "\z\addons\dayz_code\system\fire_monitor.sqf";

-----------

player_fireMonitor = 		compile preprocessFileLineNumbers "Example\system\fire_monitor.sqf";

you can have a custom fire_monitor. Now the fire_monitor is called each time something is being set on fire, so inside the Original fire Monitor, which looks like so:

 

private["_firePlace","_ok","_mags","_serial","_qty","_countr"];
_firePlace = _this;
while {alive _firePlace} do {
	while {inflamed _firePlace && alive _fireplace} do {
		//Use Wood
		_ok = false;
		_mags = getMagazineCargo _firePlace;
		clearMagazineCargoGlobal _firePlace;
		clearWeaponCargoGlobal _firePlace;
		_serial = (_mags select 0) find "PartWoodPile";
		_qty = 0;
		if (_serial >= 0) then {
			_qty = (_mags select 1) select _serial;
		};
		_ok = false;
		if (_qty > 0) then {
			_qty = _qty - 1;
			_ok = true;
			if (_qty > 0) then {
				_firePlace addMagazineCargoGlobal ["PartWoodPile",_qty];
			};
		};
		if (_ok) then {
			_countr = 0;
			while {_ok} do {
				_countr = _countr + 1;
				if (_countr > 600) then {_ok = false};
				if (!inflamed _firePlace) then {_ok = false};
				if (!alive _firePlace) then {_ok = false};
				sleep 1;
			};
		} else {
			_firePlace inflame false;
		};
	};
	while {!inflamed _firePlace && alive _fireplace} do {
		//Wait
		sleep 1;
	};
	sleep 1;
};

 

You could add some Damage on age (i.e. a Loop, that will damage the Object every x seconds)

 

private["_firePlace","_ok","_mags","_serial","_qty","_countr","_damage","_damageCalc"];
_firePlace = _this;
while {alive _firePlace} do {
	while {inflamed _firePlace && alive _fireplace} do {
	
		while {true} do {
			_damage = getDammage _firePlace;
			_damageCalc = _damage + 0.01;
			_firePlace setDamage _damageCalc;
			sleep 360;
		};
	
		//Use Wood
		_ok = false;
		_mags = getMagazineCargo _firePlace;
		clearMagazineCargoGlobal _firePlace;
		clearWeaponCargoGlobal _firePlace;
		_serial = (_mags select 0) find "PartWoodPile";
		_qty = 0;
		if (_serial >= 0) then {
			_qty = (_mags select 1) select _serial;
		};
		_ok = false;
		if (_qty > 0) then {
			_qty = _qty - 1;
			_ok = true;
			if (_qty > 0) then {
				_firePlace addMagazineCargoGlobal ["PartWoodPile",_qty];
			};
		};
		if (_ok) then {
			_countr = 0;
			while {_ok} do {
				_countr = _countr + 1;
				if (_countr > 600) then {_ok = false};
				if (!inflamed _firePlace) then {_ok = false};
				if (!alive _firePlace) then {_ok = false};
				sleep 1;
			};
		} else {
			_firePlace inflame false;
		};
	};
	while {!inflamed _firePlace && alive _fireplace} do {
		//Wait
		sleep 1;
	};
	sleep 1;
};

Alright umm this is untested. What i did was: I added a loop, that runs every 360 seconds. It will get the current Damage, then re-calculate the damage and set the Damage to the new value. .

Link to comment
Share on other sites

  • 0

Naw, not offended.  Just a gentle ribbing :P

 

My question is not how to damage an object, but how do I write a new damage value to the hive?

 

The use of a fire barrel was only an example, it could be any player built object.  The idea is to have player built objects degrade through use, not an arbitrary time period.

 

I think my answer lays within server_update_object (server compiles folder)

_object_damage = {
	private["_hitpoints","_array","_hit","_selection","_key","_damage"];
		_hitpoints = _object call vehicle_getHitpoints;
		_damage = damage _object;
		_array = [];
		{
			_hit = [_object,_x] call object_getHit;
			_selection = getText (configFile >> "CfgVehicles" >> (typeOf _object) >> "HitPoints" >> _x >> "name");
			if (_hit > 0) then {_array set [count _array,[_selection,_hit]]};
			_object setHit ["_selection", _hit];
		} count _hitpoints;
	
		_key = format["CHILD:306:%1:%2:%3:",_objectID,_array,_damage];
		//diag_log ("HIVE: WRITE: "+ str(_key));
		_key call server_hiveWrite;
	_object setVariable ["needUpdate",false,true];
	};

My problem is, how do I call that routine to update an object's damage value?  But an object may not have an array of parts to record damage (why I used fire barrel as an example)

Link to comment
Share on other sites

  • 0

What you found there is the "PVDZE_veh_Update". That is a public variable, that is used to update vehicles and objects.

 

Use like so:

	
// Update the Vehicle it want's the Target (1), the update type (either all, position, gear, damage, killed or repair) and at last the called which is the player allways, but not necessary.
PVDZE_veh_Update = [_target, "damage", player]; 
publicVariableServer "PVDZE_veh_Update"; 

//EDIT: This is used FROM the Mission Folder TO the server.

Link to comment
Share on other sites

  • 0

The difference between item and object is not a matter of semantics but rather one of terminology. For the Arma engine they are two different things. Items are things like drinks cans, ammo mag, guns, other items that a player may put in their inventory. These items are not usually saved to the DB unless they are stored I side something.  Items are not referencable by the Arma engine individually and cannot have variables attached to them (ie, ownership information, damage information).

Objects are Arma world items that are given an object reference by the game engine. These include vehicles, built Epoch buildables, other sqf / sqm file added map content (for the most part).  They can be referenced individually and can have variables attached to them.

As they are two different classes of items in Arma, it was leading to confusion. Items are not usually persistent unless I an inventory space, objects are.

Ok, so to answer your question...

Both yourself and UK Martin have got the right items. Server_updateObject.sqf is the server side call that updates the DB object (via a hiveext call) and the PVDZE_veh_Update is the client side public variable sent via publicvariableserver, with the required info, to the server to tell the server to run the object update script.

 

THe other area of confusion is the difference between hitpoints and damage.  These are two distinct items.  Hitpoints denote where on the object damage has occured and is helpful for denoting a tyre is badly damages or a rotor assembly will cause problems with trying to fly a helicopter.  Damage is the overall damage of the object.  The valid range for damage is between 0 and 1.  When this is 1 then the object is considered destroyed.

 

Hitpoints can be empty whatever damage is set to.  Epoch buildables also do not use the hitpoints field (in vanilla Epoch at least).

Link to comment
Share on other sites

  • 0

What you found there is the "PVDZE_veh_Update". That is a public variable, that is used to update vehicles and objects.

 

Use like so:

	
// Update the Vehicle it want's the Target (1), the update type (either all, position, gear, damage, killed or repair) and at last the called which is the player allways, but not necessary.
PVDZE_veh_Update = [_target, "damage", player]; 
publicVariableServer "PVDZE_veh_Update"; 

//EDIT: This is used FROM the Mission Folder TO the server.

So all I need do is publish the PVDZE_veh_update and the server writes to the hive?

 

LOL, sounds too easy....  fingers crossed I can try it later on.

 

Many thanks gents

Link to comment
Share on other sites

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
  • Advertisement
  • Discord

×
×
  • Create New...