The Dink Network

Some form of "selective" nohit function?

September 11th 2017, 09:57 PM
knightgl.gif
castman
Peasant He/Him Brazil
Some day I'll finish my mod... Some day... 
In this scenario, the player has to destroy some floor boards using bombs.

For these bombs to be able to damage and destroy these boards, their nohit value can't be set to 1, or else the bombs are not going to detect them. However, these boards being 'floor' sprites, it would be really odd if arrows and ranged spells could hit them.

Is there any way in which a bomb could detect and damage these sprites, while other 'missiles' would fly over them?

I believe I could brute force it using the 'inside_box' function, but since I intend to make this a common quirk, having to write box lines for every instance of it would be a nightmare.

Any ideas?
September 11th 2017, 10:19 PM
peasantmp.gif
Skurn
Peasant He/Him Equatorial Guinea duck bloop
can't flim flam the glim glam 
maybe you could have the bombs' script include a line where, just before exploding, it activates the floor sprite's hardness?

as for the script itself. i dunno. but maybe someone can turn my terrible idea into a script. with globals or something.
September 12th 2017, 01:00 AM
custom_robj.png
Robj
Jester He/Him Australia
You feed the madness, and it feeds on you. 
In this situation, you can create what you're calling a 'selective nohit function' with these bombs.
You can use your idea of brute forcing it with inside_box, but you can automate it so you don't have to write it for every instance. This, I suppose, is just one way to do it that I can think of right now off the top of my head.

You should be able to accomplish this in the following 3 steps:
1. edit dam-bom.c to add an external line, executing a procedure from a new script and passing on the bomb sprite using &arg1.
2. Create the new script previously called with external, which uses an automated inside_box to temporarily disable nohit if the sprite is touching the bomb.
3. create a new script and attach that one script to all sprites that you want the bomb to 'selectively hit'. In this case, your floorboard sprites.

I will demonstrate this below, however keep in mind I have no idea what the depth dot, or hard box of your floorboard sprites are, so my scripting explanation will be based on the idea of using rocks instead (seq95, frame1). You'll have to modify the values in the script called by external.

STEP 1:
Since you only need to add one line, this doesn't need much explanation, so I'll just put the whole dam-bom.c script in a pastebin and put the link here, with the added line clearly marked with a comment.
dam-bom.c

STEP 2:
The script that external calls is below. I'll call this script 'rocknh.c'. Call it whatever you want and modify it to your pleasing.
//rocknh.c

void main(void)
{
 //declare the variables -
 //there's ways of doing this and using less but for explanation reasons, let's do it this way.
 
 //get the x and y position of the bomb
 int &x = sp_x(&arg1, -1);
 int &y = sp_y(&arg1, -1);
 
 //variables for the inside box values
 int &left;
 int &tp;
 int &right;
 int &bt;
 
 //to retrieve all rock sprites for selective nohit
 //All rocks have a fake brain of 20 for easy retrieval
 int &check = 0;
 
 //the loop to check all rocks and whether the bomb is touching them
 bloop:
  &check = get_next_sprite_with_this_brain(20, 0, &check)
  if (&check > 0)
  {
   //store the x and y of the rock in these vars
   &right = sp_x(&check, -1);
   &left = sp_x(&check, -1);
   &tp = sp_y(&check, -1);
   &bt = sp_y(&check, -1);
   
   //adjust them to automate inside box check since all sprites are the same
   //if your using a few different sprites you can add a check for sprite seq and frame
   &left -= 43;
   &tp -= 49;
   &right += 45;
   &bt += 21;
   
   //check if the bomb is touching the rock
   &tp = inside_box(&x, &y, &left, &tp, &right, &bt);
   if (&tp == 1)
   {
    //It is! Let's make it hittable while the bomb is exploding.
    sp_nohit(&check, 0);
   }
   
   //increment check variable and loop.
   &check += 1;
   goto bloop;
  } 
}


STEP 3:
Here is the script that I attached to all the rocks, this will set the fake brain of the sprites to 20 for easy retrieval and set the nohit back to 1 when the bomb finishes exploding.
//rock.c

void main(void)
{
 sp_brain(&current_sprite, 20);
 sp_nohit(&current_sprite, 1);
}

void hit(void)
{
 int &checkb = compare_sprite_script(&missle_source, "dam-bomn");
 if (&checkb == 1)
 {  
  //hit by a bomb!
  //if you want other stuff to happen you can put it here
  loop:
  wait(100);
  &checkb = sp_active(&missle_source, -1)
  if (&checkb == 1)
  { 
   goto loop;
  }
  sp_nohit(&current_sprite, 1);
 }
 else
 {
  wait(50);
  goto loop;
 }
} 


I'm quite sure this will accomplish what you want in a much easier way than just 'brute forcing' it. I threw this together, so modify it and improve it. It should work as is though.
It should be clear enough hopefully. If not let me know, I'll whip together a quick video for you.