spawn a key at the party's position

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!
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

spawn a key at the party's position

Post by FeMaiden »

I'm sure this answer is somewhere on the forums, but i've been searching and can not find it.

I'm pretty sure I ight have asked this question already, but I forgot which thread it was in.

I want to spawn a key where the party is standing when they kill a boss.

I alreayd know how to spawn a scroll and set the text, but I have been using floor triggers for that which don't move, so I always know that when the party steps on the trigger, I know exactly where the party will be, so I know where to place the scripting entity since the scroll will pop out of the entity.

but I have 3 bosses in 3 different spots on the map, and i have a counter set up so that when all 3 die, it runs a script to spawn a key. but I want the key to spawn in front of the party.
so this way, the party can tacke the 3 bosses in any order they wish, and when they kill the last one, a key spawns.

i tried

Code: Select all

function key()
	local k = party.party:getWorldPosition()
	k:spawn("nexus_key")
end
as a test, i did not mess with counters, i just connected a mummy up to the script
and the editior Crashed to desktop, and a white window appeared saying a bunch of stuff, (i don't remember what it said) and I lost some progress, it seems like it rolled my mod back to an point 10 minutes earlier.

I'm sure there's more to the code, and I did something drastically wrong, but how do I do this?

i found the grimrock.log it says this
=== Software Failure ===

#script_entity_13.script:2: attempt to call method 'getWorldPosition' (a nil value)
stack traceback:
#script_entity_13.script:2: in function <#script_entity_13.script:1>
[string "Script.lua"]: in function 'sendMessage'
[string "Component.lua"]: in function 'triggerConnectors'
[string "Component.lua"]: in function 'callHook'
[string "Monster.lua"]: in function 'die'
[string "GameMode.lua"]: in function 'keyPressed'
[string "DungeonEditor.lua"]: in function 'preview'
[string "DungeonEditor.lua"]: in function 'update'
[string "Grimrock.lua"]: in main chunk
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: spawn a key at the party's position

Post by FeMaiden »

welp...i'm an idiot again.

all I had to do was

Code: Select all

function key()
	local k = spawn("nexus_key")
end

and i hooked the 3 monsters up to the counter , set the value to 3, had each one decrement it onDie. and have the counter run the script.

and the key automatically drops from the last monster
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: spawn a key at the party's position

Post by Isaac »

party:spawn("nexus_key")
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: spawn a key at the party's position

Post by FeMaiden »

oh that's simple lol...

I kept trying to do stupid stuff like

Code: Select all

party.party:getWorldPosition(), spawn("nexus_key")
(which explains the CTDs)

I always make things more complicated than they need to be
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: spawn a key at the party's position

Post by AndakRainor »

If the party stands in front of a wall, doesn't the spawned key risk to be inside it ?
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: spawn a key at the party's position

Post by FeMaiden »

i think so...,although i think the key spawns out of the entity that activates the script.

so in my example, i wanted the key to spawn after killing 3 different monsters, and i wanted it to be a "Schrödinger's Gun". (from tv tropes : meaning the item is always in a different spot depending on the player's actions, i.e. it exists in all the places and yet it also exists in none of them)

like if the there is a medusa, a mummy, and a crab.
i have a counter set up with a value of 3
and each monster i kill decrements the counter onDie connected to the counter

when the counter activates, the script activates and spawns the key where the last monster died.

so like, if the player kills medusa first, then crab then mummy, the key spawns from the mummy.
but if they kill the medusa last, then the key will spawn from the medusa.

(so, all 3 monsters are theoretically carrying the key, but at the same time, none of them are, and only the last one that dies actually drops it)

this works perfectly with just the one line of code.

Code: Select all

function key()
   local k = spawn("nexus_key")
end
however, I have a series of "fireplaces" in another section of my mod,
i used the fire pit and turned the light and particles off.
i have a torch holder on the side of each fireplace and when the player places a torch in it, the fireplace lights up.
each one decrements a counter.
when all fireplaces are lit, the counter activates and it runs a script that spawns an everburning torch.

the everburning torch spawns from the last torch holder the player lights up. since it is the torch holder that caused it.

the only issue here is because the torch holder is on the wall, it does spawn on the other side of the wall.

my work around was to orient the torch holders so that their backside is pointing to the inside of the fireplace

however, the particle effects make the prize so difficult to see, the player might not realize what happened.

my next work around was to do a simple hudPrint alerting the player that something happened

the player will know to look for this message because i have hudprint dialogue between the party members all throughout my mod, and it makes a sound (specific to each character)
whenever one of them "talks".


edit: i also have the torch holders increment the timer onrRemoveItem, and turn off the fireplaces. this forces the player to leave the torches behind in the holders, meaning that if I have 7 fireplaces, the player can t just activate them all with the same torch.
i also needed to add to the script once the counter activates the script, the script then needs to disable the counter so the player can't just keep removing and inserting that last torch to get 100 prizes.

Code: Select all

function disablecounter()
	counter_name.counter:disable()
end
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: spawn a key at the party's position

Post by Zo Kath Ra »

AndakRainor wrote:If the party stands in front of a wall, doesn't the spawned key risk to be inside it ?
The game always spawns the key on the same tile as the party if you use party:spawn("nexus_key")

Code: Select all

local key = party:spawn("nexus_key")
print("x = " .. party.x .. " / y = " .. party.y .. " / facing = " .. party.facing .. " / elevation = " .. party.elevation .. " / level = " .. party.level)
print("x = " .. key.x .. " / y = " .. key.y .. " / facing = " .. key.facing .. " / elevation = " .. key.elevation .. " / level = " .. key.level)
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: spawn a key at the party's position

Post by AndakRainor »

i have hudprint dialogue between the party members all throughout my mod, and it makes a sound (specific to each character)
whenever one of them "talks".
That is a cool idea ! I have been thinking about something like this for some time now for my mod. A character with high willpower saying she/he has seen a secret button nearby, or the party insulting the spell caster who just damaged the team with a fireball against a wall... Could be fun ! Do you use it mostly for the story in your mod or for game play elements like noticing an event ? What sounds do you use, is it a pseudo voice specific to a race/genre or just a generic sound ?
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: spawn a key at the party's position

Post by FeMaiden »

AndakRainor wrote:
i have hudprint dialogue between the party members all throughout my mod, and it makes a sound (specific to each character)
whenever one of them "talks".
That is a cool idea ! I have been thinking about something like this for some time now for my mod. A character with high willpower saying she/he has seen a secret button nearby, or the party insulting the spell caster who just damaged the team with a fireball against a wall... Could be fun ! Do you use it mostly for the story in your mod or for game play elements like noticing an event ? What sounds do you use, is it a pseudo voice specific to a race/genre or just a generic sound ?

well, here's an example of what i did in a part of my mod.


each line of dialogue is triggered by a floor_trigger.
this does take a little bit of prediction trying to guess where the player will walk
to make sure the player triggers the dialogue, i put the triggers in spots where the player *has* to walk.
my paths are "open" but some spots, such as doorway and such, are places where the player can't avoid walking.

Code: Select all

function skinny()
	playSound("power_attack_yell_human_female")
	hudPrint (" "..party.party:getChampionByOrdinal(2):getName()..": Don't you just love skinny dipping in creepy ponds?")
end

function awesome()
	playSound("damage_human_male")
	hudPrint (" "..party.party:getChampionByOrdinal(3):getName()..": Yeah it's Awesome!")
end

function dressed()
	playSound("damage_human_female")
	hudPrint (" "..party.party:getChampionByOrdinal(4):getName()..": I guess we should, like...put our clothes back on or something")
end

function overthere()
	playSound("power_attack_yell_human_male")
	hudPrint (" "..party.party:getChampionByOrdinal(1):getName()..": We left them over there by the trees")
end
this story element explains why the party begins with nothing equipped (essentially naked)

if you notice, I used getChampionByOrdinal() instead of getChampion. this is because I have a script that resets imported character stats and traits and skills and changes the characters into the ones I wrote into the story. using the ordinal numbers of the champions means that even if the player juggles their positions, it will still display the correct dilogue and the dialogue will still make sense.

so ..the opening scene of my mod plays out like this.

----the player begins, they notice their party is different. instead of who they were expecting to see, they have 8 bit pixel art portraits(I don't want to reveal the names at this time)
** the day turns into night**
the party looks to the left, they can see out across a large lak..er..pond. (there are invisible walls placed to keep the player from jumping or falling in)
they have no choice but to step
forward 1 space

champion 2 : Don't you just love skinny dipping in creepy ponds?

step forward 1 more space

champion 3 : yeah it's awesome

1 more space

champion 4 : I guess we should, like...put our clothes back on or something

1 more space

champion 1 : We left them over there by the trees

the player then enters a more wide open area, and there are articles of clothing scattered about.
each one is a complete outfit tailored to each character's personality, but the player if free to put whatever items they want on anyone.

I did later learn how to insertItem() into the players inventories, but I like this scene since it plays directly into the theme of my mod.

a few steps later, the party steps out of the trees into a more open area with buildings to the left and right of them and a ghoul pops out of the ground
and

champion 2 : OMG! is that a..a...a...
champion 1: its a zombie! quick, take shelter in the building!


the player doesn't *have* to do this, they can fight the ghoul if they want, but eventually, they will want to go in the building anyway. besides the fact it would be incredibly tedious to fight a ghoul bare handed, and there is a weapon in the building so it behooves the player to go in the building, especially since there are other ghouls creeping about.

so i have more triggers at the front door and inside that trigger more dialogue.

champion 2 : i'm so scared , whats happening, I can hear those things scratching outside!

champion 1 : I dont know but we need to keep our heads, look! theres some knives on that table!

most of the dialogue is flavor text, but some alerts the player to things that might not be noticed otherwise.
because I am using the beds and tables from Germanny's assets, a newbie might not realize these are surfaces that cna contain items.
so I tried to predict the very first instances the player encounters these new assets and trigger dialogue like

champion 4 : look, there's some stuff on that bed!
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: spawn a key at the party's position

Post by FeMaiden »

I feel like i'm writing more of a movie script than a classic grimrock dungeon lol...

I must give a little credit. I was inspired to do this by OGDA's custom dungeon, "the Legend of The Dwarven Mines of kharak'kul" or however you spell that lol.

so in a way, the toughest part of making this mod is writer's block...

another challenge is
with these dialogue triggers, I have to subtly *steer* the player towards them without making them feel *railroaded*

I'm not just making one long hallway full of hudPrints...


if you notice, i have a difference sound play for each charatcer, so the player will eventually learn these sounds and know *who* is speaking at any given time.

I could have search for custom sounds but I have not gotten that far in my "studies" yet lol

I might do that later, after i'm done and i'm fine tuning the mod.
Post Reply