Jump to content

Creation Kit / Skyrim: Is there a way to assign an NPC's response based on some random number?


Recommended Posts

I'm developing a mod where the player can invite an NPC for sex. However, I want to make it so that the NPC may or may not feel attracted to the player. 

 

At first, I thought of using one of the already implemented AI behaviors to decide the NPC's response, specifically Confidence. If the NPC has high confidence, then they'll be attracted to the player. Otherwise, they will not. Of course, this is not ideal because it means that the NPCs will be attracted to the player no matter the play through. 

 

A simple programmatic way to simulate this would be to get the NPC's Ref ID and if the last number (or any other number) is even, then the NPC will feel attracted to the player. Otherwise he/she will not. 

 

But this has two problems:  

 

(a) I don't think that's there's a way to make this calculation. Is it possible? and 

 

(b) As far as I understand, Ref IDs are constant throughout game plays which means the same NPCs will always (not) feel attracted to the player which is not what I'm looking for. So it's the same with Confidence. 

 

So my question is this:  

 

1. Is there some kind of randomly generated (when a new game begins) but constant NPC number that I can use to simulate this behavior? And if such a number exists, how can I make this check during the Player-NPC dialogue? E.g., can I do it with a Condition Function?  

 

OR  

 

2. Is there some other (clever) way of simulating this behavior?  

 

Thank you!  

Link to comment


You might consider using one of the exiting frameworks for fame, arousal, attractiveness, sexual preferences, etc.

(search the forum I think there are different ones for all of these aspects, likely more.)


If you want to program something yourself its not trivial:
a) x.getactorbase().getFormID() % 2  would compute what you mentioned for actor x;

but using it in a condition is tricky; you cannot do computations in a condition, only in a script.

 

b/1
you could create a new random number when a play though starts

Eg on your main quest have a script like this:
--
Scriptname myscriptname extends Quest Conditional

int property playthroughfixedrandom conditional

event oninit()
  playthroughfixedrandom = Utility.randomint(0,N)    ; use a fixed number for N, 1 for a single random bit.
endEvent
--

Now you can use that random to select between N conditions to use;

  GetVMQuestVariable mainquest playthroughfixedrandom != 1
  OR
  Cont 1
  AND
  ...
  GetVMQuestVariable mainquest playthroughfixedrandom != n
  OR
  Cont n

Will use Cond i if random = i

(Fill in for Con1 what ever you want to use - could be multiple lines combined with ANDs, if you need ORs you'll have to reconsider the formula above...

EDIT:  That should be: combined with ORs is fine, if you want to use ANDs you need to repeat the

GetVMQuestVariable mainquest playthroughfixedrandom != x
  OR

...

with each AND  

( c=i ) => a \/ b  ==  (c != i) \/ a \/ b,  

( c=i ) => a /\ b  == ((c!=i) \/ a)  /\ ((c!=i) \/ b) 

)

 

>2.

maybe but I can't think of it ;)

 

Edited by MTB
corrected logic for multiple part in the conditions.
Link to comment
2 hours ago, MTB said:


You might consider using one of the exiting frameworks for fame, arousal, attractiveness, sexual preferences, etc.

(search the forum I think there are different ones for all of these aspects, likely more.)


If you want to program something yourself its not trivial:
a) x.getactorbase().getFormID() % 2  would compute what you mentioned for actor x;

but using it in a condition is tricky; you cannot do computations in a condition, only in a script.

 

b/1
you could create a new random number when a play though starts

Eg on your main quest have a script like this:
--
Scriptname myscriptname extends Quest Conditional

int property playthroughfixedrandom conditional

event oninit()
  playthroughfixedrandom = Utility.randomint(0,N)    ; use a fixed number for N, 1 for a single random bit.
endEvent
--

Now you can use that random to select between N conditions to use;

  GetVMQuestVariable mainquest playthroughfixedrandom != 1
  OR
  Cont 1
  AND
  ...
  GetVMQuestVariable mainquest playthroughfixedrandom != n
  OR
  Cont n

Will use Cond i if random = i

(Fill in for Con1 what ever you want to use - could be multiple lines combined with ANDs, if you need ORs you'll have to reconsider the formula above...)

 

>2.

maybe but I can't think of it ;)

 

 

That's extremely interesting, thank you so much for sharing.

I ended up following an alternative (and simpler) method to solve this after for the initial version of the mod. But I will definitely think about how I can make use of what you shared here.

 

Many thanks!

 

 

Link to comment
  • 5 weeks later...

If you are using a dialogue, you can use a topic info fragment where you run your calculation and store the result in a global variable or a conditional quest variable, and then use that global/quest var in a condition of some dialogue topic info that follows after the first one.
 

I recently needed a similar functionality - to calculate some value when dialogue is started, and use the value in the dialogue and its conditions - you can find the exact details in https://www.loverslab.com/topic/183025-followers-get-paid-need-dialogue-writers/.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. For more information, see our Privacy Policy & Terms of Use