Reply to Re: Getting the damage/hit value
If you don't have an account, just leave the password field blank.
@SimonK
Okay, here's a script I made that will accomplish everything you need, you can apply this to individual enemies just by adding 1 external call in the HIT procedure and a couple sp_custom lines in the MAIN procedure, so you don't have to go messing about with a bunch of scripts in the Dmod. It took a bit of fine tuning and testing, and comparing everything against the source code, but it will mimick an attack exactly as the internal engine does it, calculating the damage, generating the blood and also generating the floating damage number text sprite. Since I had to disable the sp_hitpoints and manage hitpoints manually through a sp_custom value I also had to manually handle the death as well, which is fine, it's all contained in the 1 external call. It's easy to implement and use, as below.
EDIT: I updated the below script to remove something from it I used to debug it(forgot to remove before uploading) so if you grabbed it before this edit, re-download it.
First add apply.c to your story folder.
Please note this script uses no local variables so it won't consume any extra variable slots, but it does use global variables &save_x and &save_y to juggle variables. If you don't have those declared, declare them or search and replace them with your own global juggle variables.
Then do the below 4 simple steps to use it in an enemy script:
Step 1: Change your enemies sp_hitpoints to 0.
Step 2: Add this line and set the hitpoints value to whatever you wanted the sp_hitpoints to be:
Step 3: Since basewalk and basedeath can't be retrieved and my script needs to access these values, add the sp_custom lines as below but change "value" to the same as the actual sp_base_walk and sp_base_death(these are in addition to sp_base_walk and sp_base_death, don't remove those from your enemy script). You only need to include the sp_custom base death line if your enemy actually has a sp_base_death set.
Step 4: Add this at the START of the HIT procedure, and you can pass values to &arg1-&arg8 and enemies with those brains will not be able to damage the current_sprite.
Example use cases and notes
So if you want your sprite to be immune from damage for brain 9 sprites and brain 11 sprites(missiles) for example, the external call at the start of your hit procedure would be:
the external function will also return the damage/hit value. You can also retrieve the LAST raw damage done to the current_sprite(raw damage is prior to taking defense into account) at any time by retrieving value from sp_custom("dmg_raw", ¤t_sprite, -1);. And you can retrieve the LAST actual damage/hit value done at anytime using sp_custom("dmg_calc", ¤t_sprite, -1);
Important to note: sp_custom strings are case sensitive, use them exactly as they are above. E.g don't do "HP" instead of "hp".
If you pass a missile brain such as fireball as one of the brains to ignore damage from and you find it's still dealing damage, also pass brain 7. Tested with fireball, when my script retrieves the brain of the fireball sprite it's already changed to brain 7 (seq die), so that's what it detects it as.
One additional obscure thing to consider: If your sprite doesn't have a base death and also doesn't have a death sequence in it's basewalk+5 seq slot, unlike the internal engine, my script will not automatically be able to detect these both don't exist, and it won't play the sequence 164 blood explosion default death. If you want sequence 164 to play on death instead of an actual death sequence, then set sp_custom("base_death", ¤t_sprite, 164);
I tested it in DinkHD and YeOldeDink, but if you find any problems/bugs let me know and I can fix it.
Okay, here's a script I made that will accomplish everything you need, you can apply this to individual enemies just by adding 1 external call in the HIT procedure and a couple sp_custom lines in the MAIN procedure, so you don't have to go messing about with a bunch of scripts in the Dmod. It took a bit of fine tuning and testing, and comparing everything against the source code, but it will mimick an attack exactly as the internal engine does it, calculating the damage, generating the blood and also generating the floating damage number text sprite. Since I had to disable the sp_hitpoints and manage hitpoints manually through a sp_custom value I also had to manually handle the death as well, which is fine, it's all contained in the 1 external call. It's easy to implement and use, as below.
EDIT: I updated the below script to remove something from it I used to debug it(forgot to remove before uploading) so if you grabbed it before this edit, re-download it.
First add apply.c to your story folder.
Please note this script uses no local variables so it won't consume any extra variable slots, but it does use global variables &save_x and &save_y to juggle variables. If you don't have those declared, declare them or search and replace them with your own global juggle variables.
Then do the below 4 simple steps to use it in an enemy script:
Step 1: Change your enemies sp_hitpoints to 0.
Step 2: Add this line and set the hitpoints value to whatever you wanted the sp_hitpoints to be:
sp_custom("hp", ¤t_sprite, hitpoints_value_here);
Step 3: Since basewalk and basedeath can't be retrieved and my script needs to access these values, add the sp_custom lines as below but change "value" to the same as the actual sp_base_walk and sp_base_death(these are in addition to sp_base_walk and sp_base_death, don't remove those from your enemy script). You only need to include the sp_custom base death line if your enemy actually has a sp_base_death set.
sp_custom("base_walk", ¤t_sprite, value); sp_custom("base_death", ¤t_sprite, value);
Step 4: Add this at the START of the HIT procedure, and you can pass values to &arg1-&arg8 and enemies with those brains will not be able to damage the current_sprite.
external("apply", "damage");
Example use cases and notes
So if you want your sprite to be immune from damage for brain 9 sprites and brain 11 sprites(missiles) for example, the external call at the start of your hit procedure would be:
external("apply", "damage", 9, 11);
the external function will also return the damage/hit value. You can also retrieve the LAST raw damage done to the current_sprite(raw damage is prior to taking defense into account) at any time by retrieving value from sp_custom("dmg_raw", ¤t_sprite, -1);. And you can retrieve the LAST actual damage/hit value done at anytime using sp_custom("dmg_calc", ¤t_sprite, -1);
//at the start of the HIT procedure external("apply", "damage"); say("I've just been hit for &return damage!", ¤t_sprite);
//Use this anywhere to grab the LAST damge/hit value done to this sprite sp_custom("dmg_calc", ¤t_sprite, -1); say("The last hit I took was for &return damage!", ¤t_sprite);
//Use this anywhere to grab the LAST raw damage done to this sprite sp_custom("dmg_raw", ¤t_sprite, -1); say("Damage value of &return, prior to factoring in my defense", ¤t_sprite);
Important to note: sp_custom strings are case sensitive, use them exactly as they are above. E.g don't do "HP" instead of "hp".
If you pass a missile brain such as fireball as one of the brains to ignore damage from and you find it's still dealing damage, also pass brain 7. Tested with fireball, when my script retrieves the brain of the fireball sprite it's already changed to brain 7 (seq die), so that's what it detects it as.
One additional obscure thing to consider: If your sprite doesn't have a base death and also doesn't have a death sequence in it's basewalk+5 seq slot, unlike the internal engine, my script will not automatically be able to detect these both don't exist, and it won't play the sequence 164 blood explosion default death. If you want sequence 164 to play on death instead of an actual death sequence, then set sp_custom("base_death", ¤t_sprite, 164);
I tested it in DinkHD and YeOldeDink, but if you find any problems/bugs let me know and I can fix it.