Page 1 of 2

The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 12:02 am
by John Smith
I was wondering what line of code I would use in a lua script to reassign a different name to an item. An example would be a longsword in an alcove would be renamed "John's Longsword". Adding onto that, if you can change the name then surely you can change the description as well.

Re: Renaming Items

Posted: Wed Dec 26, 2012 12:07 am
by Ixnatifual
Edit the items.lua in your scripts folder and add a clone that uses the regular longsword as a base.

Example:

Code: Select all

cloneObject {
  name = "cracked_short_bow",
  baseObject = "short_bow",
  uiName = "Cracked Short Bow",
  attackPower = 9,
  description = "While retaining some basic functionality, this weapon has seen better days. Perhaps you can find a similar bow in better condition."
}
When you clone the item, all the stuff you don't specify remains the same as per the original item.
For more details, check the item section here.

Re: Renaming Items

Posted: Wed Dec 26, 2012 12:10 am
by John Smith
Ixnatifual wrote:Edit the items.lua in your scripts folder and add a clone that uses the regular longsword as a base.

Example:

Code: Select all

cloneObject {
  name = "cracked_short_bow",
  baseObject = "short_bow",
  uiName = "Cracked Short Bow",
  attackPower = 9,
  description = "While retaining some basic functionality, this weapon has seen better days. Perhaps you can find a similar bow in better condition."
}
When you clone the item, all the stuff you don't specify remains the same as per the original item.
For more details, check the item section here.
Awesome. Thank you for the help.

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 1:06 am
by John Smith
I want a player to enter a room where once they step in they are locked inside until they kill all of the monsters. How would I go about having a lua script check to see if all the monsters in that room are dead? I would think it goes a little something like this:

Code: Select all

if 
crowern_4:getHealth(0) and
crowern_5:getHealth(0) and
crowern_6:getHealth(0) and
crowern_7:getHealth(0) and
crowern_8:getHealth(0) and
crowern_9:getHealth(0) then 
	dungeon_door_wooden_5:open()
else 
	dungeon_door_wooden_5:closed()
end
Only the door will be open before players get to that part of the dungeon when it should have been closed. The variable for the monster health must be off. How would I define a dead monster?

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 1:53 am
by Komag
a couple things:
close() not closed()
getHealth() == 0 not getHealth(0)

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 1:56 am
by John Smith
Komag wrote:a couple things:
close() not closed()
getHealth() == 0 not getHealth(0)
Oh. Silly mistakes. Thank you.

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 2:06 am
by John Smith
Huh. I made the fixes but the door still doesn't seem to open, even when I kill the crowerns.

Image

You're meant to hit the wall button to open the door, you step on the invisible pleasure plate and the door closes behind you. When all the monsters die the door should open.

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 5:53 am
by Komag
hmm, I didn't really think this through, just corrected those small errors. The real problem is that those monsters no longer exist after you have killed them, so any script can't find any monster to get the health from in the first place. You'll need to check for the existence of the monsters. If you want the door to open at the death of the last monster, it might be easiest to set up a custom monster (clone) with an onDie hook to run the script, and have the script work only if it never finds the monsters (only returns nil)

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 6:07 am
by Neikun
I think it'd be easier to place a counter, have ondie hooks that reference the counter, have the counter open the door when it reaches 0.
Each monster could decrement the counter on it's death.

Re: The John Smith Asks Questions Thread

Posted: Wed Dec 26, 2012 9:35 am
by Hariolor
John Smith wrote:Huh. I made the fixes but the door still doesn't seem to open, even when I kill the crowerns.

Image

You're meant to hit the wall button to open the door, you step on the invisible pleasure plate and the door closes behind you. When all the monsters die the door should open.
viewtopic.php?p=31998#p31998

I think in this link, Shroom wanted to do almost exactly what you're doing. Might be a good starting point.

Replace "snail" with "crowern" and that should just about get you there. xMin/xMax and yMin/yMax will define a box around your room. Then replace his door name with your own.

*edit: alternative idea...

might also try:

Code: Select all

if crowern_x == nil
and crowern_y == nil
and crowern_z == nil

then door_foo:open()
end