sfall-team / sfall

sfall - Engine modifications for Fallout 2
https://sfall-team.github.io/sfall/
GNU General Public License v3.0
348 stars 41 forks source link

StdProcedure - add action_being_used parameter #419

Closed tnevolin closed 3 years ago

tnevolin commented 3 years ago

https://sfall.bgforge.net/hook-types/#stdprocedure

This would be a tremendous hook if it can also capture action_being_used thing. Unfortunately, the direct call to this function results in error probably because it is not called from the object script. Any other ways to capture skill being used when use_skill_on_p_proc is invoked ?

FakelsHub commented 3 years ago

Give your examples or Goal.

tnevolin commented 3 years ago

I am trying to create a QoL improvement where player does not need to use lockpicks on a lock to benefit from their lockpicking bonus. Instead I will intercept the lockpick operation, check whether dude has lockpicks in inventory and modify success ratio corresponding to the best and matching lockpicks type in the inventory.

I have tried to use HOOK_USESKILLON but it is not executed for lockpicking as it is overridden by scripts for each and every lock in the game. Now I am trying to do the same with HOOK_STDPROCEDURE that is called when lockpick script use_skill_on_p_proc procedure is called. It works fine. Unfortunately, it does not pass skill as a parameter and I don't know how else to retrieve it. The action_being_used fails with an error as it is called from hook function not from within the script.

NovaRain commented 3 years ago

Unfortunately, it does not pass skill as a parameter and I don't know how else to retrieve it.

Why not just check source_obj's skill level on your own?

tnevolin commented 3 years ago

I don't need skill level. I need the skill id/name. The use_skill_on_p_proc procedure could be called for any skill: science, repair, lockpick, etc. I need to make sure it is called for lockpick specifically and ignore other cases.

See example in DOORL100.ssl

procedure use_skill_on_p_proc begin
   variable Skill_Used;

   Skill_Used:=action_being_used;

   if (Skill_Used == SKILL_LOCKPICK) then begin

…
FakelsHub commented 3 years ago

When using a lockpick item, various events may occur for the game, which with your "QoL" will not be able to occur.

You probably need to unlock the lock yourself, and not pass the modified skill values. Another way is to temporarily increase the skill, and then lower it.

FakelsHub commented 3 years ago

I don't need skill level. I need the skill id/name.

OK.

FakelsHub commented 3 years ago

The action_being_used fails with an error as it is called from hook function not from within the script.

This should work from HOOK as well. Show your script.

tnevolin commented 3 years ago
procedure start begin
        register_hook_proc(HOOK_STDPROCEDURE, handleStandardProcedure);
end

procedure handleStandardProcedure begin
// fails at this point
    variable skill = action_being_used;
end
FakelsHub commented 3 years ago

https://fakelshub.github.io/sfall-wiki/objects/#set_self Used it?

set_self(source);
action_being_used
tnevolin commented 3 years ago

https://fakelshub.github.io/sfall-wiki/objects/#set_self Used it?

Nope. Let me try.

FakelsHub commented 3 years ago

I'll see later why action_being_used doesn't work if set_self doesn't act for it.

tnevolin commented 3 years ago

https://fakelshub.github.io/sfall-wiki/objects/#set_self Used it?

Nope. Let me try.

That worked. Thank you!

I have another question if you can answer it from the top of your head. If not, I'll create an issue.

All locks are scripted and the type of the lock (standard/electric) is defined in the the script.

#define LOCK_STATUS                     STATE_STANDARD_LOCK

or

#define LOCK_STATUS                     STATE_ELECTRIC_LOCK

Is there a way to retrieve this information from the object (door)? The only thing I could find is https://sfall.bgforge.net/objects-and-scripts/#get_script that return script # for object but what to do with it? Can I extract script text to parse it manually?

FakelsHub commented 3 years ago

Can I extract script text to parse it manually?

no (there is no text, there are operation codes)

FakelsHub commented 3 years ago

Is there a way to retrieve this information from the object (door)?

no, this information is only in the script (in a local variable).

tnevolin commented 3 years ago

I did this ugly way. Thank you for help with hooks!