[solved] monsterattack component ?

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!
Post Reply
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

[solved] monsterattack component ?

Post by cromcrom »

I am trying to create special monsters ("fat"; "dangerous") "on the run"
However I have trouble with the monsterattack component.

Code: Select all

local newAttPow = spawnthing.monsterattack:getAttackPower()	
returns "attempt to index field 'monsterattack' (a nil value).

Any Ideas please ?
Last edited by cromcrom on Fri Jul 03, 2015 10:13 pm, edited 1 time in total.
A trip of a thousand leagues starts with a step.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: monsterattack component ?

Post by minmay »

the object has no component named "monsterattack"
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: monsterattack component ?

Post by cromcrom »

Well, the object is a monster, and calling the "monster" component (to get and set health, for example), does work.
Monsterattack component is defined as being tied to monsteraction component, this might be the problem ?
A trip of a thousand leagues starts with a step.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: monsterattack component ?

Post by minmay »

it's not "tied to", it's just a subclass

you need to look at the asset pack, there is not a single object with a component named "monsterattack". MonsterAttackComponents are often named "basicAttack" or "turnAttack" or the like.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: monsterattack component ?

Post by cromcrom »

Thanks a lot, it worked. It was confusing for me, because of the "class" stuff.
Learning, thanks again.

Cheers.
A trip of a thousand leagues starts with a step.
Azel
Posts: 808
Joined: Thu Nov 06, 2014 10:40 pm

Re: [solved] monsterattack component ?

Post by Azel »

If the Asset Pack does not contain a single component named "monsterattack" then doesn't that mean that the Scripting Reference is misleading?

http://www.grimrock.net/modding/scripti ... kComponent
MonsterAttackComponent (MonsterActionComponent)

Implements a monster attack action. A monster can have more than one attacks.
MonsterAttackComponent:getAccuracy()
MonsterAttackComponent:getAnimationSpeed()
MonsterAttackComponent:getAnimations()
MonsterAttackComponent:getAttackFromBehindAnimation()
MonsterAttackComponent:getAttackPower()
I'm not trying to contradict or be difficult, just understand it a bit better. The Asset Pack should simply implement the Scripting Reference, and in this case it doesn't seem to do that. Quite the opposite at first glance (albeit with inexperience eyes).

In other cases, the scripting reference works just fine as a one-to-one reference. For example:

http://www.grimrock.net/modding/scripti ... lComponent
CrystalComponent (Component)

Implements the animation and behavior of healing crystals.
CrystalComponent:activate()
CrystalComponent:deactivate()
CrystalComponent:getCooldown()
CrystalComponent:setCooldown(number)
With that, I can successfully type the following script command:
healing_crystal_01.crystal:setCooldown(60);

And it works! I see no indication as to why this works yet the MonsterAttack example fails. Well, other than the notation they add, "Implements a monster attack action. A monster can have more than one attacks." If I'm reading this correctly, they made a side note about the fact that Monster Attacks are referenced much more granular through an Attack Type (ie, "a monster can have more than one Attack Type"), thus the Scripting Reference should really say:

MonsterAttackType:getAttackPower()

Or no? I have to admit that I face a lot of these discrepancies which is why I resort to trial/error and "keep it simple" tactics, instead of studying the Asset Pack. Terrible excuse, I know, but I wanted to take this chance to type this out for myself and any other Modder newbies :mrgreen:
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: [solved] monsterattack component ?

Post by minmay »

The name of a component is completely separate from its class. If you do not specify a "name" field then it defaults to the class name in lowercase. The scripting reference explains this!
Entities, game objects (or just “go”) are the objects spawned in the dungeon either by placing them in the dungeon using the Dungeon Editor or spawning them dynamically from a script. For example, instances of buttons, pressure plates, teleporters and the party are all entities. Each entity has an id, a string which identifies the entity uniquely. You can refer to an entity by simply typing it’s id. For example, the following script prints the world coordinates of the entity with the id “party” to the console:

print(party:getWorldPosition())

Entities themselves do not have much useful functionality. Instead, interesting objects are made by adding components to the entities. For example, you would build an object with a 3D model that emits a continuous sound by adding a Model and a Sound component to an entity. A component is always created and owned by a single entity and components cannot exists without an entity. Each component has a class, e.g. Door and Model are classes, and a name which uniquely identifies the components inside its entity. By default the name of a component is the class name in lower case but you can pick any name when defining assets. Usually one entity can have only one component of a kind (for example, single Door component per entity) but some components do not have this restriction. For example, an entity can have any number of Model, Light, Particle and Sound components. In this case, each component must be explicitly and uniquely named (for example, “model1″, “model2″).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: [solved] monsterattack component ?

Post by cromcrom »

Glad to see this is confusing not only for me :lol:
Actually, I had tried the basicAttack stuff, but as I had written it 'basicattack", and not 'basicAttack', it had failed on me, so I thought I was utterly wrong and stupid :lol:
A trip of a thousand leagues starts with a step.
Post Reply