Adding news perks with sfall

FeelTheRads

Vault Senior Citizen
Hi,

Does anyone have an example script with how to add new perks with sfall?

There are those examples that come with the modder pack, but those also add traits and the code is too complicated for me to figure out.

I only got as far as making a perk show up with set_selectable_perk in the map start procedure, but I assume they need to go in a sfall global script and anyway, I don't know what to do besides that.

Thanks.

OK, so I tried this by just copy/pasting stuff from the example scripts:

Code:
procedure start;

#define dude_level (get_pc_stat(1))

//perks
#define Perkname "Perkname"       //ts_chp04

procedure LevelChange begin
   if(dude_level>=1 and has_fake_perk(Perkname)==0) then begin
       set_selectable_perk(Perkname, 1, 50, "Perk Description");
   end else begin
       set_selectable_perk(Perkname, 0, 1, "");
   end
end

procedure start begin

   variable mode;
   mode:=get_sfall_global_int("dlevel00");
   if(mode!=dude_level) then begin
       call LevelChange;
       set_sfall_global("dlevel00", dude_level);
   end

end

However, it's not really working. It's only showing up if I do "dude_level>=1".
If I do "dude_level>=3" it's not showing up.
Also, it shows up for every perk pick, even though the condition is there to not do that... as far as I get it.

And obviously it's missing the part with the effects of the perk... which I of course also need help with.
 
Last edited:
And obviously it's missing the part with the effects of the perk....
The mechanics of the new perk will have to write completely through the script.

Code:
if has_fake_perk(Perkname) != 0 then
 here your code, what will be affected by perk when it is taken
end
 
Ah, yeah... but, any help with the code to add the perk itself? Why isn't what I posted above working correctly?
 
And for the effects of the perk... how do you I call "if_has_perk"? For example, if my perk is supposed to have effect just 1 time. Like adding 10HP or something like that.
 
Look at how it is done in the 'Traits' mod in the examples of the folder 'example_mods'.
If you don't know the scripts, then you will not be able to do this.

However, it's not really working. It's only showing up if I do "dude_level>=1".
If I do "dude_level>=3" it's not showing up.
dude_level - is the current player level

For example, if my perk is supposed to have effect just 1 time. Like adding 10HP
Code:
if only_once == false and has_fake_perk(Perkname) then begin
    only_once := true;
    set_pc_extra_stat(STAT_max_hit_points, get_pc_extra_stat(STAT_max_hit_points) + 10);
end
 
Last edited:
As temporary variable, wouldn't only_once reset at some point? I'd probably use a GVAR for the perk check.
 
Thank you!

Well, I was wondering if anyone has already made a script for this that I could use as a skeleton, and that covers everything, since as I said I find it hard to follow the example scripts and the sfall functions are not too well documented.

Anyway, I tried some more and got to this. Basically just copy/pasting stuff.

Code:
procedure start;

#define dude_level (get_pc_stat(1))

//perks
#define Perkname "Perkname"       //ts_chp04

procedure LevelChange begin
   if(dude_level>=3 and has_fake_perk(Perkname)==0) then begin
       set_selectable_perk(Perkname, 1, 50, "Perk description.");
   end else begin
       set_selectable_perk(Perkname, 0, 1, "");
   end
end

procedure PickedPerk begin
   if (has_fake_perk(Perkname)==1 and get_sfall_global_int("gotperkn")==0) then begin
       set_sfall_global("gotperkn", 1);
       set_critter_hit_chance_mod(dude_obj, 98, 0);
       set_pc_base_stat(0, get_pc_base_stat(0) + 1);
       set_pc_extra_stat(9, get_pc_base_stat(9) + 50);
       set_pc_extra_stat(7, get_pc_extra_stat(7) + 10);
   end
   call LevelChange;
end

procedure SetupPerks begin
   if(get_sfall_global_int("gotperkn")==1) then begin
       set_critter_hit_chance_mod(dude_obj, 98, 0);
   end
end

procedure PerksRepeat begin
   if(get_sfall_global_int("gotperkn")==1) then begin
   //nothing here, but the example files show that some need to be called constantly to remain in effect
   end
end

procedure start begin

  variable mode;
  mode:=get_sfall_global_int("ts_trt00");
   if (game_loaded) then begin
       if(mode!=-1) then begin
           call SetupPerks;

           set_global_script_repeat(100);
       end
       return;
   end

   mode:=get_sfall_global_int("dlevel00");
   if(mode!=dude_level) then begin
       call LevelChange;
       set_sfall_global("dlevel00", dude_level);
   end

   mode:=get_sfall_global_int("ts_trt01");
   if(mode!=get_perk_owed) then begin
       if(mode>get_perk_owed) then begin
           call PickedPerk;
       end
       set_sfall_global("ts_trt01", get_perk_owed);
   end
   call PerksRepeat;

end

So, this seems to work correctly, perk shows up at the correct level and only once, but who knows if it can cause other problems.
In order, it sets the maximum hit chance of the player to 98%, it increases the strength by 1, the armor class by 50 and the hit-points by 10. It looks like the some stats (the derived ones?) need to be set with "set_pc_extra". They don't seem to work with "set_pc_base".
Also I guess I'd have to add another line to or something to heal the player because those 10 extra points are added on top of your maximum so you end up injured.

Then, the maximum hit chance is not saved in saved games so it needs to be applied every time you load the game, so that's what the SetupPerks procedure does. It checks if you have the perk and applies this effect. The other effects are 1 time only so they don't get called again.

There's also the PerksRepeat procedure which is for effects that need to be checked continuously. In the example files it checked if the player is unarmed.

If anyone wants to check it for stupid shit that could cause problems I'd appreciate it.

Thank you.
 
Back
Top