Jump to content

Runway Damage


Recommended Posts

20 minutes ago, ElementLT said:

yes PLEASE! 🙂 I am currently working on my next multiplayer server development now and this would be a great addition! Thank you for your hard work sir! 

function CheckBase(Check, time) -- Damage runway

	local base = Airbase.getByName(Check):getLife() -- Check the airbase's life
	
	if base < 3600 and base >= 3240 then
		trigger.action.setUserFlag("100", 1)		
		trigger.action.outText(Check .. " is 10% damage", 60, true)
      	return time + 25
	
	elseif base < 3240 and base >= 2880 then
		trigger.action.setUserFlag("100", 2)
      	trigger.action.outText(Check .. " is 20% damage", 60, true)
		return time + 25
			
	elseif base < 2880 and base >= 2520 then
		trigger.action.setUserFlag("100", 3)
      	trigger.action.outText(Check .. " is 30% damage", 60, true)
		return time + 25
	
	elseif base < 2520 and base >= 2160 then
		trigger.action.setUserFlag("100", 4)
      	trigger.action.outText(Check .. " is 40% damage", 60, true)
		return time + 25
		
	elseif base < 2160 and base >= 1800 then
		trigger.action.setUserFlag("100", 5)
      	trigger.action.outText(Check .. " is 50% damage", 60, true)
		return time + 25
		
	elseif base < 1800 and base >= 1440 then
		trigger.action.setUserFlag("100", 6)
      	trigger.action.outText(Check .. " is 60% damage", 60, true)
		return time + 25
	
	elseif base < 1440 and base >= 1080 then
		trigger.action.setUserFlag("100", 7)
      	trigger.action.outText(Check .. " is 70% damage", 60, true)
		return time + 25
	
	elseif base < 1080 and base >= 720 then
		trigger.action.setUserFlag("100", 8)
      	trigger.action.outText(Check .. " is 80% damage", 60, true)
		return time + 25		
	
	elseif base < 720 and base >= 360 then
		trigger.action.setUserFlag("100", 9)
     	trigger.action.outText(Check .. " is 90% damage", 60, true)
		return time + 25
	
	elseif base < 360 then
		trigger.action.setUserFlag("100", 10)
      	trigger.action.outText(Check .. " is more then 90% damage", 60, true)
		return nil
	
	else
		return time + 300
		
	end
end

function morte(morto)
	trigger.action.setUserFlag("100", 11)
   	trigger.action.outText(morto .. " is destroyed", 60, true)
	
end
                     
local Event_Handler = {}

function Event_Handler:onEvent(Event)
		
	if Event.id == 1 then -- Shot		
		local aviao = Event.initiator:getName()
		local WeaponShoot = Event.weapon:getTypeName() 
		if aviao == "Player" then
			if WeaponShoot ~= "AIM-54C" and WeaponShoot ~= "AIM-7M" and WeaponShoot ~= "AIM-54A-MK" and WeaponShoot ~= "AIM-9M" then				
				if WeaponShoot ~= "AIM-120C" and WeaponShoot ~= "AIM-120B" and WeaponShoot ~= "AIM-9L" then
					if WeaponShoot ~= "weapons.missiles.AIM-7MH" and WeaponShoot ~= "AIM-9X" and WeaponShoot ~= "weapons.missiles.AIM-7F" and WeaponShoot ~= "weapons.missiles.AIM_7" then
						timer.scheduleFunction(CheckBase, "Sirri Island",timer.getTime() + 30)
		
					end
				end
			end
		end
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- dead

		local InitiatorObject = Event.initiator
		local InitiatorName = InitiatorObject:getName()
		local InitiatorCategory = InitiatorObject:getCategory()

		if InitiatorName == "Sirri Island" and InitiatorCategory == 4 then
			timer.scheduleFunction(morte, "Sirri Island",timer.getTime() + 30)
			
		end	
	end	
end

world.addEventHandler(Event_Handler)

