Home   Help Search Login Register  

Author Topic: dont allow buildings to be destroyed  (Read 2113 times)

0 Members and 1 Guest are viewing this topic.

Offline jphilapy

  • Members
  • *
  • I'm a llama!
dont allow buildings to be destroyed
« on: 27 Jan 2006, 12:41:28 »
Is there anyway to prevent a destructible building from being destroyed?

Thanks,
Jeff

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:dont allow buildings to be destroyed
« Reply #1 on: 27 Jan 2006, 13:44:27 »
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.
Plenty of reviewed ArmA missions for you to play

Offline Platoon Patton

  • Members
  • *
  • "Barbecue" CreateVehicle getpos LLama
Re:dont allow buildings to be destroyed
« Reply #2 on: 27 Jan 2006, 21:43:53 »
This addEventHandler ["hit", {(_this select 0)setdammage 0}]
« Last Edit: 27 Jan 2006, 21:44:51 by Platoon Patton »
http://www.platoon-clan.com/ We always wellcome dedicated OFP players :)

http://www.european-combat-league.com/index.php To play with us in the best OFP league ;)

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:dont allow buildings to be destroyed
« Reply #3 on: 27 Jan 2006, 22:32:33 »
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
« Last Edit: 27 Jan 2006, 22:32:43 by THobson »

Offline jphilapy

  • Members
  • *
  • I'm a llama!
Re:dont allow buildings to be destroyed
« Reply #4 on: 28 Jan 2006, 00:32:39 »
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.
Code: [Select]
;indestruct.sqs
_obj = _this select 0;

#start
_obj setdammage 0;
goto "start"
Thanks for your replies,
Jeff

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:dont allow buildings to be destroyed
« Reply #5 on: 28 Jan 2006, 02:54:15 »
Isn't that going to be greedy?
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline jphilapy

  • Members
  • *
  • I'm a llama!
Re:dont allow buildings to be destroyed
« Reply #6 on: 28 Jan 2006, 03:08:46 »
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
« Last Edit: 28 Jan 2006, 03:11:30 by jphilapy »

Offline jphilapy

  • Members
  • *
  • I'm a llama!
Re:dont allow buildings to be destroyed
« Reply #7 on: 28 Jan 2006, 03:32:04 »
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:

Code: [Select]
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:
Code: [Select]
_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:

Code: [Select]
_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



Offline XCess

  • Former Staff
  • ****
Re:dont allow buildings to be destroyed
« Reply #8 on: 28 Jan 2006, 10:11:57 »
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.
« Last Edit: 28 Jan 2006, 10:12:19 by XCess »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:dont allow buildings to be destroyed
« Reply #9 on: 28 Jan 2006, 10:30:13 »
Try this - or something similar:
Code: [Select]
;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:

Code: [Select]
;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.
« Last Edit: 28 Jan 2006, 10:49:29 by THobson »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:dont allow buildings to be destroyed
« Reply #10 on: 28 Jan 2006, 12:13:34 »
*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:

Code: [Select]
(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:
Code: [Select]
(object XXXXXX) addEventHandler ["hit",{if (!(okToDestroy)) then {(_this select 0) setDamage 0};}]or
Code: [Select]
(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..
« Last Edit: 28 Jan 2006, 12:14:45 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:dont allow buildings to be destroyed
« Reply #11 on: 28 Jan 2006, 13:35:42 »
The good old event handler strikes again. :)