Jump to content

on searchObjects: parameter #2 (function) missed


Recommended Posts

Posted (edited)

Hey there guys, I'm having troubles all day with this new function (for my knowledge)... Can anyone explain me what's wrong? 😞

local debug = false
local EventHandl = {}
local ParatroopObjType = {Object.Category.UNIT, Object.Category.STATIC, Object.Category.SCENERY, Object.Category.WEAPON}

Parat = {}
Parat.SelfOBJ = {}
Parat.EjectedBy = {}

PilotLives = {}

paraTroopID = 0

ParatroopSphereSrc = {
	id = world.VolumeType.SPHERE,
	params = {
			radius = 10.0,
	},
}

world.addEventHandler(EventHandl)
function EventHandl:onEvent(EventData)
	if EventData.id == world.event.S_EVENT_EJECTION then
		if EventData.initiator ~= nil and EventData.initiator:getPlayerName() ~= nil then
			local pName = EventData.initiator:getPlayerName()
			local ejSeatPos = EventData.target:getPosition().p

			ParatroopSphereSrc = {
				params = {
							point = ejSeatPos,
				},
			}
			--Find object paratroop
			world.searchObjects(ParatroopObjType, ParatroopSphereSrc, pObj) --error here, parameter #2 (function) missed

			local pPos = Parat.SelfOBJ[paraTroopID]:getPosition().p

			trigger.action.outText("(" .. paraTroopID .. ")" .. "Chute Spotted by " .. pName .. "Obj SELFID: " .. Parat.SelfOBJ[paraTroopID]:getID() .. "\nPosX: " .. pPos.x .. "\nPosY: " .. pPos.y .. "\nPosZ: " .. pPos.z, 5)
			Parat.SelfOBJ[paraTroopID] = EventData.target --Memo paratrooper unique mission ID

			Parat.EjectedBy[paraTroopID] = pName --Memo initiator name

			paraTroopID = paraTroopID + 1
		end
	end

	ParatroopSphereSrc = {
		params = {
					point = nil,
		},
	}
end

local pObj = function(foundItem, val) 
	Parat.SelfOBJ[paraTroopID] = foundItem:getID()
	return true
end

trigger.action.outText("Paratroopers Script loaded", 5)

 Thanks for help 🙂

Edited by DarK_FeneR996
Posted

The function that gets called by world.searchObjects needs to be defined above it in the code. So your function pObj needs to be placed somewhere above:  function EventHandl:onEvent(EventData). It basically doesn't know what pObj is at that point when the script is compiled. 

Also 

			ParatroopSphereSrc = {
				params = {
							point = ejSeatPos,
				},
			}

That code just redefines the entire table as that and you aren't just updating the point coordinate. To do that: ParatroopSphereSrc.params.point = ejSeatPos

 

I'm a little confused what you are trying to accomplish because it looks like you are trying to get the id of the ejected pilot seat by searching the area around it during the event. Which would likely return the aircraft they are in when the pilot ejected and possibly the ejected seat, but I don't think you'd actually get the seat because it isn't really a unit, static object, weapon, or scenery object. The more confusing part about all that is you already have the ejection seat by virtue of having access to the ejection seat in the form of EventData.target. You should be able to build that list via: EventData.target:getID()

But also because https://wiki.hoggitworld.com/view/DCS_event_discard_chair_after_ejection will occur sooner or later and the pilot in a parachute will detach from the chair. (Unless its a WW2 aircraft because the ejection event is all that occurs for them)

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

Posted (edited)
23 minutes ago, Grimes said:

The function that gets called by world.searchObjects needs to be defined above it in the code. So your function pObj needs to be placed somewhere above:  function EventHandl:onEvent(EventData). It basically doesn't know what pObj is at that point when the script is compiled. 

Also 

			ParatroopSphereSrc = {
				params = {
							point = ejSeatPos,
				},
			}

That code just redefines the entire table as that and you aren't just updating the point coordinate. To do that: ParatroopSphereSrc.params.point = ejSeatPos

 

