Jump to content

Script explosion at sea level


BFQ

Recommended Posts

I'm trying to simulate a "Depth charge" dropped from a helicopter (via the F10 menu) with an explosion on the surface of the sea.

 

Three questions:

 

1. How do I make the explosion at the helicopters position, but at sea level?

 

I know it is not this way:

 

do
local pelican42_vector = Unit.getByName('Pelican 4-2'):getPosition().p
trigger.action.explosion(pelican42_vector, 10 )
end

 

That will make the "Depth charge" explode inside the helicopter :-)

 

2. Is it possible to delay the explosion with approx. 10 sec?

 

3. How do I check if the "Depth charge" was dropped within a trigger zone?

Link to comment
Share on other sites

1. Insert this line after you define the value but before you explode it.

pelican42_vector.y = 0

 

2. To delay you have to schedule a function that will create an explosion. Either directly like below or another function that you create that calls the trigger.action.explosion.

 

timer.scheduleFunction(trigger.action.explosion, {pelican42_vector, 10}, timer.getTime() + 10)

 

3. Math! With the formula ((A.x - B.x)^2 + (A.z - B.z)^2)^0.5 and checking if that value is less than the radius. In other words.

 

local dZone= trigger.misc.getZone('dCharge')

if ((pelican42_vector.x - dZone.x)^2 + (pelican42_vector .z - dZone.z)^2)^0.5 < dZone.radius then

-- it is in the zone.

end

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

Its already position.

 

local pelican42_vector = Unit.getByName('Pelican 4-2'):getPosition()[b].p[/b]

The right man in the wrong place makes all the difference in the world.

Current Projects:  Grayflag ServerScripting Wiki

Useful Links: Mission Scripting Tools MIST-(GitHub) MIST-(Thread)

 SLMOD, Wiki wishlist, Mission Editing Wiki!, Mission Building Forum

Link to comment
Share on other sites

1. Insert this line after you define the value but before you explode it.

pelican42_vector.y = 0

 

2. To delay you have to schedule a function that will create an explosion. Either directly like below or another function that you create that calls the trigger.action.explosion.

 

timer.scheduleFunction(trigger.action.explosion, {pelican42_vector, 10}, timer.getTime() + 10)

 

3. Math! With the formula ((A.x - B.x)^2 + (A.z - B.z)^2)^0.5 and checking if that value is less than the radius. In other words.

 

local dZone= trigger.misc.getZone('dCharge')

if ((pelican42_vector.x - dZone.x)^2 + (pelican42_vector .z - dZone.z)^2)^0.5 < dZone.radius then

-- it is in the zone.

end

 

Thank you very much! You are a hero!

 

Works perfect :-)

Link to comment
Share on other sites

  • 2 months later...

Hey guys, great idea OP!

 

I'm trying to make it work with a scheduled delay to no avail. If I use trigger.action.explosion everything's fine, but as soon as I try to schedule it with timer.scheduleFunction or mist.scheduleFunction, nothing happens (no errors).

 

Anyone know what's happening here?

 

function Ped1()

if trigger.misc.getUserFlag(311) == 1 then

	local Pedro1 = Unit.getByName('ROT PEDRO 1')
	local Pedro1ID = Unit.getByName('ROT PEDRO 1'):getID()
	Ped1Pos = Pedro1:getPosition().p
	Ped1Pos.y = 0
	
	trigger.action.setUserFlag( 301, false )
	timer.scheduleFunction( trigger.action.explosion, { Ped1Pos , 100 } , timer.getTime() + 10 )
	--trigger.action.explosion( Ped1Pos , 100 )
	--mist.scheduleFuntion( trigger.action.explosion, {Ped1Pos,100}, timer.getTime() + 1, 10, 1 )
	
end
		
end

 

Also, I can't get outTextForGroup to work...are the group level functions still broken?

Link to comment
Share on other sites

local function Explosion(Ped1Pos)
  
  local Expl_vec3 = { x = Ped1Pos.x , y = 0 , z = Ped1Pos.z }
  trigger.action.explosion(Expl_vec3 , 100)
end


function Ped1()
 
 if trigger.misc.getUserFlag("311") == 1 and Unit.getByName('ROT PEDRO 1') then
 
   local Pedro1 = Unit.getByName('ROT PEDRO 1')
   local Ped1Pos = Pedro1:getPosition().p
   
   timer.scheduleFunction( Explosion, Ped1Pos , timer.getTime() + 10 )
   
   trigger.action.setUserFlag( "301", false )
 end
end

Link to comment
Share on other sites

Thanks Hardcard, for my education, is there a reason you can't use the raw function and arguments in the scheduleFunction?

 

EDIT: Also nevermind on the outTextForGroup question...I was using Unit.getByName():getID() instead of Group.getByName():getID()


Edited by johnv2pt0
Link to comment
Share on other sites

is there a reason you can't use the raw function and arguments in the scheduleFunction?

 

That's a question for Grimes ;)

 

I only know what works (or doesn't) based on trial and error, not intimate knowledge of the workings of the DCS scripting engine.

 

Also, the functions I schedule most of the time are too long to "compress" in a single scheduler line, so writing a separate function above the scheduler is always the best option for me (I'm a big fan of code readabililty).

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...