Using Lua to mod Monster stats? UPDATE: Solved the HP Issue!!!!

The role-playing games (I-X) that started it all and the various spin-offs (including Dark Messiah).

Moderator: Moderators

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Using Lua to mod Monster stats? UPDATE: Solved the HP Issue!!!!

Postby motter25420 » Aug 27 2017, 20:35

Hey All,

I'm using Grayfaces MMExtension to mod the game. I know I can go into Monsters.txt and mod Monster stats but I want to be able to change them only on certain maps. He gave an example to change their hostility (see below) and it works fine.

As you can see I used the common female villager. I then try to increase her Hit Points, I used the commands Grayface has listed in his MMExtension help, I tried both variations, I also tried getting her to fly, no luck.

Now the villager will come and attack me, but her HP stay the same. Do I have the command wrong? If so, does anyone have a list of the commands that work, the commands on the Help Page do not seem to be correct. Thanks.

function events.BeforeLoadMap()
if Game.Map.Name == "outc2.odm" then
LocalMonstersTxt()

Game.MonstersTxt[121].HostileType = 4 -- PeasantF1A
Game.MonstersTxt[122].HostileType = 4 -- PeasantF1B
Game.MonstersTxt[123].HostileType = 4 -- PeasantF1C

Game.MonstersTxt[121].Hitpoints = 100 -- PeasantF1A
Game.MonstersTxt[122].Hitpoints = 200 -- PeasantF1B
Game.MonstersTxt[123].Hitpoints = 300 -- PeasantF1C
end
end


*************************2nd Try

function events.BeforeLoadMap()
if Game.Map.Name == "outc2.odm" then
LocalMonstersTxt()

Game.MonstersTxt[121].HP = 100 -- PeasantF1A
Game.MonstersTxt[122].HP = 200 -- PeasantF1B
Game.MonstersTxt[123].HP = 300 -- PeasantF1C
end
end

**********************Flying

function events.BeforeLoadMap()
if Game.Map.Name == "outc2.odm" then
LocalMonstersTxt()

Game.MonstersTxt[121].Fly = Y -- PeasantF1A
Game.MonstersTxt[122].Fly = Y -- PeasantF1B
Game.MonstersTxt[123].Fly = Y -- PeasantF1C
end
end
Last edited by motter25420 on Oct 2 2017, 18:30, edited 3 times in total.

Rodril
Assassin
Assassin
Posts: 272
Joined: 18 Nov 2016

Re: Using Lua to mod Monster stats?

Postby Rodril » Sep 23 2017, 12:34

Hello. Those fields you changing are wrong. Check manual: https://sites.google.com/site/sergroj/m ... ersTxtItem

"Game.MonstersTxt[121].Hitpoints = 100" - MonstersTxt item does not contain "Hitpoints" field, you must change "FullHP" or "FullHitpoints" fields.
"Game.MonstersTxt[121].Fly = Y" - "Fly" is boolean value, "Game.MonstersTxt[121].Fly = true" will work.
Last edited by Rodril on Sep 23 2017, 12:35, edited 1 time in total.

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Re: Using Lua to mod Monster stats?

Postby motter25420 » Sep 23 2017, 21:27

OK, thanks, I had thought I tried using both "FullHP" and "FullHitpoints" and neither worked, but maybe I am wrong, will try again.

As for the "fly" I used "Y" because that is what was used in the monsters.txt file, but I'll try it with "true".

This will help a lot, thank you very much for the reply.

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Re: Using Lua to mod Monster stats?

Postby motter25420 » Sep 26 2017, 0:25

Rodril wrote:Hello. Those fields you changing are wrong. Check manual: https://sites.google.com/site/sergroj/m ... ersTxtItem

"Game.MonstersTxt[121].Hitpoints = 100" - MonstersTxt item does not contain "Hitpoints" field, you must change "FullHP" or "FullHitpoints" fields.
"Game.MonstersTxt[121].Fly = Y" - "Fly" is boolean value, "Game.MonstersTxt[121].Fly = true" will work.


