OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: jphilapy on 27 Jan 2006, 12:41:28
-
Is there anyway to prevent a destructible building from being destroyed?
Thanks,
Jeff
-
Not directly, but you can detect when it is damaged and setDammage 0. Can you attach eventHandlers to buildings? Dunno ... but a simple getDammage loop would do the trick.
-
This addEventHandler ["hit", {(_this select 0)setdammage 0}]
-
I am not sure a {hit} event handler would detect an explosion from say a satchel cahrge. Whar about a {dammaged} EH?
I use the loop method suggested by macguba
-
After reading around I tried this and it seems to work against machine guns but for satchels or tanks it still gets destroyed. However that is a good thing. There is few things more annoying then to be inside a building shooting a guy using my m60 and have the building crumple around me because it had already taken gun fire earlier from a 50 cal. So this snippet of code solves my problem in this area.
I just add it as the init of a game logic.
;indestruct.sqs
_obj = _this select 0;
#start
_obj setdammage 0;
goto "start"
Thanks for your replies,
Jeff
-
Isn't that going to be greedy?
-
Isn't that going to be greedy?
When I ran the test without the delay the game didnt lag. However it would only help to test if the building is damaged first.
Jeff
-
Not directly, but you can detect when it is damaged and setDammage 0. Can you attach eventHandlers to buildings? Dunno ... but a simple getDammage loop would do the trick.
Im sure you can pass the id of the building to the script:
object #
Where the # is the id of the building.
In anycase I was not able to stop the destruction of the building using an eventhandler. However I think this is due to the way the handler detects damage. Like it isnt detecting it fast enough.
So I tried to do the following:
_house = _this select 0;
#start
? GetDammage _house : _house setdammage 0;
goto "start"
But I am able to destroy the building with a M2.
So I do the following:
_house = _this select 0;
#start
_house setdammage 0;
goto "start"
Im not able to do destroy the building with an M2.
About it being greedy, seems that detecting if the building has damage wont work. But running the script constantly to keep the building at full health seems to work.
When I found this snippet it had a 2 second delay. I forget where in this forum I found it.
Jeff
-
maybe you need a small delay for it to work. The dammage checks probably don't have time to return a value before the check runs again.
-
Try this - or something similar:
;ProtectObject.sqs
_obj = _this select 0
#loop
@(getDammage _obj > 0.2)
_obj setDammage 0
goto"loop"
call by:
[object xxxx] exec "ProtectObject.sqs"
or for objects you have placed in the editor:
[objectname] exec "ProtectObject.sqs"
If you want the building to become destroyable later on in the mission then you can do this:
;ProtectObject.sqs
_obj = _this select 0
#loop
@(getDammage _obj > 0.2)
if okToDestroy then {exit}
_obj setDammage 0
goto"loop"
Where okToDestroy is a global variable that you set to false at the start of the mission and set to true when the building can be destroyed.
-
*sigh*
Absolutely positively no need for any looping scripts in this case...
Click "Show ID's" in the editor, then check out the object ID of the house you wanna indestructible and then in the init.sqs (preferrably) or in some game logics or other init field:
(object XXXXXX) addEventHandler ["hit",{(_this select 0) setDamage 0}]XXXXXX = the object ID
And if you want the house to be destructable later on in the mission, declare a global variable like THobson suggested and add it in the eventHandler:
(object XXXXXX) addEventHandler ["hit",{if (!(okToDestroy)) then {(_this select 0) setDamage 0};}]or
(object XXXXXX) addEventHandler ["hit",{if (okToDestroy) then {(_this select 0) removeAllEventHandlers "hit"} else {(_this select 0) setDamage 0};}]
Tested the first example with satchel charges (several set off simulatneously), the other two examples untested..
-
The good old event handler strikes again. :)