It's not too difficult - especially since there is already an entry for sleeping in STATE.IDS.
So you simply:
APPEND ~splprot.2da~ ~ULB_SLEEP%TAB%0x111%TAB%0x01%TAB%8
Then, find the line # of the row you just appended (because it may differ from one installation to another):
COPY_EXISTING ~splprot.2da~ ~override~
COUNT_2DA_COLS
READ_2DA_ENTRIES_NOW
FOR (row = 1; row < rows; ++row) BEGIN
READ_2DA_ENTRY_FORMER rows row 0 ~state~
PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_SLEEP~ BEGIN
SET sleep_row = %row%
END
END
BUT_ONLY
And then in your spell, you make a 324 effect (or 318, I guess it's the same), and any effects you want the sleeping person to be immune to must come after the 324 effect.
You only need to make sure to patch the spell when you copy it in, to make the 324 effect point to the right SPLPROT entry:
COPY ~mymod/thespell.spl~ ~override~
LPF ALTER_EFFECT INT_VAR match_opcode = 324 parameter2 = %sleep_row% END
Edited by subtledoctor, 29 March 2018 - 08:14 PM.