How to... ?

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.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Mon Ful Ir's consolidated questions list (assume that I'll draw any and all graphics needed, provide the sounds, etc.):-

Petrifaction:
1) I need to draw an image to replace the default skull; you've provided me with the default skull image, so it's easy. I need a monster special attack that petrifies characters and leaves a statue instead of bones.
2) When that's done, I need two ways of turning petrified characters back to life:- an altar of depetrifaction (like an altar of vi) and/or one-use scrolls that do it. The idea is that people using this library will be able to use either or both methods in their dungeons.
3) (This is a "would be nice", as in, if it's really hard don't worry): When that's done, I need a range attack that other monsters can have that also turns characters to stone. If possible, this attack needs to be reflectable by a character who's using a mirrored shield. It would be ideal if the reflection was an short-duration "method" for the mirrored shield that the character needs to trigger at the right moment.

Underwater levels:
4) (Embarrassingly) I've got a nice "underwater" sound but I'm afraid I can't figure out the syntax to use it.

I've set up sound.lua like this:

Code: Select all

snd.water = dsb_get_sound("WATER", "mfi_sound/WATER.wav")
That seems to work now.

I've tried to add lines to underwater.lua that trigger the sound to play continually while underwater like this:

Code: Select all

function sys_enter_level(level)
   if (level == 1) then
      dsb_set_condition(PARTY, C_UNDERWATER, 10)
      dsb_sound(snd.water, true) = 2 -- New line by me
   else
      dsb_set_condition(PARTY, C_UNDERWATER, 0)
      dsb_stopsound(2) -- New line by me
   end
end
However it doesn't work. I think that I've got the syntax wrong for chan_handle, haven't I?

5) A water breathing effect that stops characters running out of air (for example, it might stop function underwater_air_func from being called). It wants a dotted line that goes round the character portrait (just like fireshield does it). In order to accommodate the needs of various different dungeon designers, I'd ideally like it to be available as a potion, a triggered effect on an item, or a permanent effect on an item. Would this best be done as another condition?
6) There's a problem in that a player could cheat by saving and then reloading the game, thereby resetting the "running out of air" counter. I've fixed that by preventing all saves underwater, but that creates a new problem for any designer who wants to make large underwater levels--stopping anyone from saving underwater at all might not be what's wanted. Is there a way of saving the current air supply situation for the party along with a saved game?
7) (This is a "would be nice", as in, if it's really hard don't worry): I want entering an underwater level to put out the party's torches and make them unusable. I'd do that by replacing all the party's torches with an object called "soaked torch" (cloned from burnt out torch). I can do that by putting a trigger at each underwater entrance that does it, but I think that solution isn't ideal for what Gambit37 wants to do with it... I think he'll have so many entrances to his underwater area that it'd be better if the torches could be spoiled on entering the underwater level from any point. Is there a way to add this effect to sys_enter_level?

General
This one's probably quite easy to solve!
8) I've got a floorflat called "statue" which looks nice, but I want characters not to be able to walk into it. At the moment they can. The code simply looks like this:

Code: Select all

obj.floorstatue = clone_arch(obj.movablewall, {
	class="STATUE",
	front=gfx.floorflat_statue
} )
How do I set the statue so that characters can't walk through it?
9) Please could you explain how to divide up this image:
Image
... into a DSB wallset?
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: How to... ?

Post by Sophia »

