lua example


Questions, Explanations, Howtos

User avatar

Spider Stomper

Posts: 186

Joined: Friday, 8th March 2013, 13:27

Post Thursday, 30th May 2013, 19:20

lua example

I'm having a lot of fun with vaults but lua is still foreign to me. Could you help me with a very basic example?
In the vault "M" is supoused to be transparent wall and disapear if you join Xom.

  Code:
NAME:   lua_test
TAGS:   no_rtele_into no_item_gen no_monster gen temple_overflow_xom uniq_altar_xom
ORIENT:   float
WEIGHT: 3
KFEAT:   X = altar_xom
KITEM:  , = snozzcumber

.......
.nnn...
.n,M.X.
.nnn...
.......

Ziggurat Zagger

Posts: 5382

Joined: Friday, 25th November 2011, 07:36

Post Thursday, 30th May 2013, 20:25

Re: lua example

I'm afraid I can't help you, but I can recommend you post this in the contributions forum, where the people who know your answer are probably more likely to see it. They may see here too, but I'd try contributions.

For this message the author tasonir has received thanks:
Marbit
User avatar

Spider Stomper

Posts: 186

Joined: Friday, 8th March 2013, 13:27

Post Thursday, 30th May 2013, 21:02

Re: lua example

tasonir wrote:I'm afraid I can't help you, but I can recommend you post this in the contributions forum, where the people who know your answer are probably more likely to see it. They may see here too, but I'd try contributions.


I'm afraid I cannot move the post but if an admin considers that necesary, by all means do it.
User avatar

Abyss Ambulator

Posts: 1111

Joined: Monday, 18th March 2013, 23:23

Post Thursday, 30th May 2013, 21:13

Re: lua example

Hit the report button (the little exclamation point next to quote) and request a move.

hxy

Slime Squisher

Posts: 418

Joined: Friday, 11th February 2011, 13:09

Post Friday, 31st May 2013, 05:21

Re: lua example

(no experience with it, just guessing here)
define a "border" for your map, and use the "Murray drop" mechanism from one of the Sprint maps
so that when you reach the border, it triggers the code that replaces M

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Friday, 31st May 2013, 08:01

Re: lua example

Look through some of the existing altar vaults, I think there are some that have effects when you join a god.
User avatar

Abyss Ambulator

Posts: 1111

Joined: Monday, 18th March 2013, 23:23

Post Friday, 31st May 2013, 09:10

Re: lua example

There's an Ash vault where the walls turn transparent and you can see what Lair branches you'll have to deal with. It happens regardless of whether you join Ash or not, but you can probably get an idea of how it's supposed to work from that. And I'm sorry, but I have no idea what that vault is called.

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Friday, 31st May 2013, 11:21

Re: lua example

That won't hugely help with performing an action on joining a God.

But has the poster looked through the Lua triggerables documentation: https://crawl.develz.org/wiki/doku.php?id=dcss:help:maps:lua:triggerables
User avatar

Spider Stomper

Posts: 186

Joined: Friday, 8th March 2013, 13:27

Post Friday, 31st May 2013, 15:22

Re: lua example

mumra wrote:That won't hugely help with performing an action on joining a God.

But has the poster looked through the Lua triggerables documentation: https://crawl.develz.org/wiki/doku.php?id=dcss:help:maps:lua:triggerables


Yes, I have seen the obscure documentation on triggerables. It is a bit hard for me.
I had checked many vaults and I came with a solution but it was overly complicated: I plan to make give a message if the player steps on Xom's altar, wait a few turns, check if the player is following Xom and if so destroy the glass wall. I think I can manage to put this together but it is very messy, surely there is an easier trigger (so far I haven't found any in the existing vaults).

So far the code only checks if you step on the altar and if you are a demigod or follow Xom.
  Code:
{{
function callback.xom_warn_stepped(data, triggerable, triggerer, marker, ev)
  local x, y = marker:pos()

-- This checks to see if you worship Xom or are a demigod. If you do/are then
-- you get a negative message but if you don't, Xom invites you to worship
-- him in exchange for a small gift.

  if you.god() == "Xom" then
     crawl.god_speaks("Xom" , "No soup for you!")
  elseif you.race() == "Demigod" then
     crawl.god_speaks("Xom" , "Broken toy no fun!")
     dgn.grid(x, y, "floor")
  else
     crawl.god_speaks("Xom" , "I want a new toy, come to me and take your price!")
  end
end
}}

NAME:   lua_test
TAGS:   no_rtele_into no_item_gen no_monster gen temple_overflow_xom uniq_altar_xom
ORIENT:   float
WEIGHT: 3
KFEAT:   X = altar_xom
KITEM:  ,= snozzcumber

{{
local tm2 = TriggerableFunction:new{func="callback.xom_warn_stepped",
                                   repeated=false}
tm2:add_triggerer(DgnTriggerer:new{type="player_move"})
lua_marker('X', tm2)
}}

MAP
.......
.nnn...
.n,n.X.
.nnn...
.......
ENDMAP

Dungeon Master

Posts: 1531

Joined: Saturday, 5th March 2011, 06:29

Post Friday, 31st May 2013, 15:28

Re: lua example

Yes, the triggerables documentation is pretty bad. So far nobody has stepped up to improve it :)

I don't think there is actually a trigger for joining a religion. One could probably be added if there's an interesting reason to do so. But one way you could work around it is this:

- Once the player has stepped on the altar, start a timed trigger (you should be able to use master/slave to do this)
- Use this to check every turn if the player's religion has changed to see if they joined Xom
- Also check if the player is still on that square, if not you can stop the timed trigger (there's no point having a trigger going off every turn once the effect is over)
User avatar

Dungeon Master

Posts: 4031

Joined: Thursday, 16th December 2010, 20:37

Location: France

Post Friday, 31st May 2013, 17:09

Re: lua example

Moved to the coding forum
<+Grunt> You dereference an invalid pointer! Ouch! That really hurt! The game dies...

Return to Coding

Who is online

Users browsing this forum: No registered users and 7 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.