Jump to content


Photo

Is there a good way to detect sleep?


  • Please log in to reply
17 replies to this topic

#1 Ulb

Ulb
  • Modder
  • 373 posts

Posted 29 March 2018 - 03:25 AM

I'm looking for a way to "detect" sleep or rather protect none-sleeping creatures from a spell effect in that very spell effect (so doing it with a script is out of question).

 

I never bothered with spell states before but it looks like there is only DOESNT_AWAKEN_ON_DAMAGE which is set if the sleep effect persists through damage but no equivalent for waken on damage sleep effects?


Edited by Ulb, 29 March 2018 - 03:25 AM.


#2 Creepin

Creepin
  • Administrator
  • 1676 posts

Posted 29 March 2018 - 06:04 AM

I think you'll have to resort to scripting in the end: #177 works only with a limited list of IDS and splstate is not among them.

The Old Gold - v0.2 WIP (mod for BGT/BWP/BWS)


#3 Ulb

Ulb
  • Modder
  • 373 posts

Posted 29 March 2018 - 06:47 AM

No, this is for the EEs. I'm using op code 318 which can use splstate just fine. Only problem there seems to be no splstate for sleep in general.

 

Now, I know I could probably add a new splstate and just patch every sleep effect in the game to but I'd rather not do that.. I just can't believe there wouldn't be a state for sleep?



#4 Creepin

Creepin
  • Administrator
  • 1676 posts

Posted 29 March 2018 - 07:01 AM

#318 (0x13E) Unused
Parameter #1: Unknown
Parameter #2: Unknown
Description:
Unknown

You seem to know something IESDP doesn't then :) Not that I'm doubting your sources, merely marking IESDP lack thereof.


Edited by Creepin, 29 March 2018 - 07:19 AM.

The Old Gold - v0.2 WIP (mod for BGT/BWP/BWS)


#5 Roxanne

Roxanne

    Modder

  • Member
  • 3564 posts

Posted 29 March 2018 - 08:27 AM

Here is an example

318.jpg

This is probably what Ulb was aiming for. You define a spellstate and the creature is then protected from another spell if under this condition.

Problem is that you cannot define *Sleeping* for this purpose without defining a new condition that will be applied by every other spell that makes a creature sleeping...

 
 
 

Edited by Roxanne, 29 March 2018 - 08:28 AM.

The Sandrah Saga

another piece of *buggy, cheesy, unbalanced junk*

 


#6 Ulb

Ulb
  • Modder
  • 373 posts

Posted 29 March 2018 - 10:30 AM

Looks like you are using an old version of IESDP Creepin.

Use this one.

 

*edit* strange.. now it shows the same thing you are seeing for me. I swear I saw a proper entry for op code 318 somewhere..

 

Thanks for confirming that there is indeed no splstate for sleep, thanks Roxanne.

I think I'll change the concept up a little, rather than tinker with this issue for a rather minor flavor feature.


Edited by Ulb, 29 March 2018 - 10:32 AM.


#7 Argent77

Argent77
  • Administrator
  • 1419 posts

Posted 29 March 2018 - 10:36 AM

No need to reinvent the wheel. You can match the sleep state directly in SPLPROT.2DA. It's already done for blindness and panic by the vanilla game.

Example to match "sleeping" state:

index      0x111      0x01       8

SPLPROT syntax can be found in IESDP.

You still need to write some code to add the line to SPLPROT.2DA and return the index of the new entry, so you can reference it in your spell effect.



#8 Ulb

Ulb
  • Modder
  • 373 posts

Posted 29 March 2018 - 12:41 PM

Thanks Argent, good to know there is a way.

 

I might look into this later, when the rest of the kit is done and I still feel like it would make a good feature.


Edited by Ulb, 29 March 2018 - 12:41 PM.


#9 subtledoctor

subtledoctor
  • Modder
  • 656 posts

Posted 29 March 2018 - 02:00 PM

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.


#10 Ulb

Ulb
  • Modder
  • 373 posts

Posted 29 March 2018 - 10:06 PM

That's what I call service!

I'm still not sure I'll use it this time around but I'm bound to find a use for it sooner or later.

 

Thanks a lot, Doc! :)



#11 Avenger_teambg

Avenger_teambg
  • Member
  • 604 posts

Posted 30 March 2018 - 09:20 AM

I think the best would be to add lines like these, but with 0x111:

SPELLSTATE 0x112      -1         1
NOTSSTATE  0x112      -1         5
 
We should have done that :)
 

Avenger

#12 Ulb

