Teleport an enemy without a teleporter.

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Teleport an enemy without a teleporter.

Post by Emera Nova »

So I'm looking to teleport a boss mid battle on to an area where he can't harm the party and the party can't harm him until after minions spawn in and all have been killed. How would I target a enemy to be teleported without using a teleporter.
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Teleport an enemy without a teleporter.

Post by trancelistic »

So far I know it needs a very compliated script.

It needs to know mid battle boss_HP == x ?
it needs to know if boss_hp == x then teleport it..

etcetc.
I cannot code it for you. Perhaps some 1 else want to code it.

I think its possible however.
Last edited by trancelistic on Thu Jul 23, 2015 8:18 pm, edited 1 time in total.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Teleport an enemy without a teleporter.

Post by Isaac »

This can depend on what you want to trigger the teleport.

If the player (or Boss monster) activates a switch or plate to teleport the Boss, then just make a script_entity with a function for moving the Boss; (and probably pausing the boss fight). Call it from the switch or plate.

If it's a timed event, then it's the same thing as the switch function really.

If the boss is to teleport after a certain amount of damage... That can be triggered via the monster's onDamage or onDie hooks. For instance onDie could be used to refuse death, and move the monster instead.

In all cases, you use the command setPosition to move the monster.

SetPosition is described in the gameobject component listing in the scripting reference.

** I can post a blind example, but it might be better if you explain exactly how your idea is meant to work.
Last edited by Isaac on Thu Jul 23, 2015 8:28 pm, edited 1 time in total.
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Teleport an enemy without a teleporter.

Post by trancelistic »

Thanks Isaac.,

I think however with the "mid fight"of boss, I think he kinda ment like: IF The boss lost 50% of his hp,,, then is teleported.

That would force a script with onHook or so and a new defined Boss.... right?

( still learning though haha)

EDiT: I could be so wrong. I prolly am:)
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Teleport an enemy without a teleporter.

Post by Isaac »

Video
editor source

A quick example concept, using onDamage.
(This one doesn't use 50%, and just checks for a value below a given amount.)

Code: Select all

ratling_boss_1.monster:addConnector("onDamage", self.go.id, "retreat", ratling_boss_1)

function retreat(target)
	if target.go.monster:getHealth() < 150 then
	target.go:setPosition(14,17,0,2,1)
	mine_counterweight_chains_1:createComponent("Particle"):setParticleSystem("damage_shock") --Just an effect
	ratling_boss_1.monster:removeConnector("onDamage", self.go.id, "retreat", ratling_boss_1)
	end
end
If you were to use onDeath instead of onDamage as the hook, I think that you would have to define the hook in a custom monster, as returning false from connectors will not stop an occurring event; in this case the monster's death.
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Teleport an enemy without a teleporter.

Post by Emera Nova »

I ended up using something hella simple too xD...

Code: Select all

function CheckHealth()
   if warden_1.monster:getHealth() <= 600
then
    timer_143.controller:start();
	timer_145.controller:start();
	timer_146.controller:start();
		if findEntity("timer_144") ~= nil then
			timer_144:destroy()
				warden_1:setPosition(22,5,2,0,3)
				party:setPosition(22,7,0,0,3)
			hudPrint("Somebody delivered a FEAST!! Melt for me, pastycakes!")
		end
   end
end
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Teleport an enemy without a teleporter.

Post by trancelistic »

What about the log 1 script modified?. Remember the spider eggs, destroy it and a spider came out of it.


Or if x Unique I'd's were destroyed you could cause a trigger like open a door.
It should be possible to read 1 ID's hp right, then teleport it. Like the spider would from the eggs kinda?

As in other words, Just drop the boss hp to zero, so a script knows its dead ( hp = 0 ) so then spawn a new one, who you defined as a new monster with modified hp etc. ( second part|)

Just a thought.

( Yes im a noob)
Emera Nova
Posts: 146
Joined: Wed Jun 11, 2014 1:31 am

Re: Teleport an enemy without a teleporter.

Post by Emera Nova »

Funny you should mention spiders coming out of eggs xD I have that in this very dungeon.

Code: Select all

function createmonster()
   if findEntity("spider_eggs_2") == nil then
      spawn("spider",3,18,23,1,0,"spiderspawn")
	script_entity_52:destroy()
	timer_34:destroy()
   end
end
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: Teleport an enemy without a teleporter.

Post by Isaac »

Emera Nova wrote:Funny you should mention spiders coming out of eggs xD I have that in this very dungeon.

Code: Select all

function createmonster()
   if findEntity("spider_eggs_2") == nil then
      spawn("spider",3,18,23,1,0,"spiderspawn")
	script_entity_52:destroy()
	timer_34:destroy()
   end
end
Alternatively:
(These don't require timers or checks.)

Code: Select all

--script_entity on map
for object in party.map:allEntities() do
	if object.name == "spider_eggs" then
		object.health:addConnector("onDie", self.go.id, "hatch")
	end
end

function hatch(caller)
     --local option = iff(math.random(2) < 2,  false, true)
	if not option then
		self.go:spawn("spider")
	end
end

________________________

Option 2:

Code: Select all

--redefines 'spider_eggs'. Place in scripts/object.lua
--optionally replace with unique name; "spider_egg_spawner"

defineObject{
	name = "spider_eggs",
	baseObject = "spider_eggs",
	components = {
		{
			class = "Health",
			health = 160,
			immunities = { "poison" },
			spawnOnDeath = "spider_eggs_broken",
			onDie = function(self)
				for i = 1, math.random(2,7) do
					local obj = self.go:spawn("tiny_spider")
					local pos = obj:getWorldPosition()
					local spread = 1.5
					pos.x = pos.x + (math.random() - 0.5) * spread
					pos.z = pos.z + (math.random() - 0.5) * spread
					obj:setWorldPosition(pos)
				end
				--local option = iff(math.random(2) < 2,  false, true)
				if not option then
					self.go:spawn("spider")
				end
			end,
		},
	}
}
___________________________________
Uncomment --local option = iff(math.random(2) < 2, false, true)
To make the spawn chance 50% instead of 100%.
trancelistic
Posts: 275
Joined: Sat Jun 16, 2012 5:32 am

Re: Teleport an enemy without a teleporter.

Post by trancelistic »

Isaac did it again:)

I wish I understood more about "caller" I never used such a thing... Cuz yeah I never learned it haha:)
It sounds great though. I must learn it some day, just like onHooks...
No idea wtf an onHook does still:)
Post Reply