Hi,

 

If you have any doubt, just send me a message.

 

Best regards

  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Bruce_D said:

function CheckBase(Check, time) -- Damage runway

	local base = Airbase.getByName(Check):getLife() -- Check the airbase's life
	
	if base < 3600 and base >= 3240 then
		trigger.action.setUserFlag("100", 1)		
		trigger.action.outText(Check .. " is 10% damage", 60, true)
      	return time + 25
	
	elseif base < 3240 and base >= 2880 then
		trigger.action.setUserFlag("100", 2)
      	trigger.action.outText(Check .. " is 20% damage", 60, true)
		return time + 25
			
	elseif base < 2880 and base >= 2520 then
		trigger.action.setUserFlag("100", 3)
      	trigger.action.outText(Check .. " is 30% damage", 60, true)
		return time + 25
	
	elseif base < 2520 and base >= 2160 then
		trigger.action.setUserFlag("100", 4)
      	trigger.action.outText(Check .. " is 40% damage", 60, true)
		return time + 25
		
	elseif base < 2160 and base >= 1800 then
		trigger.action.setUserFlag("100", 5)
      	trigger.action.outText(Check .. " is 50% damage", 60, true)
		return time + 25
		
	elseif base < 1800 and base >= 1440 then
		trigger.action.setUserFlag("100", 6)
      	trigger.action.outText(Check .. " is 60% damage", 60, true)
		return time + 25
	
	elseif base < 1440 and base >= 1080 then
		trigger.action.setUserFlag("100", 7)
      	trigger.action.outText(Check .. " is 70% damage", 60, true)
		return time + 25
	
	elseif base < 1080 and base >= 720 then
		trigger.action.setUserFlag("100", 8)
      	trigger.action.outText(Check .. " is 80% damage", 60, true)
		return time + 25		
	
	elseif base < 720 and base >= 360 then
		trigger.action.setUserFlag("100", 9)
     	trigger.action.outText(Check .. " is 90% damage", 60, true)
		return time + 25
	
	elseif base < 360 then
		trigger.action.setUserFlag("100", 10)
      	trigger.action.outText(Check .. " is more then 90% damage", 60, true)
		return nil
	
	else
		return time + 300
		
	end
end

function morte(morto)
	trigger.action.setUserFlag("100", 11)
   	trigger.action.outText(morto .. " is destroyed", 60, true)
	
end
                     
local Event_Handler = {}

function Event_Handler:onEvent(Event)
		
	if Event.id == 1 then -- Shot		
		local aviao = Event.initiator:getName()
		local WeaponShoot = Event.weapon:getTypeName() 
		if aviao == "Player" then
			if WeaponShoot ~= "AIM-54C" and WeaponShoot ~= "AIM-7M" and WeaponShoot ~= "AIM-54A-MK" and WeaponShoot ~= "AIM-9M" then				
				if WeaponShoot ~= "AIM-120C" and WeaponShoot ~= "AIM-120B" and WeaponShoot ~= "AIM-9L" then
					if WeaponShoot ~= "weapons.missiles.AIM-7MH" and WeaponShoot ~= "AIM-9X" and WeaponShoot ~= "weapons.missiles.AIM-7F" and WeaponShoot ~= "weapons.missiles.AIM_7" then
						timer.scheduleFunction(CheckBase, "Sirri Island",timer.getTime() + 30)
		
					end
				end
			end
		end
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- dead

		local InitiatorObject = Event.initiator
		local InitiatorName = InitiatorObject:getName()
		local InitiatorCategory = InitiatorObject:getCategory()

		if InitiatorName == "Sirri Island" and InitiatorCategory == 4 then
			timer.scheduleFunction(morte, "Sirri Island",timer.getTime() + 30)
			
		end	
	end	
end

world.addEventHandler(Event_Handler)

Hi,

 

If you have any doubt, just send me a message.

 

Best regards

Thank you so much this is going to be so useful

