Naughty ore trucks in Lua

Ore trucks seem to ignore Lua commands but it's not clear why

Information and discussion for custom maps and mods.
Post Reply
jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Naughty ore trucks in Lua

Post by jeremy1337 »

Hello, grateful please for some help from anybody with experience in Lua scripting.

I have a mission map with two neutral ore trucks. I'm using them as scenery. Neither is being issued any commands.

When the mission loads, one of the ore trucks sits still.

The other ore truck, the naughty one, decides it's going off on what we call in the UK a "jolly". It drives across the map to the nearest ore field and starts filling up.

The hilarious thing about this behaviour is that nothing I have tried in Lua seems to override it:

Code: Select all

NaughtyOreTruck.Move(CPos.New(30, 87)) -- ignored, the truck just carries on driving
NaughtyOreTruck.Stop() -- also ignored
The only difference between the naughty ore truck, which ignores commands, and the good ore truck, which does what its told, is that the naughty ore truck is significantly closer to an ore field. Otherwise they're just both pieces of dumb scenery.

Please can somebody explain whether this is a feature, a bug, or what is the correct way to stop AI harvesters from harvesting. Thank you!

abcdefg30
Posts: 562
Joined: Mon Aug 18, 2014 6:00 pm

Re: Naughty ore trucks in Lua

Post by abcdefg30 »

That sounds really weird. Is the map uploaded somewhere? As easy workaround I'd suggest defining a custom unit that looks like a harvester but doesn't have the "Harvester" trait (i.e. make a unit that inherits "harv", remove that trait from it and add "RenderSprites" with "Image: harv" to it).

jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Re: Naughty ore trucks in Lua

Post by jeremy1337 »

Hi abcdefg30 thanks for the reply.

I've not made a custom unit before and have the following code which works correctly:

Code: Select all

COMB:
	Inherits: HARV
	Tooltip:
		Name: Combine
	RenderSprites:
		Image: HARV
	Harvester:
What's the syntax to totally remove the harvester trait please?

I've not stuck the map online anywhere but if you're curious about this harvester behaviour - which is still happening even after subclassing the default ore truck with the above - I'm happy to do so. Since both ore trucks have a clear path to the ore field, my conclusion is that there must be some sort of distance limit kicking in because there's no explanation otherwise.

abcdefg30
Posts: 562
Joined: Mon Aug 18, 2014 6:00 pm

Re: Naughty ore trucks in Lua

Post by abcdefg30 »

Code: Select all

COMB:
	Inherits: HARV
	Tooltip:
		Name: Combine
	RenderSprites:
		Image: HARV
	-Harvester:
would remove the Harvester trait. In general putting a "-" before any inherited trait removes it.

Edit: Thinking about it, removing the Harvester trait requires removing some more traits as well. It might be easier for you to just create a new unit and give it the harvester look. Or you try the code below, although I haven't tested if it works properly.

Code: Select all

COMB:
	Inherits: HARV
	Tooltip:
		Name: Combine
	WithFacingSpriteBody:
	RenderSprites:
		Image: HARV
	-Harvester:
	-WithHarvestAnimation:
	-WithDockingAnimation:
	-HarvesterHuskModifier:
	-WithHarvesterSpriteBody:
	-WithHarvesterPipsDecoration:

jeremy1337
Posts: 7
Joined: Wed Apr 06, 2022 7:07 am

Re: Naughty ore trucks in Lua

Post by jeremy1337 »

Your feeling was right that loads of exceptions get thrown when trying to use a harvester without certain traits. This happened even with the more detailed code you posted.

So I took your advice and figured out how to create a new unit. It looks like an ore truck, and responds to scripted commands like Move(), but with the key advantage of not driving off round the map under its own steam!

In case anybody comes to this in the future, the working version is:

Code: Select all

COMB:
	Inherits: ^Vehicle
	Tooltip:
		Name: Combine Harvester
	RenderSprites:
		Image: HARV
	Health:
		HP: 60000
	Armor:
		Type: Heavy
	Mobile:
		Speed: 85
		Locomotor: heavywheeled
	RevealsShroud:
		Range: 4c0
	SpawnActorOnDeath:
		Actor: HARV.EmptyHusk
	ChangesHealth:
		Step: 100
		Delay: 25
		StartIfBelow: 50
		DamageCooldown: 500
	Selectable:
		DecorationBounds: 42,42
Thanks again for your help!

Post Reply