Home | Download | Discussion | Help | Site Map | New Posts | Sign in

Latest Site News

Theme Catchup2018 - posted on 1st May 2018 at 1:50 PM
Replies: 22 (Who?), Viewed: 1447 times.
Instructor
Original Poster
#1 Old 8th May 2018 at 8:41 AM
Default How to store SimDescription
So in my Vampire mod I created a compel to become servant interaction which will give the Sims a custom moodlet based on the Alien servitude moodlet. Also the vampire is able to give certain commands to them when they have this moodlet like command to fight other sims, flirt with etc.

Now I want to make it so that a Sim hypnotized by one Vampire can't be commanded by another Vampire. I was thinking of doing it similar to how Vampire hunt interactioin works. The Sim's information(SimDescription) gets stored in a variable created in the OccultVampire class.

Any ideas on how to achieve this?
Advertisement
LeaderOfTheMantisShrimps
staff: administrator
#2 Old 8th May 2018 at 11:56 AM
You could maybe do it with buffs? i know you can let the script read if the sim has that buff, the interaction won't work on them
Instructor
Original Poster
#3 Old 8th May 2018 at 2:33 PM
Quote:
Originally Posted by Lyralei
You could maybe do it with buffs? i know you can let the script read if the sim has that buff, the interaction won't work on them


That's what I have done so far. I created a mind controlled buff. But the problem was that every vampire could command every enslaved Sim. I only want the Vampire that hypnotized them to be able to control them.
Lab Assistant
#4 Old 8th May 2018 at 4:55 PM Last edited by Battery : 8th May 2018 at 5:29 PM.
Hi skydome,

i suggest that you dont store the whole simdescription but rather the simdescriptionid.
For your Problem with the master/slave relationship i would suggest using an dictionary where the key is the slave and the value is the vampirelord.

something like that:
public Dictionary<ulong,ulong> SlaveMaster = new Dictionary<ulong, ulong>();
then when a sim is enslaved add the simdescriptionid of the enslaved sim as the key and the simdescriptionid of the vampire as the value
then test the interaction like that:
if (SlaveMaster.ContainsKey(SlaveID))
{
if (SlaveMaster[SlaveID] != MasterID)
{
return false;
}
}
return true;

i have included a short suggestion for a possible implementation which also allows you to load a game with the data in it, i use a similar implementation for all my mods since i always need to store user options.

When you made the adjustments to the code implement it like that (bad Lazy Singleton Implementation which i use ):

[PersistableStatic]
private static SavedData SData;
public static SavedData sData
{
get
{
if (SData == null){SData = new SavedData () };
return SData ;
}
}
Download - please read all instructions before downloading any files!
File Type: 7z SlaveMaster.7z (542 Bytes, 4 downloads) - View custom content
Instructor
Original Poster
#5 Old 8th May 2018 at 7:33 PM
Thank you so much Battery
You have been so helpful.

I'm going to try that out.
Lab Assistant
#6 Old 8th May 2018 at 8:09 PM
Quote:
Originally Posted by skydome
Thank you so much Battery
You have been so helpful.

I'm going to try that out.


Im glad i could help, looking forward to see how your ideas manifest in modform :D