I'm a little confused what you are trying to accomplish because it looks like you are trying to get the id of the ejected pilot seat by searching the area around it during the event. Which would likely return the aircraft they are in when the pilot ejected and possibly the ejected seat, but I don't think you'd actually get the seat because it isn't really a unit, static object, weapon, or scenery object. The more confusing part about all that is you already have the ejection seat by virtue of having access to the ejection seat in the form of EventData.target. You should be able to build that list via: EventData.target:getID()

But also because https://wiki.hoggitworld.com/view/DCS_event_discard_chair_after_ejection will occur sooner or later and the pilot in a parachute will detach from the chair. (Unless its a WW2 aircraft because the ejection event is all that occurs for them)

My intention is to find the EJECTED PILOT (not the chair). Using the CHAIR POS I wanna search for the EJECTED PILOT in that area. Once i get the pilot pos, I will use it to recover him with an heli, using a command near him

 

SADLY I don't know what category is the Paratrooper (ejected pilot)... I took a look some threads but nothing solved. Suggestions? I just need how to find the paratrooper (ejected pilot) and then, later, get his position for recover mission

 

EDIT:

S_EVENT_DISCARD_CHAIR_AFTER_EJECTION

I've just noticed this EVENT you mentioned (I missed it in the lists online) and seems it gets the pilot (paratrooper) position. Am I right?

Edited by DarK_FeneR996
Posted
20 minutes ago, DarK_FeneR996 said:
S_EVENT_DISCARD_CHAIR_AFTER_EJECTION

I've just noticed this EVENT you mentioned (I missed it in the lists online) and seems it gets the pilot (paratrooper) position. Am I right?

Since I, too don't know what you are trying to accomplish here - if you are after the pilot's location after ejection, maybe this event may also be of interest:

S_EVENT_LANDING_AFTER_EJECTION = 31,

If you revisit the "parashoo" example I pasted into a previous question, you'll see that that one comes with initiator (the parachutist). That script deletes the guy that parachuted after touching down.

 

 

Posted
5 hours ago, DarK_FeneR996 said:

My intention is to find the EJECTED PILOT (not the chair). Using the CHAIR POS I wanna search for the EJECTED PILOT in that area. Once i get the pilot pos, I will use it to recover him with an heli, using a command near him...

Several MEDEVAC scripts already exist, you can have a look at them.

Attached is an example with a script I wrote (nothing new, just reinventing a wheel I think). The script works with any (created in mission editor or spawned by script) ejected pilot(s) from any coalition that can be extracted by any transport helicopter of same coalition, AI or player/client, as long as heli has room aboard for them. (uses MIST functions)

In example attached a crew of 3 members ejects from a russian Il-78M, and a russian UH-1H AI does land and embark them before RTB.

You can run it as is, as spectator, or change Heli from AI to Player/Client to play the Medevac (as player/client you get a F10 MEDEVAC menu with coordinates data for every ejected pilot + possibility to ask for smoke on them, and pilots are removed from menu when rescued. When on land within 500 meters from pilots you can embark them with DCS usual radio "embarking" menu). You can also change the AI Il-78M for a Client aircraft that you control, eject yourself, and then take control of Heli Client to rescue yourself (MEDEVAC task for your previous pilot will be created when he is replaced by a soldier on the ground).

 

test-embark-ejected-pilots.miz

Posted

The different events occur in a given order and sometimes the object wouldn't exist the exact moment an event is called. With ejection there are two possibilities. 1. Target is the ejection seat. 2. Target is the ejected pilot. Simply put if the aircraft has an ejection seat then it'll be possibility 1. Then the additional event of discard chair after ejection will occur after a few seconds once below a certain altitude. That is when the ejected pilot object actually begins to exist. So with the altitude bit, if you eject above that altitude then the pilot will stay in the chair for a while to lose altitude before the parachute deploys. If the aircraft is without an ejection seat the pilot will bail out and deploy the chute immediately. With enough wind this can drift them quite a distance away.

 

The further caveat is that if the ejected pilot lands in water then the landing after ejection event simply doesn't fire. Nor does a dead event. It simply ceases to exist. 

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

  • Recently Browsing   0 members

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