I'm not sure if you found your answer yet since you haven't indicated it has been solved. The breaking of an object is already covered. However, you can also use an exploding barrel. After hitting/shooting it 10 times it will explode. What you can do is place an object within or under the barrel. Here is the script to assign to the barrel to hit 10 times.
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
gamedata = {}
local state = 0
local start = 0
local eHealth = 0
local eNumHits = 0
function test_init(e)
start = 1
eHealth = g_Entity[e]['health']
end
function test_main(e)
if start == 1 then
start = 0
-- start code goes here that runs only once
state = 1
else
if state == 1 then
--code for state 1 goes here
if g_Entity[e]['health'] < eHealth then
eHealth = g_Entity[e]['health']
eNumHits = eNumHits + 1
end
PromptLocal(e,"Number of Hits = " .. eNumHits)
--Prompt("entity health = " .. g_Entity[e]['health'] .. " and num hits = " .. eNumHits )
if eNumHits == 10 then
SetEntityHealth(e,0) --setting the health to 0 will cause the barrel to explode as long as it is explodable
state = 2
end
elseif state == 2 then
--code for state 2 goes here
elseif state == 3 then
--code for state 3 goes here
elseif state == 4 then
--code for state 4 goes here
end
end
end
When you place the barrel on the map use the highlighted properties. Make sure the strength (health of object) is large enough that it will not explode too soon. Either set IsImmobile or Physics On ? to "no". Both set to "no" is not required. Then make sure that Explodable is set to "yes".
The health pack in the barrel can be spawned but you don't want to take a chance that the player will tip over the barrel. If you allow the player to tip over the barrel then make sure and do not spawn the object at start and use activateifused after the barrel is exploded (after the tenth hit).
if eNumHits == 10 then
ActivateIfUsed(e)
SetEntityHealth(e,0)
state = 2
There is one other thing, if you tip over the barrel and it starts rolling then the health pack will not go with it. AmenMoses has created the ability to attach an entity to aother entity. The only thing I'm not sure of is if a non-spawned entity can be attached to a spawned entity. The simple fpm for this is attached and the video follows.
Alienware Aurora R7 with SSD 256GB boot drive ( C: ) and a secondary drive ( D: ) that is 2TB
Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz 3.19 with Intel Turbo-burst
Installed RAM 16.0 GB
64-bit operating system, x64-based processor
Windows 10 Home
NVIDIA GeForce GTX 1070 with 8192 MB GDDR5 and 8095 MB shared system memory