How can I code this situation?
I would like to have some characters or monsters appear on a map only after the main character receives a particular quest requiring to seek out the other char/monster. Otherwise, I would like the main character to be able to walk on those same screens and nothing will be there. I have seen a few examples in d-mods, but it seemed more like a random chance to see a character, rather than have it on the map right away after getting a quest, and not until then.
I'm guessing I would need global variables with if/else statements and maybe more. Am I on the right track?
I'm guessing I would need global variables with if/else statements and maybe more. Am I on the right track?
Yes, you are.
if (&questvariable == 1)
{
//Monster appears
}
I think that is all that's needed. Apart from setting all the monster's stats and stuff in place of the comment.
if (&questvariable == 1)
{
//Monster appears
}
I think that is all that's needed. Apart from setting all the monster's stats and stuff in place of the comment.
Thanks. I suppose that would be attached to the screen where I want the monster. Now in the case of an NPC, how can I make the NPC go away once its usefulness is done, but not before the main character leaves that screen?
Have the NPC walk off the screen with a move() command, then if you want to kill it off, use sp_active();
So, it would be something like this:
move_stop(&npc, 2, -100, 1);
sp_active(&npc, 0);
If the sp_active(); value of a sprite is 0, then the sprite is 'dead'. It disappears. So, that's why it's a good idea to have it walk off the screen before it vanishes. Also, note that once you inactivate something, you can't activate it again. It is gone forever.
So, it would be something like this:
move_stop(&npc, 2, -100, 1);
sp_active(&npc, 0);
If the sp_active(); value of a sprite is 0, then the sprite is 'dead'. It disappears. So, that's why it's a good idea to have it walk off the screen before it vanishes. Also, note that once you inactivate something, you can't activate it again. It is gone forever.
The sprite won't actually be gone forever, though, it'll be there when you re-enter the screen. To get him stay away his editor type needs to be changed.
sp_editor_num(¤t_sprite);
editor_type(&return,1);
1 stands for kill sprite completely. Check the DinkC reference for a list of different states.
These commands are pretty cool, they're used primarily for changes in the map such as burnt trees, killed monsters, destroyed barrels, but are useful for other things as well. Having a sprite introduce itself, for example, or a quest like collecting 5 mushrooms could be easily done with editor_seq(); or editor_frame(); without wasting globals.
//Example
void talk()
{
freeze(1);
int &getnum = sp_editor_num(¤t_sprite);
int &num = editor_seq(&getnum,-1);
if (&num == 0)
{
say_stop("`%Hi, I'm Mister Questman, your friendly town questgiver.",¤t_sprite);
say_stop("Nice to meet you, I'm Dink.",1);
editor_seq(&getnum,1);
}
if (&num == 1)
{
say_stop("`0Hi, Dink.",¤t_sprite);
say_stop("Hi, Mister Questman.",1);
}
unfreeze(1);
}
sp_editor_num(¤t_sprite);
editor_type(&return,1);
1 stands for kill sprite completely. Check the DinkC reference for a list of different states.
These commands are pretty cool, they're used primarily for changes in the map such as burnt trees, killed monsters, destroyed barrels, but are useful for other things as well. Having a sprite introduce itself, for example, or a quest like collecting 5 mushrooms could be easily done with editor_seq(); or editor_frame(); without wasting globals.
//Example
void talk()
{
freeze(1);
int &getnum = sp_editor_num(¤t_sprite);
int &num = editor_seq(&getnum,-1);
if (&num == 0)
{
say_stop("`%Hi, I'm Mister Questman, your friendly town questgiver.",¤t_sprite);
say_stop("Nice to meet you, I'm Dink.",1);
editor_seq(&getnum,1);
}
if (&num == 1)
{
say_stop("`0Hi, Dink.",¤t_sprite);
say_stop("Hi, Mister Questman.",1);
}
unfreeze(1);
}
Thanks, scratcher. That first bit sounds more like what I want. Should I use that in combination with what DinkDude mentioned? Or in place of it?
In the larger example, after Dink talks to the sprite the first time, what causes &num to change from 0 to 1 so that the second group of speech is used?
In the larger example, after Dink talks to the sprite the first time, what causes &num to change from 0 to 1 so that the second group of speech is used?
In response to your second question, nothing does in that example. You would need to change &num either there or in another script, but be careful of doing something like this:
if (&num == 0)
{
//do stuff
&num = 1;
}
if (&num == 1)
{
//do other stuff
}
because then both will happen. I often do this
Either use a goto command to skip to the end or put if (&num == 1) before if (&num == 0).
Edit: Sorry, no brains tonight. To change &num you'd need to do this:
&num = 1;
editor_seq(&getnum, &num);
That way &num is saved in editor_seq(), so when you speak to the sprite again (even after leaving the screen) &num will still be 1.
if (&num == 0)
{
//do stuff
&num = 1;
}
if (&num == 1)
{
//do other stuff
}
because then both will happen. I often do this