Mon Ful Ir wrote:1) I need to draw an image to replace the default skull; you've provided me with the default skull image, so it's easy. I need a monster special attack that petrifies characters and leaves a statue instead of bones.
2) When that's done, I need two ways of turning petrified characters back to life:- an altar of depetrifaction (like an altar of vi) and/or one-use scrolls that do it. The idea is that people using this library will be able to use either or both methods in their dungeons.
3) (This is a "would be nice", as in, if it's really hard don't worry): When that's done, I need a range attack that other monsters can have that also turns characters to stone. If possible, this attack needs to be reflectable by a character who's using a mirrored shield. It would be ideal if the reflection was an short-duration "method" for the mirrored shield that the character needs to trigger at the right moment.
Changing the death object is much easier in 0.46, also. Take a look at sys_character_die and see; I moved out all of the ugly housekeeping code into a single function call. This should be enough to get you going, at least on the death part of it. I also slipped in a revive_class property for the vi altar that makes the reviving easier-- clone alcove_vi and change revive_class to "STATUE" or whatever class you make the death statue and the altar should work just fine. The scroll will be more challenging. I can think about that some more, and if you need some more detailed examples I can write them up tomorrow or some time relatively soonish like that. The reflection is actually not that terribly difficult, but it takes things in a different direction and I think it'd also be best presented as a tutorial rather than just dumping code on you (teach a man to fish and all that) so I'll get around to that in the near future too.
Mon Ful Ir wrote:I think that I've got the syntax wrong for chan_handle, haven't I?
Yes, it's something that DSB returns, not something you need to set.

Code: Select all

function sys_enter_level(level)
   if (level == 1) then
      dsb_set_condition(PARTY, C_UNDERWATER, 10)
      g_water_channel = dsb_sound(snd.water, true)
   else
      dsb_set_condition(PARTY, C_UNDERWATER, 0)
      if (g_water_channel) then
         dsb_stopsound(g_water_channel) 
         g_water_channel = nil
      end
   end
end
g_water_channel is a global variable. In order to save this with your dungeon, add the following lines to your startup.lua:

Code: Select all

dsb_export("g_water_channel")
g_water_channel = nil
(You have to set the variable to nil because DSB will automatically set any exported nil to 0, which isn't what we want in this particular case. However, changing this would break so much of the base code that we'll just deal with it.)
Mon Ful Ir wrote:Would this best be done as another condition?
Yes, probably, or a character exvar. The problem of the "air counter" still being for the whole party still applies, though, unfortunately. If you need more help with this, I can do it as a tutorial eventually. It's too much code for me to write right now. :)
Mon Ful Ir wrote:There's a problem in that a player could cheat by saving and then reloading the game, thereby resetting the "running out of air" counter.
I've thought about this some and I think this is a bug in DSB. There is really no reason why sys_enter_level gets called on reload. I mean, I can think through and understand why I decided to do it this way, but you're not really entering the level on a reload. It's just a stub function in the default base code so it's not like I'm breaking anything changing it... so I think I will!

Here's a new DSB.exe that no longer calls sys_enter_level on reload, solving this issue. I've updated the main download as well.
Mon Ful Ir wrote:I want entering an underwater level to put out the party's torches and make them unusable. I'd do that by replacing all the party's torches with an object called "soaked torch" (cloned from burnt out torch) ... Is there a way to add this effect to sys_enter_level?
Of course. :D

I haven't tested this code, but I think something like this should do the trick nicely:

Code: Select all

for id in dsb_insts() do
   local idarch = dsb_find_arch(id)
   if (idarch.class == "TORCH") then
      dsb_swap(id, "torch_soaked")
   end