Hi Rodril. I appreciate your response however I tried those commands and it still does not work. Pics below, not sure what I'm doing wrong. Have you gotten this to work?

https://imgur.com/a/lvDxB

User avatar
Troller
Pixie
Pixie
Posts: 109
Joined: 30 Jul 2014
Location: Danmark

Re: Using Lua to mod Monster stats?

Postby Troller » Sep 26 2017, 8:38

Hi motter25420

I haven't tried modding but I have some experience in software development and one issue I can see is that you use "FullHitpoints" where the manual states "FullHitPoints" with a capital 'P' and in your image you have "True" often booleans are lower cases so try "true".

Good luck - hope that it can help a bit...

Regards
Troels

Rodril
Assassin
Assassin
Posts: 272
Joined: 18 Nov 2016

Re: Using Lua to mod Monster stats?

Postby Rodril » Sep 26 2017, 14:54

motter25420 wrote:https://imgur.com/a/lvDxB

As Troller stated, lines are case-sensitive, but also one thing i did not understand at once: changes in Game.MonstersTxt affecting only monsters who were spawned durning gameplay. Peasants at "oute3.odm" are predefined, they were placed at map-editing stage, and their "Fly", "HP" properties are already set, to change them use that kind of code in addition:

Code: Select all

function events.LoadMap()
   if Map.Name == "oute3.odm" and Map.Refilled then
      for i,v in Map.Monsters do
         if v.Id == 121 then
            v.Fly = true
            v.FullHP = 100
            v.HP = 100

         elseif v.Id == 122 then
            v.Fly = true
            v.FullHP = 200
            v.HP = 200

         elseif v.Id == 123 then
            v.Fly = true
            v.FullHP = 300
            v.HP = 300
         end
      end
   end
end


"LoadMap" event required becaue at "BeforeLoadMap" Map.Monsters is not loaded yet. Map.Refilled is not nil at game start and each visit when map was just refilled again.

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Re: Using Lua to mod Monster stats?

Postby motter25420 » Sep 27 2017, 20:16

Hey guys. I really do appreciate your help. I tried what you suggested, I copy and pasted it exactly and still nothing worked except the Hostile.

Just an FYI, I'm not really wanting to mod the FPeasant for my finished mod, I was just using her as the test Monster because she is right there at game start.

I understand what you meant about Monsters being spawned vs Monsters preset in the map file.

I tried all of these scripts on the Goblins in New Scorpigal who are spawned by "Mapstats" and got the same results, I can control their hostility but nothing else.

I do know some basics of programming and I am wondering why you did your "for" loop as you did. Don't you normally have to define "i" ex:

for i = 0, i < 10, i++

I am lost as to what the script is defining as "i" and also "v".

Did you try this script and it worked? What "Scripts" folder did you put it in and did you give it a certain name? Thanks again for the assistance.

User avatar
Troller
Pixie
Pixie
Posts: 109
Joined: 30 Jul 2014
Location: Danmark

Re: Using Lua to mod Monster stats?

Postby Troller » Sep 28 2017, 7:14

motter25420 wrote:I do know some basics of programming and I am wondering why you did your "for" loop as you did. Don't you normally have to define "i" ex:

for i = 0, i < 10, i++

I am lost as to what the script is defining as "i" and also "v".

I can help clarify this part.
To understand the statement

Code: Select all

    for i,v in Map.Monsters do

The data structure "Map" is important to know. It is used to map identifiers (i) to the values (v) or objects store in the map. It is often optimized to very efficiently retrieve the value given the identifier. There is probably also a syntax that lets you get a specific monster from the map without having to go thru all of them.
This for statement lets you traverse the data structure giving you the identifier and the value in the variables you entered.
You could rename them

Code: Select all

    for identifier,value in Map.Monsters do

or