The Fraternity: Georgia Reign Multiplayer Server
Dynamic Multiplayer PVE Server - 24/7

Georgia Reign Server: 69.30.198.74:10308 ★ SRS: SRS: 69.30.198.74:5002
FOR LIVE INTERACTIVE MAP & LIVE STATS: https://thefraternitysim.com/

Link to comment
Share on other sites

Hi,

 

With this version you can use the function to every base and FARP on the map (it works for every map):

 

nome = {} -- nome das bases incluso FARP
idNome = {} -- ID das bases incluso FARP
local baseaerea = world.getAirbases() -- todas as bases incluso FARP

for a, b in pairs(baseaerea) do 
	if b:getCategory() == 4 then
		idNome[#idNome+1] = tostring(b:getID())
		nome[#nome+1] = b:getName()
	end	
end

function CheckBase(Check, time) -- Pista danificada
	-- Check[1] = Nome da base aérea
	-- Check[2] = Flag
	
	local base = Airbase.getByName(Check[1]):getLife() -- Verifica a vida da base
	
	if base < 3600 and base >= 3240 then
		trigger.action.setUserFlag(Check[2], 1)		
		return time + 25
	
	elseif base < 3240 and base >= 2880 then
		trigger.action.setUserFlag(Check[2], 2)		
		return time + 25
			
	elseif base < 2880 and base >= 2520 then
		trigger.action.setUserFlag(Check[2], 3)		
		return time + 25
	
	elseif base < 2520 and base >= 2160 then
		trigger.action.setUserFlag(Check[2], 4)		
		return time + 25
		
	elseif base < 2160 and base >= 1800 then
		trigger.action.setUserFlag(Check[2], 5)		
		return time + 25
		
	elseif base < 1800 and base >= 1440 then
		trigger.action.setUserFlag(Check[2], 6)		
		return time + 25
	
	elseif base < 1440 and base >= 1080 then
		trigger.action.setUserFlag(Check[2], 7)		
		return time + 25
	
	elseif base < 1080 and base >= 720 then
		trigger.action.setUserFlag(Check[2], 8)		
		return time + 25		
	
	elseif base < 720 and base >= 360 then
		trigger.action.setUserFlag(Check[2], 9)
		return time + 25
	
	elseif base < 360 then
		trigger.action.setUserFlag(Check[2], 10)		
		return nil
	
	else
		return time + 300
		
	end
end

function morte(morto)
	trigger.action.setUserFlag(morto, 11)	
	
end

local Event_Handler = {}

function Event_Handler:onEvent(Event)
	
	if Event.id == 1 then -- disparo		
		local arma = Event.weapon:getTypeName()		
			if arma ~= "AIM-54C" and arma ~= "AIM-7M" and arma ~= "AIM-54A-MK" and arma ~= "AIM-9M" then				
				if arma ~= "AIM-120C" and arma ~= "AIM-120B" and arma ~= "AIM-9L" then
					if arma ~= "weapons.missiles.AIM-7MH" and arma ~= "AIM-9X" and arma ~= "weapons.missiles.AIM-7F" and arma ~= "weapons.missiles.AIM_7" then
						
						for c, d in pairs(nome) do
							local detalhes = {}
														
							detalhes = {
								nome[c],
								idNome[c]
							}
							
							timer.scheduleFunction(CheckBase, detalhes,timer.getTime() + 30)
							
						end
					end
				end
			end
		
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- morto

		local objeto = Event.initiator
		local pista = objeto:getName()
		local categoria = objeto:getCategory()

		if categoria == 4 then
			
			for e, f in pairs(nome) do
				
				if f == pista then
					local identidade = ""
					identidade = idNome[e]
					
					timer.scheduleFunction(morte, identidade,timer.getTime() + 30)
				
				end
			end
		end				
	end	
end

world.addEventHandler(Event_Handler)

 

The number of the flag is the ID for the base or FARP.

 

To discover this ID use the following code:

 

local baseaerea2 = world.getAirbases()
local teste = {}

for a, b in pairs(baseaerea2) do 
	if b:getCategory() == 4 then
		teste[#teste+1] = "\n ID: " .. b:getID() .. " / Name: " .. b:getName()
	end	
end

trigger.action.outText(table.concat(teste), 60)

 

Hope that I could Help.

 

If somebody could test it, I would appreciate.

 

tks


Edited by Bruce_D
  • Thanks 1
Link to comment
Share on other sites

Hi,

 

I did an improvement for the function:

 

nome = {} -- nome das bases incluso FARP
idNome = {} -- ID das bases incluso FARP
local baseaerea = world.getAirbases() -- todas as bases incluso FARP

for a, b in pairs(baseaerea) do 
	if b:getCategory() == 4 then
		idNome[#idNome+1] = tostring(b:getID())
		nome[#nome+1] = b:getName()
	end	
end

function CheckBase(Check, time) -- Pista danificada
	-- Check[1] = Nome da base aérea
	-- Check[2] = Flag
	
	local base = Airbase.getByName(Check[1]):getLife() -- Verifica a vida da base
	
	local function arredondar(x, n)
		n = math.pow(10, n or 0)
		x = x * n
		if x >= 0 then
			x = math.floor(x + 0.5)

		else
			x = math.ceil(x - 0.5)
		
		end
			return x / n
	end
	
	
	if base < 3600 and base >= 1 then
		local num = base/3600
		local numfinal = (1 - arredondar(num, 1))*10
		
		if numfinal == 10 then
			trigger.action.setUserFlag(Check[2], numfinal)			
			return nil
		
		else
			trigger.action.setUserFlag(Check[2], numfinal)			
			return time + 25
		
		end	
	
	else
		return nil
		
	end
end

function morte(morto)
	trigger.action.setUserFlag(morto, 11)	
	
end

local Event_Handler = {}

function Event_Handler:onEvent(Event)
	
	if Event.id == 1 then -- disparo		
		local arma = Event.weapon:getTypeName()		
			if arma ~= "AIM-54C" and arma ~= "AIM-7M" and arma ~= "AIM-54A-MK" and arma ~= "AIM-9M" then				
				if arma ~= "AIM-120C" and arma ~= "AIM-120B" and arma ~= "AIM-9L" then
					if arma ~= "weapons.missiles.AIM-7MH" and arma ~= "AIM-9X" and arma ~= "weapons.missiles.AIM-7F" and arma ~= "weapons.missiles.AIM_7" then
						
						for c, d in pairs(nome) do
							local detalhes = {}
							
							detalhes = {
								nome[c],
								idNome[c]
							}
							
							timer.scheduleFunction(CheckBase, detalhes,timer.getTime() + 30)
							
						end
					end
				end
			end
		
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- morto

		local objeto = Event.initiator
		local pista = objeto:getName()
		local categoria = objeto:getCategory()

		if categoria == 4 then
			
			for e, f in pairs(nome) do
				
				if f == pista then
					local identidade = ""
					identidade = idNome[e]
					
					timer.scheduleFunction(morte, identidade,timer.getTime() + 30)
				
				end
			end
		end				
	end	
end
      
world.addEventHandler(Event_Handler)

 

The number of the flag is the ID for the base or FARP.

 

The flag value goes from 1 to 10 and represents the percentage of the damage on the runway.

 

Example: if the runway receives a 10% damage the flag value is 1. If the damage is 84% the flag value is 8 and so on.

 

To discover the base's ID use the following code:

 

local baseaerea2 = world.getAirbases()
local teste = {}

for a, b in pairs(baseaerea2) do 
	if b:getCategory() == 4 then
		teste[#teste+1] = "\n ID: " .. b:getID() .. " / Name: " .. b:getName()
	end	
end

trigger.action.outText(table.concat(teste), 60)

 

If somebody could test it, I would appreciate.

 

tks


Edited by Bruce_D
Link to comment
Share on other sites

9 hours ago, Bruce_D said:

Hi,

 

I did an improvement for the function:

 


nome = {} -- nome das bases incluso FARP
idNome = {} -- ID das bases incluso FARP
local baseaerea = world.getAirbases() -- todas as bases incluso FARP

for a, b in pairs(baseaerea) do 
	if b:getCategory() == 4 then
		idNome[#idNome+1] = tostring(b:getID())
		nome[#nome+1] = b:getName()
	end	
end

function CheckBase(Check, time) -- Pista danificada
	-- Check[1] = Nome da base aérea
	-- Check[2] = Flag
	
	local base = Airbase.getByName(Check[1]):getLife() -- Verifica a vida da base
	
	local function arredondar(x, n)
		n = math.pow(10, n or 0)
		x = x * n
		if x >= 0 then
			x = math.floor(x + 0.5)

		else
			x = math.ceil(x - 0.5)
		
		end
			return x / n
	end
	
	
	if base < 3600 and base >= 1 then
		local num = base/3600
		local numfinal = (1 - arredondar(num, 1))*10
		
		if numfinal == 10 then
			trigger.action.setUserFlag(Check[2], numfinal)			
			return nil
		
		else
			trigger.action.setUserFlag(Check[2], numfinal)			
			return time + 25
		
		end	
	
	else
		return nil
		
	end
end

function morte(morto)
	trigger.action.setUserFlag(morto, 11)	
	
end

local Event_Handler = {}

function Event_Handler:onEvent(Event)
	
	if Event.id == 1 then -- disparo		
		local arma = Event.weapon:getTypeName()		
			if arma ~= "AIM-54C" and arma ~= "AIM-7M" and arma ~= "AIM-54A-MK" and arma ~= "AIM-9M" then				
				if arma ~= "AIM-120C" and arma ~= "AIM-120B" and arma ~= "AIM-9L" then
					if arma ~= "weapons.missiles.AIM-7MH" and arma ~= "AIM-9X" and arma ~= "weapons.missiles.AIM-7F" and arma ~= "weapons.missiles.AIM_7" then
						
						for c, d in pairs(nome) do
							local detalhes = {}
							
							detalhes = {
								nome[c],
								idNome[c]
							}
							
							timer.scheduleFunction(CheckBase, detalhes,timer.getTime() + 30)
							
						end
					end
				end
			end
		
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- morto

		local objeto = Event.initiator
		local pista = objeto:getName()
		local categoria = objeto:getCategory()

		if categoria == 4 then
			
			for e, f in pairs(nome) do
				
				if f == pista then
					local identidade = ""
					identidade = idNome[e]
					
					timer.scheduleFunction(morte, identidade,timer.getTime() + 30)
				
				end
			end
		end				
	end	
end
      
world.addEventHandler(Event_Handler)

 

The number of the flag is the ID for the base or FARP.

 

The flag value goes from 1 to 10 and represents the percentage of the damage on the runway.

 

Example: if the runway receives a 10% damage the flag value is 1. If the damage is 84% the flag value is 8 and so on.

 

To discover the base's ID use the following code:

 


local baseaerea2 = world.getAirbases()
local teste = {}

for a, b in pairs(baseaerea2) do 
	if b:getCategory() == 4 then
		teste[#teste+1] = "\n ID: " .. b:getID() .. " / Name: " .. b:getName()
	end	
end

trigger.action.outText(table.concat(teste), 60)

 

If somebody could test it, I would appreciate.

 

tks

 

Hi,

 

I've found a bug. Here is the correction:

 

nome = {} -- nome das bases incluso FARP
idNome = {} -- ID das bases incluso FARP
local baseaerea = world.getAirbases() -- todas as bases incluso FARP

for a, b in pairs(baseaerea) do 
	if b:getCategory() == 4 then
		idNome[#idNome+1] = tostring(b:getID())
		nome[#nome+1] = b:getName()
	end	
end

function CheckBase(Check, time) -- Pista danificada
	-- Check[1] = Nome da base aérea
	-- Check[2] = Flag
	if trigger.misc.getUserFlag(Check[2]) == 11 then
		return nil
		
	else	
		local base = Airbase.getByName(Check[1]):getLife() -- Verifica a vida da base
	
		local function arredondar(x, n)
			n = math.pow(10, n or 0)
			x = x * n
			if x >= 0 then
				x = math.floor(x + 0.5)

			else
				x = math.ceil(x - 0.5)
		
			end
				return x / n
		end
		
		if base < 3600 and base >= 1 then
			local num = base/3600
			local numfinal = (1 - arredondar(num, 1))*10
		
			if numfinal == 10 then
				trigger.action.setUserFlag(Check[2], numfinal)			
				return nil
		
			else
				trigger.action.setUserFlag(Check[2], numfinal)			
				return time + 25
		
			end	
	
		else
			return nil
		
		end
	end
end

function morte(morto)
	trigger.action.setUserFlag(morto, 11)	
	
end

local Event_Handler = {}

function Event_Handler:onEvent(Event)
	
	if Event.id == 1 then -- disparo		
		local arma = Event.weapon:getTypeName()		
			if arma ~= "AIM-54C" and arma ~= "AIM-7M" and arma ~= "AIM-54A-MK" and arma ~= "AIM-9M" then				
				if arma ~= "AIM-120C" and arma ~= "AIM-120B" and arma ~= "AIM-9L" then
					if arma ~= "weapons.missiles.AIM-7MH" and arma ~= "AIM-9X" and arma ~= "weapons.missiles.AIM-7F" and arma ~= "weapons.missiles.AIM_7" then
						
						for c, d in pairs(nome) do
							local detalhes = {}
							
							detalhes = {
								nome[c],
								idNome[c]
							}
							
							timer.scheduleFunction(CheckBase, detalhes,timer.getTime() + 30)
							
						end
					end
				end
			end
		
	
	elseif Event.id == 8 and Event.initiator ~= nil then -- morto

		local objeto = Event.initiator
		local pista = objeto:getName()
		local categoria = objeto:getCategory()

		if categoria == 4 then
			
			for e, f in pairs(nome) do
				
				if f == pista then
					local identidade = ""
					identidade = idNome[e]
					
					timer.scheduleFunction(morte, identidade,timer.getTime() + 30)
				
				end
			end
		end				
	end	
end

world.addEventHandler(Event_Handler)

 

Tks

  • Like 1
  • Thanks 3
Link to comment
Share on other sites

Tested at a few airbases in Caucaso: it works very well, thank you very much!

 

Just a little add for my problem, a trigger (switched condition):
Condition: FLAG IS TRUE (18) -- ID of the request airbase/FARP in this case Sochi-Adler
Action: DO SCRIPT  local sochidamage = trigger.misc.getUserFlag("18")
                                  local msg = string.format("Runway damaged at %i %s", sochidamage*10, "%")
                                  trigger.action.outText(msg, 10,true)

             FLAG OFF (18)

 

 

  • Like 1
  • Thanks 1

Brontolo VIAF

Link to comment
Share on other sites

2 hours ago, brontolo said:

Tested at a few airbases in Caucaso: it works very well, thank you very much!

 

Just a little add for my problem, a trigger (switched condition):
Condition: FLAG IS TRUE (18) -- ID of the request airbase/FARP in this case Sochi-Adler
Action: DO SCRIPT  local sochidamage = trigger.misc.getUserFlag("18")
                                  local msg = string.format("Runway damaged at %i %s", sochidamage*10, "%")
                                  trigger.action.outText(msg, 10,true)

             FLAG OFF (18)

 

 

Hi,

 

And what error message are you receiving?

Link to comment
Share on other sites

  • 3 months later...
 Share

  • Recently Browsing   0 members

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