end
This iterates over every inst in the dungeon (faster than it sounds, don't worry) and if the class is "TORCH" it swaps it out for a soaked one.
Mon Ful Ir wrote:How do I set the statue so that characters can't walk through it?
I think part of the problem is that you've cloned obj.movablewall, which has all kinds of strange mechanics associated with it. Here's a basic DM2 pillar that I think you can easily edit to your needs:

Code: Select all

obj.dm2pillar = {
    type="FLOORUPRIGHT",
    class="DECO",
    col = true,
    front=gfx.dm2pillar
}
Setting col(lision) to true is what keeps the party from walking through it. This can also be a function, in case you wanted objects that could be conditionally passed through.
Mon Ful Ir wrote:Please could you explain how to divide up this image into a DSB wallset?
That image can't be made into a wallset because it's missing some views. Assuming you can get the entire thing, you'll need to cut off the perspective walls and save those as separate images (the sizes are the same as in RTC), and then cut the three long front walls into their own images. You can then add this as a standard (not "ext") DSB wallset, the syntax for which should be documented on the Wiki. (You don't need to worry about the "patches," those are a weird hack that isn't really used anymore)
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

You're a very patient lady.
Sophia wrote:Changing the death object is much easier in 0.46, also. Take a look at sys_character_die and see; I moved out all of the ugly housekeeping code into a single function call. This should be enough to get you going, at least on the death part of it. I also slipped in a revive_class property for the vi altar that makes the reviving easier-- clone alcove_vi and change revive_class to "STATUE" or whatever class you make the death statue and the altar should work just fine. The scroll will be more challenging. I can think about that some more, and if you need some more detailed examples I can write them up tomorrow or some time relatively soonish like that. The reflection is actually not that terribly difficult, but it takes things in a different direction and I think it'd also be best presented as a tutorial rather than just dumping code on you (teach a man to fish and all that) so I'll get around to that in the near future too.
No problem. I'll see what I can figure out for myself, but even though I'm improving noticeably, I'm still not exactly a coder, so support would be great when you have chance! :)
Sophia wrote:Yes, it's something that DSB returns, not something you need to set.
... However, changing this would break so much of the base code that we'll just deal with it.)
Okay, I'll load that into my dungeon tomorrow.
Sophia wrote:Yes, probably, or a character exvar. The problem of the "air counter" still being for the whole party still applies, though, unfortunately. If you need more help with this, I can do it as a tutorial eventually. It's too much code for me to write right now. :)
The "air counter" being for the whole party isn't really that much of a problem. Fireshield is an all-party-or-nothing effect too, and that seems to work fine in practice... I'll look forward to the tutorial when you have chance. :)
Sophia wrote:I've thought about this some and I think this is a bug in DSB. There is really no reason why sys_enter_level gets called on reload. I mean, I can think through and understand why I decided to do it this way, but you're not really entering the level on a reload. It's just a stub function in the default base code so it's not like I'm breaking anything changing it... so I think I will!
Now here's a major benefit over RTC. :) When I learned RTC I didn't have George Gilbert on tap to rewrite the base code when the situation demanded it!

I haven't tested this but understand it to mean that the air counter is now saved, so that's solved.
Sophia wrote:I haven't tested this code, but I think something like this should do the trick nicely:
When I test it tomorrow I'm sure it'll work. :D
Sophia wrote:I think part of the problem is that you've cloned obj.movablewall, which has all kinds of strange mechanics associated with it.
Yeah. I used the movablewall in the hope that this would make it possible to switch the statue on and off, but that's not essential.
Sophia wrote:That image can't be made into a wallset because it's missing some views. Assuming you can get the entire thing,
Well, that image is extracted out of the Conflux csbgraphics.dat. It's one of about six or so that I'd like to convert to DSB. But that image, plus ceiling and floors, is all I've got for that particular wallset at the moment.

I do have rtcwm, so I can convert it into a working RTC wallset with the extra views. (It takes some fiddling about, unfortunately, because rtcwm is a bit idiosyncratic.) I think if I do that I have to use the "ext" wallset code, don't I?
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Hmmmmmmm. While I think... do we want to soak every torch in the dungeon or just those in the characters' hands or inventory?
User avatar
Gambit37
Should eat more pies
Posts: 13720
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: How to... ?

Post by Gambit37 »

Mon Ful Ir wrote:Well, that image is extracted out of the Conflux csbgraphics.dat. It's one of about six or so that I'd like to convert to DSB.
It's from Knightmare originally. Personally, I'd use the original colourful source instead of the reduced Conflux versions. same goes for monsters you extracted. The Conflux extras are all in DM 16 colours and some are very badly dithered, so they don't look good to be honest. As a lot of Conflux graphics come from higher quality original sources, wouldn't it be better to work with those original sources?
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: How to... ?

Post by ian_scho »

Mon Ful Ir wrote:2) Dialogue screens for talking to NPCs. You'd have "dialogue" methods, giving one, two or three options for what the character says, and scripted NPC replies; the conversation would appear on the screen. (Subrenderer?)

