Jump to content

Get (and set) static object position


Toumal

Recommended Posts

Hi,

I'm having trouble getting the position of a static object. I have created a static object in the editor but I cannot use function such as GetVec2().x and .y to get the position. Basically I'm trying to save the position of an existing static to respawn it later.

I have analyzed SimpleStaticSaving (https://github.com/thebgpikester/SimpleStaticSaving/blob/master/SSS) as well as SWAPR and CTLD. Is there a difference between mission editor placed static objects and dynamically spawned ones when trying this?

Also, when iterating through all statics with SET_STATIC:New():FilterStart(), how does one differentiate between the group entry and the, well, "unit" entry of the static object?

 

Thanks!

Link to comment
Share on other sites

I tried that, but no joy. But even before that I have the problem that I do not know what object is which, for when I iterate though every static I get 2 objects returned for a single static object in game and I don't see a way to discern between these two. And calling getPoint() on a static that I fetch by known name results in a nil error.

EDIT: I think there's something wrong in DCS here. The returned objects seem to imply that internally there's both a group and a unit. But the usual methods don't work.


Edited by Toumal
Link to comment
Share on other sites

	AllStatics:ForEach(function (grp)
		local _name = grp:GetName()
		if (string.starts(_name, "CTLD ") ) then
			env.info("Found CTLD static: "..grp:GetName())
			env.info("Found CTLD static X: ".. grp:getPoint().x .." Z: ".. grp:getPoint().z)
			env.info("Found CTLD static Country: ".. grp:getCountry())
			SaveStatics[grp:GetName()] =
			{
				["heading"] = grp:GetHeading(),
				["groupId"] =grp:GetID(),
				["shape_name"] = grp:GetTypeName(),
				["type"] = grp:GetTypeName(),
				["unitId"] = grp:GetID(),
				["rate"] = 20,
				["name"] = grp:GetName(),
				["category"] = grp:GetCategoryName(),
				["y"] = grp:GetVec2().y, 
				["x"] = grp:GetVec2().x, 
				["Country"] = grp:GetCountry()
			}
		end
	end)

 

I also tried staticObject = StaticObject.getByName(name), no joy.

I actually found a workaround by not using any of those functions, and just storing commands for recreating the objects needed along with the required parameters. But it's super cumbersome, and I also found out that some scripts hook into the static creation in a way that completely breaks it (specifically Airboss).

It's all quite painful.

Link to comment
Share on other sites

Pretty sure I've solved your problem, I was unsure if you were using MOOSE or just the SSE, but now I see MOOSE. Methods in MOOSE most likely always start with capital, while SSE starts with lowercase:

MOOSE :GetName()

SSE :getName()

so keep that in mind when utilizing moose

Any who here is the changed code:
 

AllStatics:ForEachStatic(function(staticObj)
    local _name = staticObj:GetName()
    if ( string.match(_name, "CTLD ") ) then
        env.info("Found CTLD static: "..staticObj:GetName())
        env.info("Found CTLD static X: ".. staticObj:GetVec2().x .." Y: ".. staticObj:GetVec2().y)
        env.info("Found CTLD static Country: ".. staticObj:GetCountry())
        SaveStatics[staticObj:GetName()] =
        {
            ["heading"] = staticObj:GetHeading(),
            ["groupId"] =staticObj:GetID(),
            ["shape_name"] = staticObj:GetTypeName(),
            ["type"] = staticObj:GetTypeName(),
            ["unitId"] = staticObj:GetID(),
            ["rate"] = 20,
            ["name"] = staticObj:GetName(),
            ["category"] = staticObj:GetCategoryName(),
            ["y"] = staticObj:GetVec2().y,
            ["x"] = staticObj:GetVec2().x,
            ["Country"] = staticObj:GetCountry()
        }
    end
end)

 

A few things to note:

When iterating through sets you should use the appropriate for method, in this case for statics we iterate with ForEachStatic.

Changed string.starts to string.match, unless you've made your own function I'd suggest just using string.match, because that function does not exist

Instead of using the SSE :getPoint() method, that log entry now just uses the GetVec2 method to print the x, y coords.

Changed getCountry to GetCountry for your 3rd log message

 

Link to comment
Share on other sites

Thanks, that is indeed confusing. I have to have MOOSE (as well as mist, witchcraft and a few others) to support the various modules. I did not intend to use MOOSE specifically, in fact I was actually trying to avoid using it for fundamental things 😉

However, as it turns out for me the cleanest way to proceed is to store intent instead of results, i.e. commands that led to the creation of the static, instead of the statics themselves.

Anyway, thanks a lot for the help! I'm pretty sure I'll run into the problem of iterating through statics again soon, so this will come in handy.

  • Like 1
Link to comment
Share on other sites

  • Recently Browsing   0 members

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