Questions about DSB/ESB

This forum is for the Lua scriptable clone of DM/CSB called Dungeon Strikes Back by Sophia. Use DSB to build your own highly customised games.

Moderator: Sophia

Forum rules
Please read the Forum rules and policies before posting.
Post Reply
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Yeah, that's probably why I will avoid it. :-) I can do basic stuff, but I'm not about to start ripping into the AI code... :-)

For passive wandering monsters, I think it would work to spawn a new critter on their death, so if the party kills them by walking into them, a new one is generated behind the party. Might work, I'll test it out.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Couple more questions:

1) Is there a way of preventing items being placed on tiles containing a pillar? With large pillars, it looks really weird that items sit on top of them when really there wouldn't be enough room.

2) For wallsets, which is drawn first: the ceiling or the floor?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:Is there a way of preventing items being placed on tiles containing a pillar? With large pillars, it looks really weird that items sit on top of them when really there wouldn't be enough room.
It seems like the easiest way to handle this would be to treat the square as a wall but tell not actually draw a wall. I'll figure out the best way to make that approach work.
Gambit37 wrote:For wallsets, which is drawn first: the ceiling or the floor?
Ceiling first, then the floor.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I've been experimenting with saving variables in a save game. You prevously suggested I do something like this in my startup:

Code: Select all

dsb_export("snp_data")
snp_data = {
   sound_feet = 0,
   sound_ambient = 0
}
During game play those variables might become pointers to sound entries, something like:

Code: Select all

snp_data = {
   sound_feet = snd.feet_on_stone
   sound_ambient = snd.ambient_wind
}
When re-loading a save game that stored these variables, DSB complains with:

Code: Select all

PROGRAM CRASH!
Location: 10 10 19
Reason: FMOD error 36
An invalid parameter was passed to this function. 
Stack Dump:
DSBmain
DSBgameloop
run_timers
lua.dsb_3dsound
play_3dsound
These are the functions used to play the footstep sounds, which work fine normally, but fail when restoring a save game:

Code: Select all

snd.feet_stone = { } -- Declare it as a table
	for num=1,4 do
      snd.feet_stone[num] = dsb_get_sound("FEET_ROCK" .. num, path .. "FTROC_P" .. num .. ".wav")
	end

function snd_footsteps(sound)
	local lev, x, y, face = dsb_party_coords()
	dsb_delay_func(1, function() dsb_3dsound(sound[dsb_rand(1, 4)], lev, x, y) end)
end

function h_party_move(have_party, delay)
	snd_footsteps(snp_data.sound_feet)
	return delay
end
I'm not really understanding why this isn't working. Should I be using the format "snp_data.sound_feet" or "snp_data[sound_feet]" to get the contents of these table entries? Either way, it doesn't seem to work.

I don't really know what I'm doing :-) :-P
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

You can't save table references like that. The snd table gets created anew every time you run DSB.
The references when you reload are invalid (because pointers have moved etc.), which is why DSB crashes.

What you can do is store the names as strings, such as:

Code: Select all

snp_data.sound_feet = "feet_on_stone"
Then do:

Code: Select all

function snd_footsteps(sound_name)
   local sound = snd[sound_name]
   local lev, x, y, face = dsb_party_coords()
   dsb_delay_func(1, function() dsb_3dsound(sound[dsb_rand(1, 4)], lev, x, y) end)
end
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Cool, it worked, thank you :-)

As you may have noticed, I do get rather confused between table references, asset pointers and properties of archs.... :cry: :shock: :? :lol:
User avatar
beowuuf
Archmastiff
Posts: 20687
Joined: Sat Sep 16, 2000 2:00 pm
Location: Basingstoke, UK

Re: Questions about DSB/ESB

Post by beowuuf »

All sounds as clear as mud to me!


Seriosuly though ,for someone who seemed to have been scared of any form of programming in this mode a year or less ago, you seem to be making enticing strides. Can't wait to see your work finalyl get shown off one of these days :)