The dialogue screens would let you write quite complex plots, did you ever play Planescape: Torment?
Events
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Thanks, both -- I'll get to what you say in a moment. In the meantime, here's the current version of this file:-

(removed -- please use a later file version)

Contents:

* For the first time, basic but fully functional underwater code. Doesn't put out torches yet.

Monsters:
* Ant, Giant
* Banshee
* Basilisk
* Beholder
* Bone Naga
* Bugbear
* Cerberus
* Cockatrice
* Chimera
* Death Knight
* Ettin
* Feyr
* Gargoyle
* Ghoul (with special attack)
* Gnoll
* Goblin
* Guardian
* Hobgoblin
* Kobold
* Leech, Giant
* Lizardman
* Medusa (snake-bodied)
* Medusa (woman-bodied)
* Mind Flayer (with special attacks)
* Minotaur
* Ogre Slug
* Orc
* Otyugh
* Poltergeist
* Shadow
* Skeleton (variant)
* Skeleton Warrior
* Sorceror (two graphic sets for this monster)
* Spider, Giant (two graphic sets for this monster)
* Tree (three graphic sets for this monster)
* Troll
* Umber Hulk
* Undead Beast
* Wight (with special attack)
* Witch
* Wraith
* Xorn
* Zombie
* Water weird (new with this version)
* Water elemental (new with this version)

