How to differ Building from Vehicle? In general?

Lua code; D2k

Information and discussion for custom maps and mods.
Post Reply
Adrian
Posts: 118
Joined: Wed Feb 12, 2020 5:44 pm

How to differ Building from Vehicle? In general?

Post by Adrian »

Question about Lua code.
How to differ D2k Building from vehicle? In general?

I can write detail

Code: Select all

actor.Type ~= "wind_trap"
actor.Type ~= "palace"
actor.Type ~= "wall"
and so on.

I would like to found more general solution.

If object is Building then ...
If object is Vehicle then ...


---

P.S. Or maybe an unique property?

JovialFeline
Posts: 5
Joined: Mon May 15, 2023 12:58 pm

Re: How to differ Building from Vehicle? In general?

Post by JovialFeline »

The usual method is to check if an actor can use StartBuildingRepairs. Most buildings can do this, with some exceptions like civilian houses in Red Alert or in Dune's case, the Sietch.

Code: Select all

local USSR = Player.GetPlayer("USSR")

local function GetSovietBase()
	local buildings = Utils.Where(USSR.GetActors(), function(actor)
		return actor.HasProperty("StartBuildingRepairs")
	end)

	return buildings
end

local function ExplodeSovietBase()
	local buildings = GetSovietBase()

	Utils.Do(buildings, function(b)
		b.Kill("ExplosionDeath")
	end)
end

WorldLoaded = function()
	Trigger.AfterDelay(DateTime.Minutes(1), ExplodeSovietBase)
end
Aircraft can be checked with the Land property.

Ground attack vehicles may just require a type check (at least for now), since the locomotor can't be checked and there's not yet a Lua property for ordering a vehicle to repair at a pad.

Code: Select all

local tankTypes = { "combat_tank_o", "combat_tank_h", "combat_tank_a" }
local tanks = Ordos.GetActorsByTypes(tankTypes)

Adrian
Posts: 118
Joined: Wed Feb 12, 2020 5:44 pm

Re: How to differ Building from Vehicle? In general?

Post by Adrian »

...to check if an actor can use StartBuildingRepairs
Thank you for explanation. And for big and informative answer.
I thought in this direction yesterday. But I made mistake.
I searched in yaml files for traits that different for buildings and vehicles. And I found trait "RepairableBuilding".

It does not work:

Code: Select all

actor.HasProperty("RepairableBuilding")
Your variant works, thank you.

Code: Select all

actor.HasProperty("StartBuildingRepairs")
--------

And I found properties for units: "Attack" and "Move".

Code: Select all

actor.HasProperty("Attack")
It founds all the units, that can attack, including turrets (a kind of buildings).

It is not quite the same that was asked in my question here. But I was looking for something like this.

--------

Property "Move" founds everything that moves. Including aircrafts ("carryalls").

Post Reply