The Dink Network

Two questions

August 14th 2006, 06:11 PM
fairy.gif
Arik
Peasant He/Him
 
1) Anyone know if there's any way to stop a monster running its die() procedure when I get it to use the hurt command on itself? i.e. hurt(&current_sprite, 10);

2) Anyone know the limitations of set_callback_random? I've got an action attached to a brain 9 monster but it stops working once I hit it.

It's all stuff I can work around (and probably would be better worked around), but knowledge is power, right? (This d-mod's going to kill me.)
August 14th 2006, 07:24 PM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
2) is a limitation of about anything: If a script attached to a monster does something, and then you hit it (or talk, touch, die, push, other built-in procs), it plainly forgets what it was supposed to do and continues to do the built-in proc.

Try it with an unfrozen Dink in a lengthy talk()-dialogue, then hit him. He'll stop talking.

The way I see it, set_callback_random(proc, base, range) is equivalent to:

int &rndtime = random(base, range);
wait(&rndtime);
proc();

So if you had it waiting before it runs proc(), and then hit it, the script forgets that it was waiting and runs the hit() thing.

It's also the reason why sp_touch_damage(&current_sprite,0); should be in the first line of a touch-proc: It detects that Dink touches it and forgets doing whatever it was doing in the touch-proc, and then runs the touch-proc.
August 14th 2006, 08:48 PM
custom_king.png
redink1
King He/Him United States bloop
A mother ducking wizard 
1) Weird. Looked through the source code... double-weird. This should work, though:

sp_nohit(&current_sprite, 1);
hurt(&current_sprite, 10);
sp_nohit(&current_sprite, 0);

2) set_callback_random is... funky. If you really want to use it, try something like this:

void main(void)
{
// blah hitpoints brain
set_callback_random("woo", 500, 2000);
}

void hit(void)
{
// Playsound, blah blah blah
set_callback_random("woo", 500, 2000);
}

But, if the player hits the sprite a lot in quick succession, it might not be called.
August 15th 2006, 09:51 AM
fairy.gif
Arik
Peasant He/Him
 
Weirdly enough, magicman, if I touch the monster it doesn't stop the callback from running - it's only hitting it that causes the problem. That said, I've got a set_callback_random running on a non-monster that does stop when I touch it, whether I use touch or buttonon.

Funky indeed. Thanks guys!
August 15th 2006, 09:58 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
Does that monster have a sp_touch_damage() other than -1? Only if it's -1 the proc will be called, so the script suddenly has something else to do.
August 15th 2006, 10:25 AM
fairy.gif
Arik
Peasant He/Him
 
It has a touch damage of greater than 0, and the touch procedure is definitely being called.
August 15th 2006, 10:29 AM
custom_magicman.gif
magicman
Peasant They/Them Netherlands duck
Mmmm, pizza. 
I agree, that's weird
August 15th 2006, 02:34 PM
knightg.gif
cypry
Peasant He/Him Romania
Chop your own wood, and it will warm you twice. 
Why don't you create another sprite on the screen, that should call the procedure.
In your monster's main procedure, use:
int &caller = create_sprite(0,0,0,100,1);//just random numbers
sp_nodraw(&caller,1);
sp_nohit(&caller,1);
sp_brain_parm(&caller,&current_sprite);
sp_script(&caller,"caller");

now, the "caller" script:
void main(void)
{
int &monster = sp_brain_parm(&current_sprite,-1);
set_callback_random("woo",500,2000);
}
void woo(void)
{
//place here your procedure
//just refer to &monster
}

in the monster's die procedure, don't forget to add
sp_active(&caller,0);

Hope it works. I didn't test it.