DSA: monster draining attributes
Moderator: Zyx
Forum rules
Please read the Forum rules and policies before posting. You may
to help finance the hosting costs of this forum.
Please read the Forum rules and policies before posting. You may

DSA: monster draining attributes
I've been asked how to make monsters draining attributes.
So I will try to give some explanations and an example of code for the DSA here in the next days.
So I will try to give some explanations and an example of code for the DSA here in the next days.
Last edited by Zyx on Fri May 13, 2005 2:14 pm, edited 2 times in total.
First, some basic concepts (from my own vision... Mr Stevens would probably get mad about my definitions!):
What's a DSA? (Designer-Specified Actuator)
*It's an actuator that can be placed in the dungeon.
*It can respond to certains events, like messages from pushbuttons and pressure pads, or spell casting, monster moving, monster attacking, object examining, feeding, etc.
*The effects of a DSA must be coded by the designer.
--------------------
Coding a DSA:
- a DSA have several states, they are like pages
- a DSA can respond to 12 kinds of messages (set/close/toggle x north/east/south/west -> 3 x 4 =12).
Each page or state has 12 lines, one for each kind of message.
To reference a particular line for a particular page, I'll say the number of the state, the letter of the message, and the number of the facing (0=north, 1=east, 2=south, 3=west)
Example: 0S0 is the line at state 0, message "Set", facing North.
-----------------
So what's the use of those references?
1) If a DSA receive a message from a pushbutton or a pressure pad, for example, you can determine which line of code will be executed.
2) When executing code, you can jump or gosub to other lines. You need to reference the lines.
All the DSA begin in state 0 by default. You can change a state manually or by code, but we won't need this in our case.
--------------
So what's the use of those lines?
To put code in them of course!
We'll see that in the next section.
--------
To create a DSA, here are the steps to be followed:
1) Design the DSA: click on the red button named DSA on the toolbar on the left. Select an unused slot, and click "Edit selected DSA". Give it a name and put the code of the DSA
2) Each level can have 32 types of DSA. So edit the level by clicking on the blue " = " on the toolbar on the left, then click on "Edit DSA List". Select an unused slot, click on "Replace selected DSA", and choose the DSA you just created.
3) Now you have to put an instance of this DSA in this level. Point on the desired tile, right click to open the "Edit wall/floor" dialog. Choose the facing (doesn't matter at all for a DSA), click "New", select "Actuator->
Designer-Specified Actuator"
4) Now you're in the "Edit DSA actuator" dialog. Click on "Select DSA type" and choose the type you just added on this level.
A DSA has two parameters, A and B. You can use them to hold values (integers) or targets.
5) Usually you'll need to put a pressure pad or a pushbutton somewhere targetting the tile of the DSA to activate it.
What's a DSA? (Designer-Specified Actuator)
*It's an actuator that can be placed in the dungeon.
*It can respond to certains events, like messages from pushbuttons and pressure pads, or spell casting, monster moving, monster attacking, object examining, feeding, etc.
*The effects of a DSA must be coded by the designer.
--------------------
Coding a DSA:
- a DSA have several states, they are like pages
- a DSA can respond to 12 kinds of messages (set/close/toggle x north/east/south/west -> 3 x 4 =12).
Each page or state has 12 lines, one for each kind of message.
To reference a particular line for a particular page, I'll say the number of the state, the letter of the message, and the number of the facing (0=north, 1=east, 2=south, 3=west)
Example: 0S0 is the line at state 0, message "Set", facing North.
-----------------
So what's the use of those references?
1) If a DSA receive a message from a pushbutton or a pressure pad, for example, you can determine which line of code will be executed.
2) When executing code, you can jump or gosub to other lines. You need to reference the lines.
All the DSA begin in state 0 by default. You can change a state manually or by code, but we won't need this in our case.
--------------
So what's the use of those lines?
To put code in them of course!
We'll see that in the next section.
--------
To create a DSA, here are the steps to be followed:
1) Design the DSA: click on the red button named DSA on the toolbar on the left. Select an unused slot, and click "Edit selected DSA". Give it a name and put the code of the DSA
2) Each level can have 32 types of DSA. So edit the level by clicking on the blue " = " on the toolbar on the left, then click on "Edit DSA List". Select an unused slot, click on "Replace selected DSA", and choose the DSA you just created.
3) Now you have to put an instance of this DSA in this level. Point on the desired tile, right click to open the "Edit wall/floor" dialog. Choose the facing (doesn't matter at all for a DSA), click "New", select "Actuator->
Designer-Specified Actuator"
4) Now you're in the "Edit DSA actuator" dialog. Click on "Select DSA type" and choose the type you just added on this level.
A DSA has two parameters, A and B. You can use them to hold values (integers) or targets.
5) Usually you'll need to put a pressure pad or a pushbutton somewhere targetting the tile of the DSA to activate it.
Last edited by Zyx on Sun May 22, 2005 11:55 pm, edited 1 time in total.
What we will do is create a DSA triggered when a monster attacks.
If you go to Edit->Global info, you get a "Game Global Information" dialog.
At the special locations, set the "Mosnter Attack Filter Location" to the tile where you will put this DSA.
Our DSA will then execute the line 0S0 each time a monster attempts an attack.
----------------------------------------
Here's a generic code to put at 0S0:
Code For state 0, line S0:
----------------------------------------------
Explanations:
This gets 20 parameters from the monster's attack event, and store them from slot 0 to slot 19. We have 100 slots to store information for personnal use.
For the list of those parameters, go Here
This will retrieve the value of slot 0 and put it on the stack.
->the value of slot 0 is the first parameter of the monster's attack event: it's the monster's ID. (we just stored the parameters of the attack to the first 20 slots, remember?)
->each object and monster have a unique ID. Several DSA operations need their ID to operate on them.
->the stack is an ordered list of values. You can add and remove values from the stack, and make basic operations on them, like suming or multiplying.
->When a DSA operation needs some parameters to work, it consumes the last entries of the stack.
For example, L20 L0 did put value 20 and value 0 to the stack, and &PARAM@ consumed the last two values, because it required:
1) the number of parameters to be retrieved (20)
2) the first slot of memory to fill (0).
This gets 7 parameters from the monster with the ID we retrieved before (that is, the monster currently attacking), and store them from slot 21 to slot 27.
Go here for the list of those parameters.
This a gosub to the line C0 of state 0. The DSA will execute all the code at line C0 (including other jumps and gosub from there), and when everything has been executed, it will go back to our current line and continue with the remaining operations.
(I'll post line C0 in the next section)
This updates 20 parameters to the monster's attack event. The values are provided by slots 0 to 19.
This updates 7 parameters to the monster with the ID we retrieved before. The values are provided by slots 21 to 27.
--------------------
Summary:
1) Line 0S0 retrieves the parameters of the attack, and the parameters of the attacking monster.
2) Then it will execute any code at line C0. (we will probably change the parameters of the attack or the monster here)
3) Finally it updates the parameters
If you go to Edit->Global info, you get a "Game Global Information" dialog.
At the special locations, set the "Mosnter Attack Filter Location" to the tile where you will put this DSA.
Our DSA will then execute the line 0S0 each time a monster attempts an attack.
----------------------------------------
Here's a generic code to put at 0S0:
Code For state 0, line S0:
Code: Select all
L20 L0 &PARAM@ L0 &@ L21 L7 &MONSTER@ GC0 L20 L0 &PARAM! L0 &@ L21 L7 &MONSTER!
Explanations:
Code: Select all
L20 L0 &PARAM@
For the list of those parameters, go Here
Code: Select all
L0 &@
->the value of slot 0 is the first parameter of the monster's attack event: it's the monster's ID. (we just stored the parameters of the attack to the first 20 slots, remember?)
->each object and monster have a unique ID. Several DSA operations need their ID to operate on them.
->the stack is an ordered list of values. You can add and remove values from the stack, and make basic operations on them, like suming or multiplying.
->When a DSA operation needs some parameters to work, it consumes the last entries of the stack.
For example, L20 L0 did put value 20 and value 0 to the stack, and &PARAM@ consumed the last two values, because it required:
1) the number of parameters to be retrieved (20)
2) the first slot of memory to fill (0).
Code: Select all
L0 &@ L21 L7 &MONSTER@
Go here for the list of those parameters.
Code: Select all
GC0
(I'll post line C0 in the next section)
Code: Select all
L20 L0 &PARAM!
Code: Select all
L0 &@ L21 L7 &MONSTER!
--------------------
Summary:
1) Line 0S0 retrieves the parameters of the attack, and the parameters of the attacking monster.
2) Then it will execute any code at line C0. (we will probably change the parameters of the attack or the monster here)
3) Finally it updates the parameters
Last edited by Zyx on Wed May 18, 2005 12:46 am, edited 2 times in total.
- Paul Stevens
- CSBwin Guru
- Posts: 4322
- Joined: Sun Apr 08, 2001 6:00 pm
- Location: Madison, Wisconsin, USA
Fixed.
Code For state 0, line C0:
----------------------------------------------
Explanations:
This puts the type of the monster into the stack.
Here are the 27 types:
List of monsters:
00 Scorpion
01 Slime Devil / Lemure
02 Giggler
03 Beholder / Flying eye
04 Rat / Hellhound
05 Ruster
06 Screamer
07 Rockpile
08 Ghost / Rive
09 Golem
10 Mummy
11 Flame
12 Skeleton
13 Couatl
14 Vexirk
15 Worm
16 Blue ogre / Antman
17 Wasp / Muncher
18 Knight
19 Zytaz
20 Water elemental
21 Oitu
22 Demon
23 Lord Chaos
24 Dragon
25 Lord Order
26 Grey Lord
This is a CASE statement. It uses the value in the stack, and according to this value, will jump to the corresponding line.
Since there are 27 types of monsters, I put 27 possible jumps.
Monster type 1 will jump to line 1S0 (state 1, line S0).
Monster type 2 will jump to line 2S0 (state 2, line S0).
Etc.
Since the page/state 0 is already used, monster type 0 will jump to line 27S0 (state 27, line S0) instead of 0S0.
If you leave the S0 line of each state in blank, then nothing will happen. No code will be executed, and the gosub will end. We will return to the line 0S0 from where we called the gosub, right after the GC0 instruction, and the rest of the line will be processed: it will update the parameters. Since we didn't change them, nothing special will happen. All the monsters will attack as usual.
However we're going to put some code at 12S0. For the skeletons.
--------------------
Summary:
1) According to the type of monster, we will execute a different line of code. For the skeleton, it will be line 12S0.
Edit: fixed some errors. Thanks Beowuuf.
Code For state 0, line C0:
Code: Select all
L1 &@ ??{(0,27S0)(1,1S0)(2,2S0)(3,3S0)(4,4S0)(5,5S0)(6,6S0)(7,7S0)(8,8S0)(9,9S0)(10,10S0)
(11,11S0)(12,12S0)(13,13S0)(14,14S0)(15,15S0)(16,16S0)(17,17S0)(18,18S0)(19,19S0)
(20,20S0)(21,21S0)(22,22S0)(23,23S0)(24,24S0)(25,25S0)(26,26S0)}
Explanations:
Code: Select all
L1 &@
Here are the 27 types:
List of monsters:
00 Scorpion
01 Slime Devil / Lemure
02 Giggler
03 Beholder / Flying eye
04 Rat / Hellhound
05 Ruster
06 Screamer
07 Rockpile
08 Ghost / Rive
09 Golem
10 Mummy
11 Flame
12 Skeleton
13 Couatl
14 Vexirk
15 Worm
16 Blue ogre / Antman
17 Wasp / Muncher
18 Knight
19 Zytaz
20 Water elemental
21 Oitu
22 Demon
23 Lord Chaos
24 Dragon
25 Lord Order
26 Grey Lord
Code: Select all
??{(0,27S0)(1,1S0)(2,2S0)(3,3S0)(4,4S0)(5,5S0)(6,6S0)(7,7S0)(8,8S0)(9,9S0)(10,10S0)
(11,11S0)(12,12S0)(13,13S0)(14,14S0)(15,15S0)(16,16S0)(17,17S0)(18,18S0)(19,19S0)(20,20S0)
(21,21S0)(22,22S0)(23,23S0)(24,24S0)(25,25S0)(26,26S0)}
Since there are 27 types of monsters, I put 27 possible jumps.
Monster type 1 will jump to line 1S0 (state 1, line S0).
Monster type 2 will jump to line 2S0 (state 2, line S0).
Etc.
Since the page/state 0 is already used, monster type 0 will jump to line 27S0 (state 27, line S0) instead of 0S0.
If you leave the S0 line of each state in blank, then nothing will happen. No code will be executed, and the gosub will end. We will return to the line 0S0 from where we called the gosub, right after the GC0 instruction, and the rest of the line will be processed: it will update the parameters. Since we didn't change them, nothing special will happen. All the monsters will attack as usual.
However we're going to put some code at 12S0. For the skeletons.
--------------------
Summary:
1) According to the type of monster, we will execute a different line of code. For the skeleton, it will be line 12S0.
Edit: fixed some errors. Thanks Beowuuf.
Last edited by Zyx on Tue Sep 13, 2005 11:02 am, edited 3 times in total.
Code For state 12, line S0:
----------------------------------------------
Explanations:
This will retrieve the value of slot 15 and put it on the stack.
->the value of slot 15 is the 16th parameter of the monster's attack event: it's the targetted character.
This gets 10 parameters from the targetted character with the ID we retrieved before (that is, the monster currently attacking), and store them from slot 60 to slot 69.
Check here for the list of the parameters.
Gosub to line 12C0. Here we will change some attributes of the character.
This updates 10 parameters to the targetted character. The values are provided by slots 60 to 69.
--------------------
Summary:
1) Line 12S0 retrieves the parameters of the targetted character.
2) Then it will execute any code at line C0. (we will probably change some attributes of the character here)
3) Finally it updates the parameters
Code: Select all
L15 &@ L60 L10 &CHAR@ GC0 L15 &@ L60 L10 &CHAR!
Explanations:
Code: Select all
L15 &@
->the value of slot 15 is the 16th parameter of the monster's attack event: it's the targetted character.
Code: Select all
L15 &@ L60 L10 &CHAR@
Check here for the list of the parameters.
Code: Select all
GC0
Code: Select all
L15 &@ L60 L10 &CHAR!
--------------------
Summary:
1) Line 12S0 retrieves the parameters of the targetted character.
2) Then it will execute any code at line C0. (we will probably change some attributes of the character here)
3) Finally it updates the parameters
Last edited by Zyx on Wed May 18, 2005 8:11 pm, edited 2 times in total.
Code For state 12, line C0:
----------------------------------------------
Explanations:
This will retrieve the value of slot 62 and put it on the stack.
->the value of slot 62 is the 3rd parameter of the targetted character: it's his life (hitpoints).
This compares the value 0 to the hitpoints of the character.
0 < hitpoints
This operation consumes both values from the stack and put another one, the result:
1 if it's true
0 if it's false
This is a conditional jump:
If the value in the stack is false (0), it will read the next operation (none in this case).
If the value in the stack is true (any other value than 0), it will jump to the line 12T0.
---------------------------
Summary:
1) Here we check that the character is alive.
2) If he's alive, we execute the code at line T0.
3) If he's dead or non existing, we do nothing.
Code: Select all
L0 L62 &@ &< ?JT0
Explanations:
Code: Select all
L62 &@
->the value of slot 62 is the 3rd parameter of the targetted character: it's his life (hitpoints).
Code: Select all
L0 L62 &@ &<
0 < hitpoints
This operation consumes both values from the stack and put another one, the result:
1 if it's true
0 if it's false
Code: Select all
?JT0
If the value in the stack is false (0), it will read the next operation (none in this case).
If the value in the stack is true (any other value than 0), it will jump to the line 12T0.
---------------------------
Summary:
1) Here we check that the character is alive.
2) If he's alive, we execute the code at line T0.
3) If he's dead or non existing, we do nothing.
Code For state 12, line T0:
----------------------------------------------
Explanations:
The Random operation chooses a random value between 0 and the value in the stack, which is 50.
This number will be the loss of stamina points of the character.
Since the number must be substracted to the stamina, we make it negative. (there is no direct operator for substraction in CSBuild, you need to add negative numbers instead)
This will retrieve the value of slot 68 and put it on the stack.
->the value of slot 68 is the 9th parameter of the targetted character: it's his stamina. (value is 10 times what is shown in DM engine)
we add the negative "stamina damage" to the stamina.
we update the slot 68.
---------------------------
Summary:
1) We substract a random value between 0 and 49 to the stamina of the character.
Code: Select all
L50 &RAND &NEG L68 &@ &+ L68 &!
Explanations:
Code: Select all
L50 &RAND
This number will be the loss of stamina points of the character.
Code: Select all
&NEG
Code: Select all
L68 &@
->the value of slot 68 is the 9th parameter of the targetted character: it's his stamina. (value is 10 times what is shown in DM engine)
Code: Select all
&+
Code: Select all
L68 &!
---------------------------
Summary:
1) We substract a random value between 0 and 49 to the stamina of the character.
Complete code:
The skeletons will drain you some stamina each time they attack you.
Code: Select all
0S0 = L20 L0 &PARAM@ L0 &@ L21 L7 &MONSTER@ GC0 L20 L0 &PARAM! L0 &@ L21 L7 &MONSTER!
0C0 = L1 &@ ??{(0,27S0)(1,1S0)(2,2S0)(3,3S0)(4,4S0)(5,5S0)(6,6S0)(7,7S0)(8,8S0)(9,9S0)
(10,10S0)(11,11S0)(12,12S0)(13,13S0)(14,14S0)(15,15S0)(16,16S0)(17,17S0)
(18,18S0)(19,19S0)(20,20S0)(21,21S0)(22,22S0)(23,23S0)(24,24S0)(25,25S0)
(26,26S0)}
12S0 = L15 &@ L60 L10 &CHAR@ GC0 L15 &@ L60 L10 &CHAR!
12C0 = L0 L62 &@ &< ?JT0
12T0 = L50 &RAND &NEG L68 &@ &+ L68 &!
- Paul Stevens
- CSBwin Guru
- Posts: 4322
- Joined: Sun Apr 08, 2001 6:00 pm
- Location: Madison, Wisconsin, USA
This code is overkill for the simple case where you want
skeletons to drain stamina. Zyx did it this way because
( if I read his mind correctly ) it opens up the
code to be easily adapted for other possibilities later. He
might want Screamers to add stamina and the 'hooks' will
already be written and ready for use. He might want
the rusters to steal your sword and the 'hooks' are already
there. This is good coding practice but it makes the example
a bit harder to understand for the novice.
Examples are good. Ask questions about this one and suggest
some others.
skeletons to drain stamina. Zyx did it this way because
( if I read his mind correctly ) it opens up the
code to be easily adapted for other possibilities later. He
might want Screamers to add stamina and the 'hooks' will
already be written and ready for use. He might want
the rusters to steal your sword and the 'hooks' are already
there. This is good coding practice but it makes the example
a bit harder to understand for the novice.
Examples are good. Ask questions about this one and suggest
some others.
I tried changing
to
which should have drained Mana. However it still drained the stamina and added to the mana. What is it I am doing wrong?
Code: Select all
L50 &RAND &NEG L68 &@ &+ L68 &!
Code: Select all
L50 &RAND &NEG L64 &@ &+ L64 &!
- Paul Stevens
- CSBwin Guru
- Posts: 4322
- Joined: Sun Apr 08, 2001 6:00 pm
- Location: Madison, Wisconsin, USA
It certainly looks like you are doing the right thing.
Do you know about the TimerTrace? In the Misc menu I believe.
You will be able to see the results of your DSA executeion one
step at a time and make sure it is doing what you want.
When all else fails, you send it to me with a recording to
prove that CSBwin has a bug.
Notice that there is no asterisk. Changing Strength is not
implemented. You need to ask me to do that if you want to
modify strength.
Do you know about the TimerTrace? In the Misc menu I believe.
You will be able to see the results of your DSA executeion one
step at a time and make sure it is doing what you want.
When all else fails, you send it to me with a recording to
prove that CSBwin has a bug.
Code: Select all
result[11] = Strength
implemented. You need to ask me to do that if you want to
modify strength.
- Paul Stevens
- CSBwin Guru
- Posts: 4322
- Joined: Sun Apr 08, 2001 6:00 pm
- Location: Madison, Wisconsin, USA
OK, Mr. Clark. Here is what I see in your dungeon.
At the bottom of the stairs to level 5 you have a pressure
pad that sends a Set 0 message to the Monter Attack Filter.
But of course no monster has attacked so there are no
attack parameters available. Nevertheless, because things
been set to zeero it seems to work quite well and the character's
mana is drained when he goes down the stairs.
The Attack filter neglected to load the attack parameters. So
there is no way to knwo which character is being attacked.
You neglected to copy the first part of Zyx's example.
Nevertheless, because everything had been set to zero you
drained the mana from character zero. Very lucky for you.
So everything seems to me to work quite well in spite of
your two errors. I tried it with version 9.8v48 and all seemed
well. Mana went down when the skeleton attacked. Mana went
down at the bottom of the stairs. Stamina stayed the same.
However, I tried both the CSB and DM graphics files from
release 9.8 and neither was the same as the one you
were using. And I got sequence errors with version9.8v48
which was the version you used. So something is different.
Why don't you get Version9.8v53 and fix the two problems
in you DSA and see how things go. If it is still a problem,
ship me the recording, the graphics file, and the dungeon file.
At the bottom of the stairs to level 5 you have a pressure
pad that sends a Set 0 message to the Monter Attack Filter.
But of course no monster has attacked so there are no
attack parameters available. Nevertheless, because things
been set to zeero it seems to work quite well and the character's
mana is drained when he goes down the stairs.
The Attack filter neglected to load the attack parameters. So
there is no way to knwo which character is being attacked.
You neglected to copy the first part of Zyx's example.
Nevertheless, because everything had been set to zero you
drained the mana from character zero. Very lucky for you.
So everything seems to me to work quite well in spite of
your two errors. I tried it with version 9.8v48 and all seemed
well. Mana went down when the skeleton attacked. Mana went
down at the bottom of the stairs. Stamina stayed the same.
However, I tried both the CSB and DM graphics files from
release 9.8 and neither was the same as the one you
were using. And I got sequence errors with version9.8v48
which was the version you used. So something is different.
Why don't you get Version9.8v53 and fix the two problems
in you DSA and see how things go. If it is still a problem,
ship me the recording, the graphics file, and the dungeon file.
-
- Artisan
- Posts: 178
- Joined: Wed Dec 17, 2003 1:39 am
- Location: Osaka, Japan
- Contact:
hi.
i've written a biased tutorial for CSBuild to have a DSA finally.
http://members.at.infoseek.co.jp/danmas ... /index.htm
some part of DSA explanation is taken from Zyx's post in this topic. Zyx, thanks for well formed DSA overview!
EDITED: fixed buggy image links.
i've written a biased tutorial for CSBuild to have a DSA finally.
http://members.at.infoseek.co.jp/danmas ... /index.htm
some part of DSA explanation is taken from Zyx's post in this topic. Zyx, thanks for well formed DSA overview!
EDITED: fixed buggy image links.
- Paul Stevens
- CSBwin Guru
- Posts: 4322
- Joined: Sun Apr 08, 2001 6:00 pm
- Location: Madison, Wisconsin, USA
Your demonstration of setting up a Champion Portrait
skipped over the very helpful Text Dialog option
"Edit Portrait". It avoids typing in those strings of
characters.
I followed some of your othe links and found some more
very nice documentation. All of these put together should
be sufficient for anyone to learn to ask an intelligent
question. Thanks everyone!!
skipped over the very helpful Text Dialog option
"Edit Portrait". It avoids typing in those strings of
characters.
I followed some of your othe links and found some more
very nice documentation. All of these put together should
be sufficient for anyone to learn to ask an intelligent
question. Thanks everyone!!