Things
* Berries (consumable)
* Bottle
* Brigandine armour (torso and legs, male and female variants of each)
* Chalice (empty and full version)
* Crown
* Egg (consumable, although it doesn't look healthy)
* Feather
* Fruit (consumable)
* Gauntlets (ninja weapon)
* Hammer (fighter weapon)
* Heart (consumable)
* Leather armour (variant for female characters, torso and legs)
* Spear (fighter weapon)

Doors, keys and keyholes
* Brass door, with brass key and brass keyhole
* Ornate door
* Glass door
* Red key and keyhole
* Flower key and keyhole

Wallitems
* Altar
* Collapse (a seriously damaged wall)
* Cross (in a niche, but only with front graphic, not side and rear -- so needs solid walls to left and right if it's to be used)
* Deer Skull (mounted on wall)
* Painting (two kinds: male and female portraits)
* Skeletons (mounted on the wall, not monsters)
* A decorated stone skull
* Crossed swords
* Another painting (new with this version)
* Wall banners (two kinds) (new with this version)
* Tapestry (new with this version)

Floorflat
* A different kind of statue
* Chandelier (new with this version)

Misc
* A graphic for the Mind Flayer's Mind Blast

Sounds
* Underwater sound effect (new with this version)
* Mind blast sound effect (new with this version)

Graphics/sounds only
* No code for these yet, but there's graphics for another object (a mirrored shield), portraits for two champions, and wallitems illustrating the champions chained up as prisoners, which will eventually act as character-holders for them. There's also a sound effect which will be the attack sound for the new underwater monsters.
Last edited by Mon Ful Ir on Sun Dec 12, 2010 12:10 am, edited 1 time in total.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Gambit37 wrote:It's from Knightmare originally. Personally, I'd use the original colourful source instead of the reduced Conflux versions. same goes for monsters you extracted. The Conflux extras are all in DM 16 colours and some are very badly dithered, so they don't look good to be honest. As a lot of Conflux graphics come from higher quality original sources, wouldn't it be better to work with those original sources?
Well, I thought about that. But in several cases I decided to use the Conflux graphics mostly straight (I've done some re-colouring with a couple of them) because I'd like this library to be usable by people who're also using the original DM graphics. While some of the things are prettier, they're hopefully not so pretty as to look out of place.

I know there are some people (including you!) who're very clever with graphics and are producing much better-looking material for the clones, but I think those people will tend to want to draw things themselves.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

ian_scho wrote:Events
This is too complicated for an off-the-cuff reply! Thank you very much for the code. I'll look at it closely and see if I can figure out how it all works.
User avatar
Gambit37
Should eat more pies
Posts: 13720
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: How to... ?

Post by Gambit37 »

No problem, I understand about keeping things in DM style. Personally, I'm sick of playing custom dungeons with the original graphics now -- my patience for those grey walls has worn far too thin.... ;-)
ian_scho wrote:Events
Holy....! Wow. I can see DSB is powerful and much more flexible, but this is exactly why I prefer pointing and clicking to build stuff!
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: How to... ?

Post by ian_scho »

If you can understand how cascading style sheets work, Gambit, you have the mental capacity to play with stuff in lua :)
User avatar
Gambit37
Should eat more pies
Posts: 13720
Joined: Wed May 31, 2000 1:57 pm
Location: Location, Location
Contact:

Re: How to... ?

Post by Gambit37 »

CSS is just a bunch of simple rules. LUA, and all coding, is about logic and more in-depth problem solving. That feels too much like hard work when I'm trying to relax and be creative making a dungeon. It's the big thing holding me back from jumping into DSB because I know that I'll just get bored once I have to start writing lots of code.

By the way, that dungeon.lua you posted in the Events zip won't load in ESB 0.46.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: How to... ?

Post by Sophia »

Ian, that is really impressive. :shock:
You're going to scare away all the potential converts, though. ;)
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Gambit37 wrote:LUA, and all coding, is about logic and more in-depth problem solving. That feels too much like hard work when I'm trying to relax and be creative making a dungeon. It's the big thing holding me back from jumping into DSB because I know that I'll just get bored once I have to start writing lots of code.
Yeah, I've felt like that for ages. But I'm also frustrated with RTC's (many) limitations and for a long time, I've wanted to be able to produce some material that RTC just can't produce. I've thought about learning DSB for a while, but two things held me back:- first, the (previous) lack of a graphical editor and second, I kept thinking to myself, "Wouldn't it be nice if I could just use someone else's code to do the complicated things, and create my dungeon by pointing and clicking?"

This thread started when I suddenly and unexpectedly had some time to be the "someone else". I'm recovering from surgery, so I'm physically incapacitated for a while, and I can hardly go out of the house because I'm not supposed to meet anyone who might infect me with anything, but I can think reasonably straight, so there's no reason why I can't do this. I've just got to learn to make sense of the code.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Today's version:

(removed -- please use a later file version)

Changelog:
* Underwater monsters now make a "splash" sound when they hit
* Offsets for floorupright_statue, broken in previous update, now fixed
* Wraiths now have a mana-draining special attack
* New monster: Shambling Mound
* New underwater monster: Seaspirit
* New thing: obj.petrified (part of the yet-to-be-written petrifaction mechanics)
* Some stat changes to the various monsters (this will be an ongoing project)
Last edited by Mon Ful Ir on Sun Dec 12, 2010 12:11 am, edited 1 time in total.
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: How to... ?

Post by ian_scho »

Some cool ideas. I like the updates!
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Thanks. I'm afraid that owing to a stupid typo by yours truly ("shamblingmount" instead of "shamblingmound"), that most recent version won't actually load into DSB. Fixed for the next update tomorrow.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Ian_scho, is there any documentation for your "events" code? I think I can see what you're doing and it's absolutely pregnant with possibilities, but I'm afraid I'm not a programmer, and I'm having all kinds of trouble adapting it to my purposes.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Sophia, I'm afraid I'm struck with the petrifaction code. Here's what I have:-

obj.petrified is the statue left when a character dies. It's written like this, with the two associated functions:-

Code: Select all

obj.petrified = {
	name="PETRIFIED",
	type="THING",
	class="PETRIF",
	mass=15,
	icon=gfx.thing_icon_petrified,
	dungeon=gfx.thing_dungeon_petrified,
	max_throw_power=18,
	impact=2
}

function obj.petrified:namechanger(id, who_look)
	if (exvar[id] and exvar[id].owner) then
		return dsb_get_charname(exvar[id].owner) .. " " .. self.name
	else
		return nil
	end
end

function obj.petrified:on_click(id)
	if (exvar[id] and exvar[id].in_altar) then
		return true
	else
		return nil
	end
end
obj.petrif_alcove is the thing that brings an obj.petrified back to life. It's written like this, with one associated function:-

Code: Select all

obj.alcove_petrif = {
	type="WALLITEM",
	class="ALCOVE",
	front=gfx.wallitem_petrif_front,
	side=gfx.wallitem_petrif_side,
	on_click=use_petrif_alcove,
	msg_handler = vi_altar_msg_handler,
	revive_class = "PETRIF",
	drop_zone=true,
	ignore_empty_clicks=true
}

function use_petrif_alcove(arch, id, what)

	wallitem_click(arch, id, what)
	if (not what) then return end
	
	local rev_arch = dsb_find_arch(what)
	local revive_class = "PETRIF"
	if (arch.revive_class) then revive_class = arch.revive_class end
	if (rev_arch.class == revive_class) then
	    if (exvar[what] and exvar[what].owner) then
			dsb_sound(snd.zap)
			exvar[what].in_altar = true
			dsb_msg(4, id, M_NEXTTICK, what)
		end
	end
end
The actual petrifaction comes from sys_character_petrified which looks like this:-

Code: Select all

function sys_character_petrified(ppos, who, mouse_drop)
	
	drop_all_items_and_magicshields(ppos, who, mouse_drop)

	local lev, xc, yc = dsb_party_coords()
	local tile_pos = dsb_ppos_tile(ppos)
	local petrified_id = dsb_spawn("petrified", lev, xc, yc, tile_pos)
	exvar[petrified_id] = { owner = who }

end
And finally, function petrif_special_attack is:-

Code: Select all

function petrif_special_attack(arch, id, ppos, who, dtype, damage)
   sys_character_petrified(ppos, who)
end
When clawed by a cockatrice, the character obligingly drops all his items and leaves a statue of himself. Unfortunately the character doesn't actually die!

There's something I'm missing. Please could you enlighten me?

Also, I can't seem to see where I'm supposed to load in my alternative version of top_dead.pcx. :\
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: How to... ?

Post by Sophia »

Mon Ful Ir wrote:When clawed by a cockatrice, the character obligingly drops all his items and leaves a statue of himself. Unfortunately the character doesn't actually die!

There's something I'm missing. Please could you enlighten me?
The problem here is that the character never actually dies because you never actually kill the character. The sys_* functions have that name because they are special hooks that are called by the system, but the naming is just so you can tell that's what they are. There is nothing special about naming a function sys_, and, in fact, you probably shouldn't, because it'll just get confusing. In order to make the character actually die, we have to set the hp to 0. Then the character will die and it'll call sys_character_die as normal. So, all the tricky code has to, in actuality, go inside of sys_character_die.

Code: Select all

function sys_character_die(ppos, who, mouse_drop)
   
   drop_all_items_and_magicshields(ppos, who, mouse_drop)
   
   local death_object
   use_ch_exvar(who)
   if (ch_exvar[who].petrified) then
      death_object = "petrified"
      dsb_replace_topimages(who, nil, nil, "top_dead_petrified")
      ch_exvar[who].petrified = nil
   else
      death_object = "bones"
      dsb_replace_topimages(who, nil, nil, 0)
   end

   local lev, xc, yc = dsb_party_coords()
   local tile_pos = dsb_ppos_tile(ppos)
   local dead_id = dsb_spawn(death_object, lev, xc, yc, tile_pos)
   exvar[dead_id] = { owner = who }

end
That code checks if a ch_exvar (that is, a character exvar) exists called petrified. Just like exvars with instances, character exvars are used with characters to store all kinds of data that the core engine can't but is relevant to the game. If the exvar exists, we set the new death_object and change the top image. Otherwise, we assert the default state.

Then, in our special attack, this means all we need to do is set the "petrified" special character exvar and then kill the character.

Code: Select all

function petrif_special_attack(arch, id, ppos, who, dtype, damage)
   use_ch_exvar(who)
   ch_exvar[who].petrified = true
   dsb_set_bar(who, HEALTH, 0)
end
Mon Ful Ir wrote:Also, I can't seem to see where I'm supposed to load in my alternative version of top_dead.pcx. :\
You can load the image in graphics.lua just like any other custom graphic. In the code above, it's expecting the image to be in gfx.top_dead_petrified.
User avatar
Sophia
Concise and Honest
Posts: 4240
Joined: Thu Sep 12, 2002 9:50 pm
Location: Nowhere in particular
Contact:

Re: How to... ?

Post by Sophia »

I just noticed that the current version of DSB doesn't provide a use_ch_exvar function. It'll be in the next version, but in the meantime, here's one for your startup.lua:

Code: Select all

function use_ch_exvar(who)
   if (not ch_exvar[who]) then ch_exvar[who] = { } end
end
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: How to... ?

Post by ian_scho »

Mon Ful Ir wrote:Ian_scho, is there any documentation for your "events" code? I think I can see what you're doing and it's absolutely pregnant with possibilities, but I'm afraid I'm not a programmer, and I'm having all kinds of trouble adapting it to my purposes.
If it were me starting off I'd go for the simplest of dialogue trees. I'd have a persons image on the left, and the text flowing directly to the right of it. All of the other stuff would be OTT. If you like I could do a more complete example/demo dungeon of this stuff, but it would take me a little while - so if you're patient :lol:

The examples, commented or otherwise, are pretty much a description of what they can do. I doubt the commented ones all work as they came out of another dungeon! Basically as soon as you can throw a bit of LUA code together you... are... off...

i love the 'pregnant with possibilities' quote.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Thank you, Sophia!

For anyone who might be following this code, the dsb 0.46 syntax is actually dsb_replace_topimages and not dsb_set_topimages, so Sophia's code for sys_character_die should read:

Code: Select all

function sys_character_die(ppos, who, mouse_drop)
   
   drop_all_items_and_magicshields(ppos, who, mouse_drop)
   
   local death_object
   use_ch_exvar(who)
   if (ch_exvar[who].petrified) then
      death_object = "petrified"
      dsb_replace_topimages(who, nil, nil, "top_dead_petrified")
      ch_exvar[who].petrified = nil
   else
      death_object = "bones"
      dsb_replace_topimages(who, nil, nil, 0)
   end

   local lev, xc, yc = dsb_party_coords()
   local tile_pos = dsb_ppos_tile(ppos)
   local dead_id = dsb_spawn(death_object, lev, xc, yc, tile_pos)
   exvar[dead_id] = { owner = who }

end
With this correction, the cockatrice now petrifies with a claw attack. However, my code for the altar of depetrifaction doesn't work for some reason.

ian_scho wrote:If it were me starting off I'd go for the simplest of dialogue trees. I'd have a persons image on the left, and the text flowing directly to the right of it. All of the other stuff would be OTT. If you like I could do a more complete example/demo dungeon of this stuff, but it would take me a little while - so if you're patient :lol:

The examples, commented or otherwise, are pretty much a description of what they can do. I doubt the commented ones all work as they came out of another dungeon! Basically as soon as you can throw a bit of LUA code together you... are... off...

i love the 'pregnant with possibilities' quote.
Thank you; I liked it myself. :)

I agree: the dialogue tree needs the character's portrait at the top left, the text in the middle and options at the bottom. I'd definitely be grateful for your example!

Here is today's version of the dungeon:

(removed -- please use a later file version)

* Code change: Player can now save the game underwater. But player can no longer sleep underwater.
* Code change: The cockatrice now petrifies by attack.
* More stat changes to monsters (ongoing)
* Shambling mound graphics fixed (broken in last update)
* New flooritem: minotaur statue
* New wallitem: altar of depetrifaction (not working yet)
* New wallitem: prisoner_yvonne (a live character held prisoner--when clicked she can join the party)
* New wallitem: prisoner_wort (a live character held prisoner--when clicked he can join the party)

The prisoner champions still need code updates. I wanted to use ian_scho's "events" code to create a screen full of dialogue with character backstories and a choice to add the character to the party or leave them behind, but I just can't seem to make it work. At the moment the offer to join the party is called "ressurect", which I need to change to "join", and when they join the party they need to disappear from the wall they're chained to, which doesn't happen at the moment.
Last edited by Mon Ful Ir on Sun Dec 12, 2010 12:12 am, edited 1 time in total.
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Today's questions for Sophia:-

1) My current code executed when going underwater looks like this:-

