Help setting monster level

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
KnotuAgain
Posts: 17
Joined: Sun Oct 05, 2014 7:29 am

Help setting monster level

Post by KnotuAgain »

I have an object script "my_coffin" that onDie spawns a skeleton (my_skeleton), and onDie(skeleton) drops random loot. It works fine. Now i cloned the my_coffin and the my_skeleton (..my_coffin_02 and my_skeleton_02..) because I want to make the same thing but at a more differcult level. I tried to use monster:setLevel(2) and I get a "tried to use global monster " error. I tried Monster:setLevel(2), same thing. I tried a setLevel(2), same thing. What is the correct command? I tried placing that command in the my_coffin_02 after the skeleton is spawned in the object scprit, did not work. I tried placing it in the my_skeleton_02 monster script.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Help setting monster level

Post by cromcrom »

In the wait for more educated replies, if you make clones, why don't you make them the level you want ? So you just have to spawn the creature.
A trip of a thousand leagues starts with a step.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Help setting monster level

Post by Isaac »

KnotuAgain wrote:I have an object script "my_coffin" that onDie spawns a skeleton (my_skeleton), and onDie(skeleton) drops random loot. It works fine. Now i cloned the my_coffin and the my_skeleton (..my_coffin_02 and my_skeleton_02..) because I want to make the same thing but at a more differcult level. I tried to use monster:setLevel(2) and I get a "tried to use global monster " error. I tried Monster:setLevel(2), same thing. I tried a setLevel(2), same thing. What is the correct command? I tried placing that command in the my_coffin_02 after the skeleton is spawned in the object scprit, did not work. I tried placing it in the my_skeleton_02 monster script.
When you say that you tried... monster:setLevel(2) ...
The "monster" part must be a named reference to the specific monster that you wish to adjust.

Some examples:
  • snail_1:setLevel(2)
  • ogre_3:setLevel(4)
  • myVar:setLevel(2)
*This last one 'myVar' would be a script variable that references a specific monster; for example:
for x = 1,4 do
myVar = findEntity('ogre_'..x)
myVar:setLevel(x)
end
KnotuAgain
Posts: 17
Joined: Sun Oct 05, 2014 7:29 am

Re: Help setting monster level

Post by KnotuAgain »

cloneObject {
name="my_skeleton_warrior_02",
baseObject="skeleton_warrior",
my_skeleton_warrior_02:setLevel(2),
onDie=function(self)
skeletonLoot_02={
"arrow",
"cave_nettle",
"throwing_knife",
"tar_bead",
"huntsman_cloak",
"dm_dart_poison",
"leather_cap",
"sack",
"leather_gloves",
"throwing_axe"
} -- end skeletonLoot
spawn(skeletonLoot_02[math.random(1, #skeletonLoot_02)], self.level, self.x, self.y, 0)
end -- end onDie
} -- end cloneObject

I get the following error while trying to open my mod: "attemp to index global 'my_skeleton_warrior_02' (a nil value)"

I also don't understand when comma are needed and when they are not needed in the lua langage.

I am trying to learn lua by reading other people code and trail and error. I thank you for any and all help the people in this forum give.
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Help setting monster level

Post by Isaac »

KnotuAgain wrote:I get the following error while trying to open my mod: "attemp to index global 'my_skeleton_warrior_02' (a nil value)"

I also don't understand when comma are needed and when they are not needed in the lua langage.

I am trying to learn lua by reading other people code and trail and error. I thank you for any and all help the people in this forum give.
Commas are used for separating data. You see them used in function parameters and table definitions.
Like:
print("Hello", "World")
myCollection = {1,2,3,4,5,6,7,8,9,0}

The definition of cloneObject is a table, and has commas between each value.
** my_skeleton_warrior_02:setLevel(2) is correct, but this does not belong in the definition; it belongs in a user script in the editor.

In the editor any placed monster can have the level set on load. Like this:
Image

But in scripts where you spawn a monster, you would use my_skeleton_warrior_02:setLevel(2) either as it is, or use it in conjunction with a spawn call, using this alternate form:
spawn('my_skeleton_warrior_02', 1,1,1,1):setLevel(2)

Notice that the spawn function itself takes the place of the monster's name.
Post Reply