Page 1 of 1

LUA questions about entering regions

Posted: Sun Aug 10, 2008 2:52 pm
by adventfear
How can I make it so that a Jet Trooper is killed when he enters a region?

Is it possible to keep a jedi starfighter from spawning until I enter a certain region?

Re: Need help with a couple things...

Posted: Sun Aug 10, 2008 4:39 pm
by Maveritchell
Code for killing a jettrooper when he enters a region (goes in ScriptPostLoad). I made some assumptions when I wrote this, my first was that your jettrooper is the 6th unit (from top to bottom), and my second was that your region was called "jettrooperkillregion." The name in quotes at the end has to match the name in ZE (and property name in ZE- this should be the same as the name in ZE) of your region. The number after GetCharacterClass should be equal to the position of your unit minus 1 (If it's the 4th unit, it would be set == 3, etc.).

This could also be done without any .lua code at all, if you made a damage region that affected all "person" healthtypes and gave your hero a different healthtype (e.g. "animal") and then set the region to not do damage to that healthtype.

Code: Select all

OnEnterRegion(
	function(region, player)
		if GetCharacterClass(player) == 5 then
			playerunit == GetCharacterUnit(player)
			SetProperty(playerunit, "CurHealth", 0)
		end
	end,
"jettrooperkillregion"
)
However, the code for the second makes the code for the first redundant. I'm assuming you only want your hero unit to be able to unlock the vehicle - it's a lot easier to streamline all this into one piece of code. You have to tie a vehicle spawn into a CP and then kill the CP when the map starts, and respawn it when the right unit enters a region.

Again, here I made some assumptions. I'm still assuming that your jettrooper is your 6th unit; I also assumed that the team you want to give the bonus to (i.e. the team with the hero that can reach this) is team 1. I also assumed that you called the CP (that you tied the vehicle spawn to) was called "bonuscp" and I assumed that the region was called "givebonus."

Code: Select all

KillObject("bonuscp")
OnEnterRegion(
	function(region, player)
		if GetCharacterTeam(player) == 1 and GetCharacterClass (player) ~= 5 then
			RespawnObject("bonuscp")
		end
	end,
"givebonus"
)