banjo_oz
First time out of the vault

I've been trying to make a mod that checks a critter's PID when it dies (I may change it to art type for simplicity though) and if it is of a certain type, adds some jerky to its corpse's inventory.
I'm really stuck trying to write the script, though. I presumed a global script that hooks into ondeath would be the best way, since it would avoid having to edit every critter's scripts. However, my code doesn't seem to work as I kill a Giant Ant in the temple trial at the start... and it still has no inventory (as normal) after death.
Here is my script. If anyone can help and tell me what I've done wrong, I'd appreciate it. I am sure it's a stupid obvious mistake!
/*
Drop meat on critter death if an edible animal
*/
/* Include Files */
#define SCRIPT_REALNAME "gl_drop_meat"
#include "../headers/define.h"
#include "../headers/command.h"
/* Defines */
procedure start;
procedure check_meat_drop;
#define critter_ant (obj_pid(critter) == PID_GIANT_ANT)
#define critter_rat (obj_pid(critter) == PID_RAT or obj_pid(critter) == PID_MUTATED_RAT or obj_pid(critter) == PID_VORPAL_RAT)
#define critter_pigrat (obj_pid(critter) == PID_PIG_RAT or obj_pid(critter) == PID_TOUGH_PIG_RAT or obj_pid(critter) == PID_MUTATED_PIG_RAT)
#define critter_molerat (obj_pid(critter) == PID_MOLE_RAT or obj_pid(critter) == PID_GREATER_MOLE_RAT or obj_pid(critter) == PID_MUTATED_MOLE_RAT)
variable meat;
/* Script Procedures */
procedure start begin
if (game_loaded) then begin
register_hook_proc(HOOK_ONDEATH, check_meat_drop);
end
end
procedure check_meat_drop begin
variable critter := get_sfall_arg;
if (critter_ant) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,1);
end
else if (critter_rat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,1);
end
else if (critter_pigrat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,2);
end
else if (critter_molerat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,4);
end
end
EDIT: previously the script was crashing the game on load until I noticed I had an error in my create_obj lines... fixed that, but now it seems to load fine. It just doesn't do anything!
I'm really stuck trying to write the script, though. I presumed a global script that hooks into ondeath would be the best way, since it would avoid having to edit every critter's scripts. However, my code doesn't seem to work as I kill a Giant Ant in the temple trial at the start... and it still has no inventory (as normal) after death.
Here is my script. If anyone can help and tell me what I've done wrong, I'd appreciate it. I am sure it's a stupid obvious mistake!
/*
Drop meat on critter death if an edible animal
*/
/* Include Files */
#define SCRIPT_REALNAME "gl_drop_meat"
#include "../headers/define.h"
#include "../headers/command.h"
/* Defines */
procedure start;
procedure check_meat_drop;
#define critter_ant (obj_pid(critter) == PID_GIANT_ANT)
#define critter_rat (obj_pid(critter) == PID_RAT or obj_pid(critter) == PID_MUTATED_RAT or obj_pid(critter) == PID_VORPAL_RAT)
#define critter_pigrat (obj_pid(critter) == PID_PIG_RAT or obj_pid(critter) == PID_TOUGH_PIG_RAT or obj_pid(critter) == PID_MUTATED_PIG_RAT)
#define critter_molerat (obj_pid(critter) == PID_MOLE_RAT or obj_pid(critter) == PID_GREATER_MOLE_RAT or obj_pid(critter) == PID_MUTATED_MOLE_RAT)
variable meat;
/* Script Procedures */
procedure start begin
if (game_loaded) then begin
register_hook_proc(HOOK_ONDEATH, check_meat_drop);
end
end
procedure check_meat_drop begin
variable critter := get_sfall_arg;
if (critter_ant) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,1);
end
else if (critter_rat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,1);
end
else if (critter_pigrat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,2);
end
else if (critter_molerat) then begin
meat := create_object(PID_MEAT_JERKY,0,0);
add_mult_objs_to_inven(critter,meat,4);
end
end
EDIT: previously the script was crashing the game on load until I noticed I had an error in my create_obj lines... fixed that, but now it seems to load fine. It just doesn't do anything!
Last edited: