Re: Spawning a Monster From a Barrel
Yep, that's right. Another question. What I want to do, is have Dink punch a barrel, and a monster spawns from it. I just got the barrel script bar-e.c and copy & pasted everything from it, into my new script. Then before kill_this_task();, I have my monster spawn bit. This is how it goes:
// main.c excerpt
make_global_int("&dd-barx1",0);
make_global_int("&dd-barx2",0);
make_global_int("&dd-barx3",0);
make_global_int("&dd-bary1",0);
make_global_int("&dd-bary2",0);
make_global_int("&dd-bary3",0);
// script excerpt
if (&rand == 1)
{
// Bad barrel
// Save X and Y coordinates for monster spawn
&dd-barx1 = sp_x(¤t_sprite,-1);
&dd-bary1 = sp_y(¤t_sprite,-1);
// Monster spawn
// Weak monster: Bonca
int &bonc = create_sprite(&dd-barx1,&dd-bary1,9,533,1);
sp_script(&bonc,"en-bonc");
}
I think I might be doing the "Save X and Y corrdinates" bit wrong. But I'm not sure.
// main.c excerpt
make_global_int("&dd-barx1",0);
make_global_int("&dd-barx2",0);
make_global_int("&dd-barx3",0);
make_global_int("&dd-bary1",0);
make_global_int("&dd-bary2",0);
make_global_int("&dd-bary3",0);
// script excerpt
if (&rand == 1)
{
// Bad barrel
// Save X and Y coordinates for monster spawn
&dd-barx1 = sp_x(¤t_sprite,-1);
&dd-bary1 = sp_y(¤t_sprite,-1);
// Monster spawn
// Weak monster: Bonca
int &bonc = create_sprite(&dd-barx1,&dd-bary1,9,533,1);
sp_script(&bonc,"en-bonc");
}
I think I might be doing the "Save X and Y corrdinates" bit wrong. But I'm not sure.
Maybe it would be easier to modify the make.c script and spawn the monster the same way normal barrels spawn hearts and such. All you would have to do is make a new procedure in it.
Instead of copying from the empty barrel script, you probably should've looked at a barrel script that actually spawns an item. I've made some sample script for what you're trying to accomplish. BTW in the barrel hit script I only modified the procedure name of the external script and cut out the comments.
//hit procedure for barrel script
void hit ( void )
{
playsound(37, 22050, 0,0,0);
int &hold = sp_editor_num(¤t_sprite);
if (&hold != 0)
{
editor_type(&hold, 3);
editor_seq(&hold, 173);
editor_frame(&hold, 6);
}
sp_seq(¤t_sprite, 173);
sp_brain(¤t_sprite, 5);
sp_notouch(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
&save_x = sp_x(¤t_sprite, -1);
&save_y = sp_y(¤t_sprite, -1);
external("make", "wbonc");
sp_hard(¤t_sprite, 1);
draw_hard_sprite(¤t_sprite);
kill_this_task();
}
//new procedure for make.c
void wbonc( void )
{
int &mcrap = random(1,5);
if (&mcrap == 1)
{
int &bonc = create_sprite(&save_x,&&save_y,9,533,1);
sp_script(&bonc,"en-bonc");
}
}
Instead of copying from the empty barrel script, you probably should've looked at a barrel script that actually spawns an item. I've made some sample script for what you're trying to accomplish. BTW in the barrel hit script I only modified the procedure name of the external script and cut out the comments.
//hit procedure for barrel script
void hit ( void )
{
playsound(37, 22050, 0,0,0);
int &hold = sp_editor_num(¤t_sprite);
if (&hold != 0)
{
editor_type(&hold, 3);
editor_seq(&hold, 173);
editor_frame(&hold, 6);
}
sp_seq(¤t_sprite, 173);
sp_brain(¤t_sprite, 5);
sp_notouch(¤t_sprite, 1);
sp_nohit(¤t_sprite, 1);
&save_x = sp_x(¤t_sprite, -1);
&save_y = sp_y(¤t_sprite, -1);
external("make", "wbonc");
sp_hard(¤t_sprite, 1);
draw_hard_sprite(¤t_sprite);
kill_this_task();
}
//new procedure for make.c
void wbonc( void )
{
int &mcrap = random(1,5);
if (&mcrap == 1)
{
int &bonc = create_sprite(&save_x,&&save_y,9,533,1);
sp_script(&bonc,"en-bonc");
}
}
That looks good. I'll try it, thanks.