Ulb
  • Modder
  • 373 posts

Posted 01 April 2018 - 02:04 AM

Sooooo... I'm toying around with this but it seems like something is off.

WeiDU is complaining that it wants some token at line 16 but being a WeiDU illiterate I'm not sure where the token is missing and which one..

 

[C:\BGEE\EET-Ready\Baldur's Gate II - Enhanced Edition\Setup-UB_tester.exe] WeiD
U version 24400
In state 428, I expected one of these tokens:
  [2] ~~
  [379] DOLLARS
  [399] EVALUATE_BUFFER
Parse error (state 428) at READ_2DA_ENTRIES_NOW

[UB_TESTER/SETUP-UB_TESTER.TP2] PARSE ERROR at line 16 column 1-22
Near Text: READ_2DA_ENTRIES_NOW
        GLR parse error

[UB_TESTER/SETUP-UB_TESTER.TP2]  ERROR at line 16 column 1-22
Near Text: READ_2DA_ENTRIES_NOW
        Parsing.Parse_error
ERROR: parsing [UB_TESTER/SETUP-UB_TESTER.TP2]: Parsing.Parse_error
ERROR: problem parsing TP file [UB_TESTER/SETUP-UB_TESTER.TP2]: Parsing.Parse_er
ror

FATAL ERROR: Parsing.Parse_error

Press ENTER to exit.

 

Here is the code:

 

// sleep prot
APPEND ~splprot.2da~ ~ULB_SLEEP%TAB%0x111%TAB%0x01%TAB%8~
APPEND ~splprot.2da~ ~ULB_NOSLEEP%TAB%0x111%TAB%0x05%TAB%8~

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

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_NOSLEEP~ BEGIN
      SET NOsleep_row = %row%
    END
  END
BUT_ONLY


COPY_EXISTING ~UB_TS.spl~ ~override~
  LPF ALTER_EFFECT INT_VAR match_opcode = 324 parameter2 = %NOsleep_row% END

 





#13 subtledoctor

subtledoctor
  • Modder
  • 656 posts

Posted 01 April 2018 - 04:56 AM

My bad, copy/paste error.
COUNT_2DA_COLS
should be
COUNT_2DA_COLS cols
Also that line can maybe just be excluded.

Also, you don't need to copy and analyze splprot twice. You can put these together:
FOR (row = 1; row < rows; ++row) BEGIN
    PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_SLEEP~ BEGIN
      SET sleep_row = %row%
    END
    PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_NOSLEEP~ BEGIN
      SET NOsleep_row = %row%
    END
END

Edited by subtledoctor, 01 April 2018 - 04:59 AM.


#14 Ulb

Ulb
  • Modder
  • 373 posts

Posted 01 April 2018 - 05:34 AM

WeidU still doesn't like it, though it got more unspecific as to why it doesn't like it. :P

 

COPY_EXISTING ~splprot.2da~ ~override~
  COUNT_2DA_COLS 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
    PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_NOSLEEP~ BEGIN
      SET NOsleep_row = %row%
    END
END


#15 Gwendolyne

Gwendolyne
  • Administrator
  • 1016 posts

Posted 01 April 2018 - 05:41 AM

WeidU still doesn't like it, though it got more unspecific as to why it doesn't like it. :P

 

COPY_EXISTING ~splprot.2da~ ~override~
  COUNT_2DA_COLS 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
    PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_NOSLEEP~ BEGIN
      SET NOsleep_row = %row%
    END
END

 

Try this:

COPY_EXISTING ~splprot.2da~ ~override~
  COUNT_2DA_COLS cols
  READ_2DA_ENTRIES_NOW rows cols
  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
    PATCH_IF ~%state%~ STRING_EQUAL_CASE ~ULB_NOSLEEP~ BEGIN
      SET NOsleep_row = %row%
    END
END

CARPE DIEM ....
 

In progress : Menace sur le Royaume de Diamant Éternel there.


#16 subtledoctor

subtledoctor
  • Modder
  • 656 posts

Posted 01 April 2018 - 06:46 AM

Oh yeah, didn't spot that one. Weird how both of those lines got cut off in the copy/paste. Hazards of writing on a phone...

#17 Ulb

Ulb
  • Modder
  • 373 posts

Posted 01 April 2018 - 07:39 AM

It works!

 

Thanks a lot all of you! :cheers:



#18 temnix

temnix
  • Member
  • 983 posts

Posted 07 May 2018 - 10:23 AM

I'm interested in doing the reverse of this - applying effects only to people who are asleep. How would I go about that?