Hopefully it might encourage other people who feel similarly, and that is the only reason they don't undertake their own dungeon
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I just push stuff about until it works... with lots of help from Sophia, of course! But thanks, yeah, I do feel I'm finally getting somewhere.... still a long way to go though. :-)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Is there any sort of shading adjustment that can be applied to floor and wall decorations at different view distances? Once you start using the level tinting options, the automatic shading can cause some strange problems with decorative items no longer blending correctly at different distances.
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

What sort of shading adjustment? What problems are you having?

Right now, there isn't really anything that can be adjusted, because it always sort of "just worked" so far. But, of course, what I'd end up opening up to customization depends on what you feel doesn't look right. :)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I'll prepare you some screenshots in a private message. :-)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I can't work out how to use on_expire and convert_expire. Well, I mean, adding them into the arch is obvious enough, but where do I set the countdown timer for the expire message to be fired?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

It doesn't quite work like that. It's based on an expire message, so you set the timer (so to speak) by adding a delay to the expire message.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Ah, right OK. I've been avoiding the whole area of messages so far and focusing on easy stuff. Looks like I can't avoid it any more ;-)
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Well, it's not hugely difficult. :)

There are two events that might interest you.
:arrow: on_spawn is called when an instance of that archetype is created.
:arrow: on_init is called when an instance of the archetype is first initialized, whether that's a spawn or a dsb_swap.
(Note that this is a full swap. Neither function is called after a qswap, because that simply changes an instance's archetype and nothing else)

So, here's some simple code:

Code: Select all

function expire_after_delay(arch, id)
   local exp_delay = arch.expire_delay
   if (exvar[id] and exvar[id].expire_delay) then
      exp_delay = exvar[id].expire_delay
   end
  dsb_msg(exp_delay, id, M_EXPIRE, 0)
end
If you set one of the above two properties (preferably on_init, but your mileage may vary) to expire_after_delay and set expire_delay as either an arch property or an exvar for a given instance, that will do what you want.

Code: Select all

-- instances of my_obj will receive an expire message after 20 ticks
obj.my_obj.on_init = expire_after_delay
obj.my_obj.expire_delay = 20
obj.my_obj.on_expire = do_something_else
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Aha, very nice, thank you :-)

While documenting Things, I came across this which made me ponder: One can specify stat and stat_up to boost a statistic. Do these only accept a single value, or can they take an array, eg:

Code: Select all

stat = {STAT_DEX, STAT_WIS, STAT_STR},
stat_up = {10,20,30}
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Currently, they can't. But I like that.
I'll hack that into the base code for 0.55. :)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Cooliio :-)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Is there a way of altering the positions of items drawn inside alcoves, at all 3 distances?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Not at present.
Tell me what you'd like to do and I can probably make something work.
(PM it if you'd like)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

I have a larger altar and the positions of contained items need to be adjusted to match it's shelf. I couldn't do it if I clone an alcove, so I tried it with two items: a simple decoration and a transparent alcove over the top. No matter how I adjust the tweak values for the mid and far views, the alcove position does not change. Do they work differently from normal wall items or am I doing something wrong?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

I think they're probably bugged. The code to generate the position for items drawn in an alcove is kind of a weird exception and it's off in its own little place in the renderer. I'll look into it and fix it for 0.55, probably.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

OK. I've sent you a couple of screenies to show the issue.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Is it possible to draw graphics and text directly into the viewport? If not, what would be the best way of doing that?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

The best way would probably be either as a condition that defines an overlay, or by defining your own custom zone in gui_info.
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

How do I add extra stuff to functions attached to a monster, such as on_die=setup_food_drop or on_move=monster_step?

Is it simply ok to move that function call into my custom function and call that instead, for example:

Code: Select all

(arch definition)
   on_move = handle_move
(end arch definition)


function handle_move(arch,id,group_leader)
     monster_step(arch, id, group_leader)
     ... more code ....
end
What if I wanted to modify *every* monsters on_move code so that every monster has something extra happen when they move? Do I just copy the function from base code and modify it?

Also, how would I add extra features to every monster's death -- would I need to copy all those setup_drop functions and add my features in there or is there a cleaner way?

Finally, I noticed the animation_timer in ESB. How does this work, and can I set it in code? For example, is it something I can set when a monster spawns to make sure it's timers dont't match other critters? I'm still seeing animations happening the same on groups of creatures, looks like they're dancing in time together :-)
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Also, you previously mentioned changing the speed of spells and missiles using dsb_set_flyreps(). It's listed in the Wiki, but with no details, and I can't find an example anywhere in the base code -- could you provide some info on how to do this and I'll update the Wiki?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