Code: Select all

    for identifier,monster in Map.Monsters do

I would almost bet that i is equal to v.Id

I hope that helped a bit.

Regards,
Troller
Last edited by Troller on Sep 28 2017, 7:17, edited 2 times in total.

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Re: Using Lua to mod Monster stats?

Postby motter25420 » Sep 28 2017, 15:52

Yeah, I think I understand the loop now, but still can't get the stats to change. Oh well, I have to work around it. Thanks again!

****EDIT: I got it to work finally!!! I realized even the map names are case sensitive as well. All this time and frustration just because I was using a capital "O" for the "oute3.odm".

Now the only problem I have is figuring out the "Attack" Syntax.
Last edited by motter25420 on Oct 2 2017, 18:01, edited 1 time in total.

User avatar
GrayFace
Titan
Titan
Posts: 1385
Joined: 29 Nov 2005

Re: Using Lua to mod Monster stats?

Postby GrayFace » Oct 3 2017, 19:47

Troller wrote:The data structure "Map" is important to know. It is used to map identifiers (i) to the values (v) or objects store in the map. It is often optimized to very efficiently retrieve the value given the identifier. There is probably also a syntax that lets you get a specific monster from the map without having to go thru all of them.

The data structure you're talking about is the basic building block of Lua, it's called just "table" in Lua. My arrays, such as "Map.Monsters" are made to be traversed with that syntax, unlike regular tables that are traversed by for k, v in pairs(t) do or for k, v in ipairs(t) do.
My patches: MM6 MM7 MM8. MMExtension. Tools. Also, I love Knytt Stories and Knytt Underground. I'm also known as sergroj.

User avatar
Troller
Pixie
Pixie
Posts: 109
Joined: 30 Jul 2014
Location: Danmark

Re: Using Lua to mod Monster stats?

Postby Troller » Oct 4 2017, 9:10

GrayFace wrote:The data structure you're talking about is the basic building block of Lua, it's called just "table" in Lua. My arrays, such as "Map.Monsters" are made to be traversed with that syntax, unlike regular tables that are traversed by for k, v in pairs(t) do or for k, v in ipairs(t) do.

Good to know - how are the complexity then - often maps have a hash map implementation underneath with an O(1) retrieval complexity and an insert that is very dependent on the implementation O(1) -> O(N). I know I'm a geek when it comes to data structures :-)
Last edited by Troller on Oct 4 2017, 9:12, edited 1 time in total.

motter25420
Leprechaun
Leprechaun
Posts: 30
Joined: 04 Feb 2017

Re: Using Lua to mod Monster stats?

Postby motter25420 » Oct 6 2017, 18:44

GrayFace wrote:
Troller wrote:The data structure "Map" is important to know. It is used to map identifiers (i) to the values (v) or objects store in the map. It is often optimized to very efficiently retrieve the value given the identifier. There is probably also a syntax that lets you get a specific monster from the map without having to go thru all of them.

The data structure you're talking about is the basic building block of Lua, it's called just "table" in Lua. My arrays, such as "Map.Monsters" are made to be traversed with that syntax, unlike regular tables that are traversed by for k, v in pairs(t) do or for k, v in ipairs(t) do.


-Can I use MMExtension to mod maps? I'm not trying to make new maps, just want to remove some things like the pyramid in "Dragonsand", I also want to move one of the buildings in MM8 to another map.

-BDJ had taught how to hex it, but I don't like to hex if I don't have to, you're Extension is so much easier, plus as I say I hardly remember most of the stuff from 7yrs ago.

-One last thing, in MM6 in the Character Portraits there is a face for the Diseased condition but it doesn't show in the game, they just get the same pic as when they're poisoned, I've searched all the files and can't find where this is controlled.

Thanks as always. I'll be sure to post my mods when I'm done, I'll give you all the credit you're due.


Return to “Might and Magic”

Who is online

Users browsing this forum: Google [Bot] and 17 guests