Two questions
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(¤t_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.)
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.)
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(¤t_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.
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(¤t_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.
1) Weird. Looked through the source code... double-weird. This should work, though:
sp_nohit(¤t_sprite, 1);
hurt(¤t_sprite, 10);
sp_nohit(¤t_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.
sp_nohit(¤t_sprite, 1);
hurt(¤t_sprite, 10);
sp_nohit(¤t_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.
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!
Funky indeed. Thanks guys!
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.
It has a touch damage of greater than 0, and the touch procedure is definitely being called.
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,¤t_sprite);
sp_script(&caller,"caller");
now, the "caller" script:
void main(void)
{
int &monster = sp_brain_parm(¤t_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.
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,¤t_sprite);
sp_script(&caller,"caller");
now, the "caller" script:
void main(void)
{
int &monster = sp_brain_parm(¤t_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.











