Jump to content

Recommended Posts

Posted

Is it possible to set a parameter that essentially "rolls dice" to cause a missile to fail when fired by a player? My goal is to model a % chance that a missile fired will simply not guide.

I've looked up how to use the "Set Failure" trigger but in the few tutorials that exist, I am told to select a system from a drop down menu. However when I do so in the Editor, my list is empty and there is no field to select a specific unit to which to apply this failure. 

I could have sworn I've seen server messages in the "Just Dogfight" server that state "missile fired by XX: chances of failure = 50%" or something akin to that.

Posted (edited)
7 hours ago, SgtPappy said:

Is it possible to set a parameter that essentially "rolls dice" to cause a missile to fail when fired by a player? My goal is to model a % chance that a missile fired will simply not guide.

A work-around would be to create a script - when the missile fires, roll the dice, and when you are unlucky, simply delete the missile. Something along these lines:

simFail = {}
simFail.failPercent = 10 / 100 -- 10 percent 

function simFail:onEvent(event)
	local ID = event.id
	if ID ~= 1 then return end -- not a 'shot' event. ignore 
	local theUnit = event.initiator
	if not theUnit then return end -- no initiator. ignored. 
	
	local playerName = theUnit:getPlayerName() -- nil if not a player
	if not playerName then return end -- not fired by player 
	
	local theWeapon = event.weapon 
	if not theWeapon then return end -- not interesting. bye! 
	
	local theTarget = theWeapon:getTarget()
	if not theTarget then return end -- not a guided missiled. See ya!
	
	-- if we get here, a player launched a guided weapon at a target.
	-- set's assume that was a missile 
	-- roll the dice 
	p = math.random() 
	if p < simFail.failPercent then 
		-- missile failed 
		theWeapon:destroy()
		trigger.action.outText("Missile fired by " .. playerName .. " failed", 30)
	end

end

-- connect the code to dcs 
world.addEventHandler(simFail)

 

Edited by cfrag
  • Like 1
  • Thanks 1
Posted
9 hours ago, cfrag said:

A work-around would be to create a script - when the missile fires, roll the dice, and when you are unlucky, simply delete the missile. Something along these lines:

simFail = {}
simFail.failPercent = 10 / 100 -- 10 percent 

function simFail:onEvent(event)
	local ID = event.id
	if ID ~= 1 then return end -- not a 'shot' event. ignore 
	local theUnit = event.initiator
	if not theUnit then return end -- no initiator. ignored. 
	
	local playerName = theUnit:getPlayerName() -- nil if not a player
	if not playerName then return end -- not fired by player 
	
	local theWeapon = event.weapon 
	if not theWeapon then return end -- not interesting. bye! 
	
	local theTarget = theWeapon:getTarget()
	if not theTarget then return end -- not a guided missiled. See ya!
	
	-- if we get here, a player launched a guided weapon at a target.
	-- set's assume that was a missile 
	-- roll the dice 
	p = math.random() 
	if p < simFail.failPercent then 
		-- missile failed 
		theWeapon:destroy()
		trigger.action.outText("Missile fired by " .. playerName .. " failed", 30)
	end

end

-- connect the code to dcs 
world.addEventHandler(simFail)

 

 

Thank you! So it looks like I will have to get into scripting. I wonder if the empty drop down list in the default trigger is a bug.

  • Recently Browsing   0 members

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