Code: Select all

function sys_enter_level(level)
   if (level == 1) then
      dsb_set_condition(PARTY, C_UNDERWATER, 10)
      g_water_channel = dsb_sound(snd.water, true)
      for id in dsb_insts() do
         local idarch = dsb_find_arch(id)
         if (idarch.class == "TORCH") then
         dsb_swap(id, "torch_soaked")
      end
   end
   else
      dsb_set_condition(PARTY, C_UNDERWATER, 0)
      if (g_water_channel) then
         dsb_stopsound(g_water_channel)
         g_water_channel = nil
      end
   end
end
It turns all the torches in the dungeon into soaked torches. How can I restrict it just to torches the party is carrying or has in its inventory?

2) I'm afraid there's something wrong with my altar of depetrifaction and I can't tell what it is. :\ Can you tell why it doesn't bring a petrified character back to life?

Thanks!
User avatar
Joramun
Mon Master
Posts: 925
Joined: Thu May 25, 2006 7:05 pm
Location: The Universe

Re: How to... ?

Post by Joramun »

MFI, I get a crash when loading your dungeon :

Code: Select all

Parsing D:\Jeux\DM\DSB\dungeons\mfi_dungeon/dungeon.lua
FATAL LUA ERROR: Lua Function sys_tick: base/system.lua:583: attempt to perform arithmetic on global 'g_last_party_move' (a boolean value)
I'm using the fixed dsb0.46 exe

