Page 1 of 2
spawn a monster with a script
Posted: Sun Oct 25, 2015 11:07 pm
by FeMaiden
I know this is has probably been answered before..
how do I spawn a monster with a script, not using a spawner. spawners don't move.
I want the game to spawn a new monster in the same tile the first monster was on when it triggers the script with "onDie"
I see this command
spawn("uggardian", party.level, 11, 15, 1, 0)
and this
spawn("herder",1,1,1,1,0)
and this
spawn("viper_root", party.level, 17, 4, 3, 0)
but I don't understand what those numbers are at the end, and what does "party.level" mean?
are those numbers after it, the coordinates?
like if my map is at x2 y3 z1, i would need to type
spawn("viper_root", party.level, 2, 3, 1, 0)
?
but i'm assuming this command spawns the monster in front of the party, I'm hoping to make it spawn the new monster in the same square that the first monster was in when it died,
in case the party used a ranged attack, I don't want it to look weird that the second monster spawns in front of the party when the original was 3 squares away.
I want it to spawn one of those swarms that has 2 monsters on the same tile when they kill the first monster so it looks like it split into 2.
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:09 pm
by minmay
http://www.grimrock.net/modding/scripting-reference/
Look for the "spawn" function on that page. It's in the "Global Functions" section near the top.
For your specific case, you'd probably prefer to use the shortcut function GameObject:spawn(), which simply spawns the object at the same position as the GameObject used to call the method. So party:spawn("torch") will spawn a torch at the party's position. Your onDie hook could just read:
Code: Select all
onDie = function(self)
self.go:spawn("twigroot")
end
and it would spawn a twigroot at the same position as the dying monster. Note that this creates a console warning since there's already a monster at that position (the dying one), so you should probably delay it until later in the frame instead.
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:16 pm
by FeMaiden
minmay wrote:http://www.grimrock.net/modding/scripting-reference/
Look for the "spawn" function on that page. It's in the "Global Functions" section near the top.
For your specific case, you'd probably prefer to use the shortcut function GameObject:spawn(), which simply spawns the object at the same position as the GameObject used to call the method. So party:spawn("torch") will spawn a torch at the party's position. Your onDie hook could just read:
Code: Select all
onDie = function(self)
self.go:spawn("twigroot")
end
and it would spawn a twigroot at the same position as the dying monster. Note that this creates a console warning since there's already a monster at that position (the dying one), so you should probably delay it until later in the frame instead.
how do I "delay" it?
I like that "simpler" solution.
however, i would like a better explanation of the earlier example. i'm reading the scripting reference
in the earlier examples,
(viper_root, party.level, 17,4,3,0)
"party.level" is the level index?
17.4 is the xy coordinates of the map?
while the 3 means the mob will face west?
and the 0 is the elevation?
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:30 pm
by FeMaiden
well, i wrote this script
Code: Select all
function herderSplit()
onDie = function(self)
self.go:spawn("herder_swarm")
end
end
and nothing happens...at least it doesn't crash...
theres no new monster spawn, no hud warning either.
I made sure to connect the herder to my script with onDie and it executes the herderSplit function
but nothing happens
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:34 pm
by THOM
FeMaiden wrote:
17.4 is the xy coordinates of the map?
while the 3 means the mob will face west?
and the 0 is the elevation?
yes
the "party.level" term means, the level, on which the object is created is the same, the party is on. You could also write the specific number like "12". Or "self.level" which would mean the same level, the existing object is on.
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:36 pm
by FeMaiden
this time i tried this
Code: Select all
function herderSplit()
self.go:spawn("herder_swarm")
end
and it correctly spawns the herder swarm but not where the monster is. it spawns it where I spaced the scripting entity, I basically just scripted my own stationary "spawner" asset.
why is this so hard for me...
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:43 pm
by THOM
a yes - the "self" is always the object, the command comes from. In this case a script-entity. If you would put the code in the onDie hook of the monster, the "self" would be the monster.
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:46 pm
by FeMaiden
THOM wrote:a yes - the "self" is always the object, the command comes from. In this case a script-entity. If you would put the code in the onDie hook of the monster, the "self" would be the monster.
how do I put the code in the onDie hook of the monster?
is that the space where it says "select target"?
well, I just tried this
Code: Select all
function split()
herder_5:spawn()
onDie = function(self)
self.go:spawn("herder_swarm")
end
end
and the whole dungeon editor crashed to the desktop, completely closing the app...
please just explain what the "onDie hook" is and how I "put code in the onDie hook"
am I supposed to create a scripting entity and link the onDie connector to it?
is the "hook" someplace else it in the monster object itself?
Re: spawn a monster with a script
Posted: Sun Oct 25, 2015 11:55 pm
by THOM
The onDie hook is part of the monster-component.
you can add there something like
Code: Select all
onDie = function(self)
self.go.sound:fadeOut(1)
end,
this example is copied from the definition of the "fire-elemental" monster.
Re: spawn a monster with a script
Posted: Mon Oct 26, 2015 12:00 am
by FeMaiden
*sigh*
in the components of the monster I see
gravity
model
animation
monster
brain
move
turn
basicAttack
where is the "hook"?
I expand "monster" and see
AI state
monster level
health
items
connectors
where is the "hook"?
if I expand connectors
I see onDie <select target> and a space to execute a function
where is the "Hook"?
so I just paste that code in one long line into the <select target> space?