Either use a goto command to skip to the end or put if (&num == 1) before if (&num == 0).
Edit: Sorry, no brains tonight. To change &num you'd need to do this:
&num = 1;
editor_seq(&getnum, &num);
That way &num is saved in editor_seq(), so when you speak to the sprite again (even after leaving the screen) &num will still be 1.
Well, editor_seq(&getnum,1); changes the value of editor_seq();, &num is just used to tell us what that value is. It doesn't need to be changed in the middle of the script, unless you really want to run into the problem you mentioned. =)
In the case of most (all?) attributes, a positive number will change the value, a negative number will tell you what the value is without changing it.
Thanks, scratcher. That first bit sounds more like what I want. Should I use that in combination with what DinkDude mentioned? Or in place of it?
The engine doesn't remember changes to the sprite's properties, except for the sprite numbers. sp_active only does anything when the player is on the screen, it won't have an effect on how things look the next time you enter it. On the other hand, the editor numbers won't do anything to the sprite right away, they only change how things are the next time the screen is drawn.
In the case of most (all?) attributes, a positive number will change the value, a negative number will tell you what the value is without changing it.
Thanks, scratcher. That first bit sounds more like what I want. Should I use that in combination with what DinkDude mentioned? Or in place of it?
The engine doesn't remember changes to the sprite's properties, except for the sprite numbers. sp_active only does anything when the player is on the screen, it won't have an effect on how things look the next time you enter it. On the other hand, the editor numbers won't do anything to the sprite right away, they only change how things are the next time the screen is drawn.
You're right in your example, as I said, I have no brains tonight
I usually do this bit:
int &getnum = sp_editor_num(¤t_sprite);
int &num = editor_seq(&getnum,-1);
in the main procedure so I'd need to change &num because otherwise if I speak to the NPC without leaving the screen &num wouldn't have changed. I believe main is only run when the screen is first drawn? Whatever.
And I think only -1 tells you what a value is, you can set attributes to other negative numbers.

I usually do this bit:
int &getnum = sp_editor_num(¤t_sprite);
int &num = editor_seq(&getnum,-1);
in the main procedure so I'd need to change &num because otherwise if I speak to the NPC without leaving the screen &num wouldn't have changed. I believe main is only run when the screen is first drawn? Whatever.
And I think only -1 tells you what a value is, you can set attributes to other negative numbers.
Me as well, but I usually add &num = editor_seq(&getnum,-1); in the talk procedure. I like this way more, but either works.
And I think only -1 tells you what a value is, you can set attributes to other negative numbers.
You may be right, I was contemplating on this before posting but somehow seemed to remember it applies to all negative numbers. Essentially, just being too dang lazy to check.
And I think only -1 tells you what a value is, you can set attributes to other negative numbers.
You may be right, I was contemplating on this before posting but somehow seemed to remember it applies to all negative numbers. Essentially, just being too dang lazy to check.
