Ask a simple question, get a simple answer

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
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

Just when you think you're getting it, the game always finds a way to smack you in the face.

I got a crash with "attempt to perform arithmetic on a nil value" using this:

Code: Select all

function spawnWalls()
    spawn("swamp_toad", party.level, 12, 2, 4, party.elevation, "frogger_1")
    spawn("zarchton_pair", party.level, 8, 2, 3, party.elevation, "ztons_1")
    frogger_1.monster:setAIState("guard")
    ztons_1.monstergroup:setAIState("guard")
end
What is wrong here? I am calling this at the end of a string of events the player has to perform. I tried using delayedCall and the other actions at the end of the sequence execute fine, then it crashes while trying to summon the monsters. The chain of LUA game files in the info dump starts with Brain.lua.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

It's the toad. You've set the facing argument to 4, but the valid range is 0-3.
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

I should stop crunching so hard on that mod and also never try to write scripts past 11pm. I know what the valid facing values are but I never figured out what was wrong! :D

Thanks, Isaac! <3

Edit: Is there a way to edit and trim down an exported item_atlas.dds?
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

I decided to gate everything behind currency including experience in my mod.
Experience will have to be bought.

What's the easiest way to make all monsters give 0 experience?
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

You can copy all monster definitions from the asset pack, rename the monsters' editor names (the first 'name' field in the LUA files) and give them zero in experience values under exp = XYZ in the 'Monster' class of the definition.

Or you can wait for Isaac or minmay to come up with a better way! :D
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

MonsterComponent:setExp(number)
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

Xardas wrote:MonsterComponent:setExp(number)

And where exactly do I implement this line?

I added 1 single turtle on my map, it's called turtle_1
I changed it's hp value to 1 in the dungeon editor and then saved my dungeon and closed the editor.

Then I checked the lines in the dungeon.lua

Right under the set health line.

spawn("turtle",13,13,2,0,"turtle_1")
turtle_1.monster:setHealth(1)

so I tried adding turtle_1.monster:setExp(0)

I have obviously no idea what I'm doing because that didn't work :)
User avatar
Xardas
Posts: 83
Joined: Fri Jul 28, 2017 12:30 am

Re: Ask a simple question, get a simple answer

Post by Xardas »

Don´t look into the definitions for this one.
There is an object, which is called "script_entity" in the Editor. You have to write your Code inside one of These.
Here is a simple, but not excellent solution for your Problem.

Name your Monsters ("monster_1","monster_2",etc...)
change "highest monsternumber" to the highest Monster index
e.g. monster_5 was your last monster so write: for i = 1, 5 do
then copy paste this into a lua script and it should work....
I haven´t tested it in the Editor, if there´s a Problem with it pm me.

Code: Select all

function setexp()
  for i = 1, "highest monsternumber" do       --put index here
     local monster = findEntity("monster_"..i)
     if monster then
       monster. monster:setExp(0)
    end
  end
end

delayedCall(self.go.id, 0.1, "setexp")  --calls the function at the start of the game
Also take a look at that. It´s the Scripting reference. https://github.com/JKos/log2doc/wiki/Components
Last edited by Xardas on Fri May 18, 2018 11:57 am, edited 1 time in total.
In order to get to the other side of the pit you have to get hit by the fireball and die....
Yep.....moving on!
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

I need something relatively simple but I can't figure out how to do it.

I have a bossfight which changes the lighting in its room, turning off some light sources and swapping them for others. However, once the fight is over, I'd like to fade back to the original non-boss lighting. I thought about onDie hooks for the bosses, that tick down a counter, which changes lighting when the bosses die, like in Skuggasveinn's tutorial, but the monsters are spawned via script and I'm not sure how to attach onDie to spawned stuff.

Nevermind, figured it out!

boss_id_1.monster:addConnector("onDie", "countername", "decrement")

I hadn't formatted the parameters as strings with quotation marks! :D
User avatar
Curunir
Posts: 332
Joined: Fri Mar 30, 2012 11:19 pm

Re: Ask a simple question, get a simple answer

Post by Curunir »

Can someone detail how and why exactly setWorldPosition() works?

The scripting reference has nothing on it, LOG2DOC tells me it takes (vec). Searching the forum shows me at least two different uses:

lr_6:setWorldPosition(26.9999,-0.49,27.5,0)

but also in a table, used by Isaac: "mine_door_spear_1", 'setWorldPosition',vec(50.65,0,49.5)

Is there anywhere I can read up on how vectors work, because I really don't understand those? I sort of figured out color vectors in sky and fog definitions but have no idea how positional ones work.

Why does the firs example use 4 values (3 commas) and the second one - just 3 values (2 commas)?
Post Reply