Page 89 of 396
Re: Ask a simple question, get a simple answer
Posted: Thu Sep 03, 2015 12:02 am
by Isaac
The cube wrote:How do i make a item that triggers a script on power attack?
Use the itemActionComponent's onAttack hook in the item's definition.
There you can either script what effect you want, or call a script entity on the map.
Example:
Code: Select all
onAttack = function(self) custom.script:action() end,
This ~placed in the item's power attack component, will call the action() function in the
custom object each time the power attack is used.
Re: Ask a simple question, get a simple answer
Posted: Thu Sep 03, 2015 7:50 am
by Azel
Azel wrote:The cube wrote:The player is unable to interact with the tiles where the chasms can spawn in any way, but he can see them.
The tile must look like a normal tile before the explosion, and have a chasm in it after the explosion.
The player is in the level below so he can not see the chasm appear.
Okay so I was able to get everything to work in a Dungeon by spawning a Pit and using some tricks. I know it's not an outdoor Chasm but I was limited on time today and I wanted to get you something at least semi-useful.
You can download both the playable dungeon and the editor project files here:
http://mystrock.com/files/chasms.zip
Tomorrow I will add the outdoor region and do the same thing with a forest_chasm. I tested this out (save/reload, etc) and everything works fine. I was able to simulate the item problem you mentioned (it didn't fall when the pit spawned), but a simple invisible teleporter solved it. You will notice a floor trigger where the pit appears. The trigger is a placeholder, but if for some reason a Chasm doesn't work the same as the Pit, then I have a function near the floor trigger that can be called to simulate the party falling down the chasm.
This was pretty fun; I hope to have the outdoor version ready by tomorrow night
Okay, I completed the Forest Chasm version. You can download the updated file from the same location:
http://mystrock.com/files/chasms.zip
This was done entirely using the out-of-box Editor (no modified Assets, etc). The only thing I changed from your original description, is I put a Chest on top of the Stone Ring. When the bomb goes off, I simulate the Chest falling down through the Chasm and "breaking" ... which reveals whatever items were inside (eg, a Gold Key).
Both the dungeon file and Editor files are available in the ZIP. Hope this helps!
Re: Ask a simple question, get a simple answer
Posted: Thu Sep 03, 2015 11:07 pm
by The cube
How do i define a monster that triggers a script when damaged? I tried this, but it didin't seem to work.
(The base object is ice elemental) (Game crashes when i try to spawn the object.)(I am trying to create a monster that gains health from normal attacks, but instantly dies to backstabs)
Code: Select all
{
class = "Monster",
resistances = {},
onDamage = function(self, damage, damageType)
if this.facing ~= party.facing then
this.setHealth(this.getHealth()+damage*2)
if this.getHealth() > this.getMaxHealth() then
this.setMaxHealth(this.getHealth())
end
else
this:die()
end
end,
},
Re: Ask a simple question, get a simple answer
Posted: Thu Sep 03, 2015 11:57 pm
by Isaac
The cube wrote:How do i define a monster that triggers a script when damaged?
There are some differences from Grimrock 1 scripting, with the new component model for objects.
*Also you have to replace the whole component when defining a new one; not just the properties added or needing replaced.
Code: Select all
defineObject {
name = "custom",
baseObject = "ice_guardian",
components = {
{
class = "Monster",
meshName = "ice_guardian_mesh",
hitSound = "ice_guardian_hit",
dieSound = "ice_guardian_die",
deathEffect = "death_icy",
hitEffect = "hit_ice",
capsuleHeight = 0.6,
capsuleRadius = 0.3,
collisionRadius = 0.8,
health = 400,
protection = 10,
evasion = 10,
flying = true,
exp = 500,
immunities = { "sleep", "blinded" },
traits = { "elemental" },
resistances = {},
onDamage = function(self, damage, damageType)
if self.go.facing ~= party.facing then
self.go.monster:setHealth(self.go.monster:getHealth()+damage*2)
if self.go.monster:getHealth() > self.go.monster:getMaxHealth() then
self.go.monster:setMaxHealth(self.go.monster:getHealth())
end
else
self.go.monster:die()
end
end,
}
}
}
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 5:18 pm
by AndakRainor
Is there a way to know if the current Weapon Set of a champion is the first or the second set ?
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 6:16 pm
by Isaac
AndakRainor wrote:Is there a way to know if the current Weapon Set of a champion is the first or the second set ?
The item slots are 1 & 2 and 11 & 12 ~respectively.
Code: Select all
party.party:getChampion(1)getItem(11)
...would be the PC's right [
their right] hand weapon in the second set; unless I'm misunderstanding your question.
____
I have my own question about this. What reason is there that Champion:getOtherHandItem(slot) returns the item in the opposite hand, instead of the item from the same hand in the opposite set? (Slot 11 instead of slot 2 for instance.)
Is this a bug? It would seem to make sense that the first function return the current items, and the second returns the alternates.
(Obviously it does say ~exactly what it does, but it's still counterintuitive IMO; though I can see it both ways... I guess it's a loop optimization? To check both hands in one pass ~with one value?)
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 6:32 pm
by AndakRainor
Isaac wrote:The item slots are 1 & 2 and 11 & 12 ~respectively.
____
I have my own question about this. What reason is there that Champion:getOtherHandItem(slot) returns the item in the opposite hand, instead of the item from the same hand in the opposite set? (Slot 11 instead of slot 2 for instance.)
Is this a bug? It would seem to make sense that the first function return the current items, and the second returns the alternates.
(Obviously it does say ~exactly what it does, but it's still counterintuitive IMO.)
But when I swap between the two hand sets, the current items in hands are always in slots 1 & 2. 11 & 12 are never the current set. So I have no information on which set is active, as shown by the default gui with the I / II icons. I try to show the same I / II icons in a custom gui but I can't tell which one should be drawn.
You are right about this confusing function! It's a good thing is a totally useless function to begin with in both case
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 6:43 pm
by Isaac
AndakRainor wrote:
But when I swap between the two hand sets, the current items in hands are always in slots 1 & 2. 11 & 12 are never the current set. So I have no information on which set is active, as shown by the default gui with the I / II icons. I try to show the same I / II icons in a custom gui but I can't tell which one should be drawn.
I'm missing something [probably very basic] then... If slots 11 & 12 are never the current set, why would they matter to the GUI? What's wrong about just rendering slots 1 & 2? (...and presumably, when the player swaps them, then slots 1 & 2 become ... Aha, you are asking how to detect the swap in realtime?)
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 6:53 pm
by AndakRainor
Yes, the default gui makes the difference between set 1 and set 2 by drawing different icons :
- g.drawGuiItem(""HandSlot1", x, y)
- g.drawGuiItem(""HandSlot2", x, y)
those have the "I" or "II" symbols highlighted...
Re: Ask a simple question, get a simple answer
Posted: Sun Sep 06, 2015 7:50 pm
by Isaac
Well my first thought was to assign an onUnequipItem connector to any item equipped; to signal when it was unequipped (and then remove the hook)... But that crashes the game... So to use that option, it looks like you would have to add the hook to the initial definition of every item.
*But it works.
Barring a better method, if every item had the onUnequipItem hook call ~notify your GUI that an item was unequipped, then you could check for a changed slot (was 1, now 11), and know the sets had been switched. But it seems rather involved. There should be a better way than this.
What about doing that slot check every time the mouse is clicked on the UI?
It seems possible to add an onDrawGui hook to the party, and call function to check the party's equipment on context.mouseDown(3), but I haven't managed a good check to detect the swap ~yet.
*context.mouseDown(3) seems undocumented. The usual number for 'left mouse button' is 0 [zero], but that continuously triggers while pressed... 3 seems to only trigger once per press.