Gambit37 wrote:How do I add extra stuff to functions attached to a monster, such as on_die=setup_food_drop or on_move=monster_step?

Is it simply ok to move that function call into my custom function and call that instead
Yes, that is perfectly fine.
Gambit37 wrote:What if I wanted to modify *every* monsters on_move code so that every monster has something extra happen when they move? Do I just copy the function from base code and modify it?
Yes, or write your own with a wrapper like you did there.

Remy discovered a trick a while ago for overriding functions that's a little weird but can save your some headaches:

Code: Select all

orig_monster_step = monster_step
function monster_step(self, id, group_leader)
   -- Your code here
   orig_monster_step(self, id, group_leader)
   -- Put more code here
end
What this will do is create a reference to the DSB base code's monster_step called orig_monster_step and then replace the base code's monster_step with your own. By the time base/objects.lua is parsed, this code has executed, so any reference to monster_step will use yours.
Gambit37 wrote:Also, how would I add extra features to every monster's death -- would I need to copy all those setup_drop functions and add my features in there or is there a cleaner way?
The cleanest way is probably to write your own h_monster_died. Take a look at base/hooks.lua.
Gambit37 wrote:Finally, I noticed the animation_timer in ESB. How does this work, and can I set it in code? For example, is it something I can set when a monster spawns to make sure it's timers dont't match other critters?
The timer counts ticks, not frames or anything like that. So you'll have to set it to a high enough number depending on how many ticks each frame of your animation lasts.

You can set it in code via dsb_set_animtimer(id, value)
(If you set the timer in ESB, you can see this function call in the saved dungeon.lua)
Gambit37 wrote:Also, you previously mentioned changing the speed of spells and missiles using dsb_set_flyreps(). It's listed in the Wiki, but with no details, and I can't find an example anywhere in the base code -- could you provide some info on how to do this and I'll update the Wiki?
It's just dsb_set_flyreps(id, repetitions), where id must be an instance that is currently flying through the air. It will then execute its flying code repetitions times every time it updates. The default value is 1, of course, but setting it to a higher value will make fast or "instant hit" missiles.

At some point, I was going to add a flyreps property to object archs (or maybe attack methods?) to make this easier to invoke as part of the base code, but I apparently forgot to do that. :oops:
User avatar
Gambit37
Should eat more pies
Posts: 13714
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: Questions about DSB/ESB

Post by Gambit37 »

Great, thanks for all the info.
I was going to add a flyreps property to object archs (or maybe attack methods?) to make this easier to invoke as part of the base code
That would be really useful. Otherwise, I imagine the best way of using it would be to call dsb_set_flyreps() through an arch property like on_spawn?

Another question: how do I find out the open/closed state of a door (assuming I already have its inst ID). Also, if it's opening or closing?
User avatar
Sophia
Concise and Honest
Posts: 4239
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: Questions about DSB/ESB

Post by Sophia »

If a door is open, it's inactive. So a call to dsb_get_flag(id, GF_INACTIVE) which will return true if the door is open. As for whether the door is moving, an exvar called door_state will be nil if the door is open or closed, 1 if the door is opening, and 2 if the door is closing.
Post Reply