E: one thing i forgot to mention. You may want to call the cleanup on game quit since data can also carry over between saves (meaning one savegame bleeds into another, thats one reason why many simmers recommend that you dont load a game from an active session since not all mods and i think even EA's implementation isnt all that clean)
Instructor
Original Poster
#7 Old 8th May 2018 at 8:36 PM
How do I get the SimDescriptionID?
I also didn't understand the cleanup part
Lab Assistant
#8 Old 8th May 2018 at 8:44 PM
Quote:
Originally Posted by skydome
How do I get the SimDescriptionID?
I also didn't understand the cleanup part


1. Sim.Simdescription.SimdescriptionID (where Sim would be the sim you would like to access)
2. the persistable attribute makes the whole thing persist even between saves so if you have Sim a being a slave of sim b in your current session and then load another game where taht should not be the case the stored values will be applied (so a will still be enslaved by b) if you dont do a cleanup before loading the game, so hook up the gamequit event to your code to execute the cleanup.
Instructor
Original Poster
#9 Old 8th May 2018 at 9:05 PM
Lol the first one was so easy, I feel embarrassed to ask. Like duh lol.
The gamequit event I'll add in the OnWorldLoadFinished right?
Lab Assistant
#10 Old 8th May 2018 at 9:12 PM
Quote:
Originally Posted by skydome
Lol the first one was so easy, I feel embarrassed to ask. Like duh lol.
The gamequit event I'll add in the OnWorldLoadFinished right?


its like your gameloadfinished but with this code

World.OnWorldQuitEventHandler += OnQuit;
private static void OnQuit(object sender, EventArgs e)
{
/*Implement your cleanup here
e.g.
sData.Cleanup() ;
sData = null; //also implement the setter for sData if you want
*/
}

So im off for the next 20 -22 hours so if i dont answer new posts earlier thats probably why :P
Instructor
Original Poster
#11 Old 8th May 2018 at 9:43 PM
Ok thank you. You are very helpful. I'm also going to sleep now
Instructor
Original Poster
#12 Old 9th May 2018 at 10:45 PM
Omigosh it worked! Thank you!! So much!!

I do have another question but I'll ask that in another topic.
Instructor
Original Poster
#13 Old 9th May 2018 at 10:56 PM
BTW why did you say I should store the SimDescriptionID and not SimDescription? Is there a problem with the SimDescription?
Instructor
#14 Old 10th May 2018 at 3:37 AM
Hi
Just walking by even though I haven't been scripting for a long time.
But since I also worked with dictionary storing simDescriptionID, I think it's because it's a more common practice to locate a particular Sim. ID is also probably smaller in size.
Good luck
Instructor
Original Poster
#15 Old 10th May 2018 at 8:00 AM
Quote:
Originally Posted by SimsMatthew
Hi
Just walking by even though I haven't been scripting for a long time.
But since I also worked with dictionary storing simDescriptionID, I think it's because it's a more common practice to locate a particular Sim. ID is also probably smaller in size.
Good luck

Thanks for replying
That does make sense.

BTW what would happen if I store the Sim directly as a key in the dictionary? Would that be bad?
Lab Assistant
#16 Old 10th May 2018 at 8:47 AM Last edited by Battery : 10th May 2018 at 9:06 AM.
Hello Skydome,

as SimsMatthew suspected it is common practice to store a simple value as a key in the dictionary which is also smaller than the whole sim/simdescription.
As said its a value rather than a reference type. (its just the reference, even if you make a <sim,sim> dict, that gets stored so its not a copy of the sim !)

You could of course take the sim as a key and another sim as the value. While im not completely sure i believe this is a slower approch.
You could make a <Sim,Sim> Dictionary or you could create a struct with the value types you need as key and or as value. Hope this helps and dosnt bring in more confusion.

best regards
Battery
Instructor
Original Poster
#17 Old 12th May 2018 at 6:10 PM
Unfortunately while the Dictionary works the value doesn't persist. If I save and reload the dictionary keys get removed.

I'm only posting part of the code.
Code:
[Persistable]
public class SavedData // the class.
{
[PersistableStatic]
public static Dictionary<ulong, ulong> SlaveMaster = new Dictionary<ulong, ulong>();

Why is this happening?
Lab Assistant
#18 Old 12th May 2018 at 6:21 PM Last edited by Battery : 12th May 2018 at 7:11 PM.
could you upload your whole project it would be easier for me to make tests myself and come up with an answer since its the weekend i got time to do a bit of testing

one thing you did implement the empty default constructor as i wrote right ?

One thing i always use when making dictionarys/lists persistable i forgot to include write the following to the default constructor:

if (SlaveMaster == null)
{
SlaveMaster = new Dictionary<ulong,ulong>();
}
and delete the above new Dictionary in the class itself

btw you dont need those things to be static since you got an instance if you have taken the singleton approach i suggested
Instructor
Original Poster
#19 Old 12th May 2018 at 10:19 PM
I have done this yes
[PersistableStatic]
public static Dictionary<ulong, ulong> SlaveMaster = new Dictionary<ulong, ulong>();

Ok I'll upload the project.
Instructor
Original Poster
#20 Old 12th May 2018 at 11:26 PM
Here is the DLL file. Keep in mind that I have been editing a lot of stuff in it. And have hastily made a lot of things comments for testing purposes. Check in the VampInteraction Namespace. The other two are not being used here.
Download - please read all instructions before downloading any files!
File Type: 7z NewBuff.7z (16.5 KB, 1 downloads) - View custom content
Instructor
Original Poster
#21 Old 13th May 2018 at 4:11 AM
While I'd still like to know the reason behind not persisting. I've decided to use another method to do this and that is to save the Master Vampire's ID inside the instance of the mind controlled moodlet. This I found a lot more efficient as well and it's working as well. Thanks again for all your help Battery
Lab Assistant
#22 Old 13th May 2018 at 7:05 AM Last edited by Battery : 13th May 2018 at 7:33 AM. Reason: Reading Failure
Uh ok i meant uploading the source code rather then the compiled dll, but i look into it and make a little example mod.

Uh and i could not find a pulbic constructor in your SavedData class you MUST have a public standard constructor for it to work !

E: ok just read that you got it working never mind then
Download - please read all instructions before downloading any files!
File Type: 7z saveData Example.7z (2.1 KB, 2 downloads) - View custom content
Instructor
Original Poster
#23 Old 15th May 2018 at 4:50 PM
Thank you for that Battery. It's very helpful
Back to top