spawn a monster with a script
spawn a monster with a script
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.
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
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:
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.
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")
endGrimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: spawn a monster with a script
how do I "delay" it?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: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.Code: Select all
onDie = function(self) self.go:spawn("twigroot") end
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
well, i wrote this script
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
Code: Select all
function herderSplit()
onDie = function(self)
self.go:spawn("herder_swarm")
end
end
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
yesFeMaiden 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?
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
this time i tried this
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...
Code: Select all
function herderSplit()
self.go:spawn("herder_swarm")
end
why is this so hard for me...
Re: spawn a monster with a script
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
how do I put the code in the onDie hook of the monster?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.
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
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?
Last edited by FeMaiden on Sun Oct 25, 2015 11:56 pm, edited 1 time in total.
Re: spawn a monster with a script
The onDie hook is part of the monster-component.
you can add there something like
this example is copied from the definition of the "fire-elemental" monster.
you can add there something like
Code: Select all
onDie = function(self)
self.go.sound:fadeOut(1)
end,Re: spawn a monster with a script
*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?
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?