EDIT: And it's not doing it when I'm not. Weird.
Last edited by Joramun on Thu Dec 09, 2010 5:19 pm, edited 1 time in total.
What Is Your Quest ?
User avatar
Joramun
Mon Master
Posts: 925
Joined: Thu May 25, 2006 7:05 pm
Location: The Universe

Re: How to... ?

Post by Joramun »

ian_scho wrote:
Mon Ful Ir wrote:2) Dialogue screens for talking to NPCs. You'd have "dialogue" methods, giving one, two or three options for what the character says, and scripted NPC replies; the conversation would appear on the screen. (Subrenderer?)

The dialogue screens would let you write quite complex plots, did you ever play Planescape: Torment?
Events
Your system is so complex Ian !!!! It's amazing, awesome and awfully scary.
What Is Your Quest ?
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Joramun wrote:MFI, I get a crash when loading your dungeon... I'm using the fixed dsb0.46 exe

EDIT: And it's not doing it when I'm not. Weird.
Can't explain that, Joramun, sorry.
Joramun wrote:Parsing D:\Jeux\DM\DSB\dungeons\mfi_dungeon/dungeon.lua
Tu ne serais pas français? Où francophone?
User avatar
Joramun
Mon Master
Posts: 925
Joined: Thu May 25, 2006 7:05 pm
Location: The Universe

Re: How to... ?

Post by Joramun »

Je suis français !! :wink:
C'est un bug de DSB, il n'y a pas de souci, ça ne vient pas de ton donjon de test par ailleurs très impressionnant !!
What Is Your Quest ?
Mon Ful Ir
Adept
Posts: 221
Joined: Sat Jan 07, 2006 1:54 am
Location: Britain

Re: How to... ?

Post by Mon Ful Ir »

Plop donc, les français! :D Les britanniques vous saluons!

Merci beau, j'espère qu'on le trouvera utile.
User avatar
ian_scho
High Lord
Posts: 2806
Joined: Fri Apr 07, 2006 8:30 am
Location: Zaragoza, Spain

Re: How to... ?

Post by ian_scho »

Joramun wrote:Your system is so complex Ian !!!! It's amazing, awesome and awfully scary.
Unfortunately that's how my brain works...

I'm sure *all* of you can do better though! I wrote it and a few other things so that I can actually build a dungeon as fast as possible.
Post Reply