Jump to content

Recommended Posts

Posted (edited)

I'm trying to make a weapon loadout check script that is handled by S_EVENT_TAKEOFF.

 

The part of the script that should see that I have a restricted weapon type on board is not working though. I'm printing the weapon names to the log, so I know what they're called, but I'm missing something.

 

For reference, the aircraft unit name is "TIGER" and it has a Mk-84 and 2 GBU-12 onboard...for testing. It always outTexts the debug message "No problem with your loadout" so my conditional checks aren't correct.

 

Also, getAmmo doesn't seem to pick up targeting / ecm pods. Is there another api that can detect these?

 

Any help is appreciated.

 

--Ordnance Restriction Script --
env.setErrorMessageBoxEnabled(false)

clients = {

'WOLF',
'PIG', 
'BOAR', 
'COLT', 
'PONTIAC',
'TIGER', 
'THUNDER', 
'BISON', 
'ROOK', 
'FROG', 
'FLANKER', 
'FULCRUM',
'SHARK', 
'SHOOTER', 
'STING', 
'VENOM', 
'CAT', 
'DOG', 
'RAMPART', 
'SPIDER', 
'FANG', 
'HAMMER', 
'NASTY',
'HAWG',
'DRAGON',
'WANG'}

restrictedWeapons = {
'Mk-84',
'Mk_84',
'GBU-12',
}
---------------

ClientOrdnanceCheck = {}

function ClientOrdnanceCheck:onEvent(event)

if world.event.S_EVENT_TAKEOFF == event.id then

	local _player = event.initiator
	local _playerName = _player:getName()
		--env.info(_playerName)
		
	for j = 1, #clients do
		
		if _playerName:find(clients[j]) then
			
			local _playerLoadout = _player:getAmmo()
			
			for i = 1, #_playerLoadout do
			env.info(_playerLoadout[i].desc.typeName)
			env.info(_playerLoadout[i].desc.displayName)
			
							
				if _playerLoadout ~= nil then
				
					for k = 1, #restrictedWeapons do 
					
						if type(_playerLoadout) == 'string' and _playerLoadout:find(restrictedWeapons[k])  then
		
							trigger.action.outText("".._playerName.." you have an unauthorized loadout.  Please RTB and rearm.", 30)
			
						else
							trigger.action.outText("Debug--No problem with your loadout.",30)
							
						end
					end	
	
				end
			end
		end
	end
end
end
world.addEventHandler(ClientOrdnanceCheck)

env.info("Ordnance Restriction Script Loaded!")

Edited by johnv2pt0
Posted

getAmmo() returns a table and not a string, hence

_playerLoadout[i].desc.typeName

works and type(_playerLoadout) == 'string' returns false. The string match would have to be changed accordingly: not via find() but ...desc.typeName== restrictedWeapons[k].

  • Recently Browsing   0 members

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