PDA

View Full Version : Scripting - Sim Stuck After Interaction


fway
19th Jun 2011, 4:07 PM
So I've been attempting to get away from making tuning mods and decided to look into pure scripting modding since it seemed like a better way to override/add new interactions to things in the game. I've read Buzzler's scripting modding tutorials and started referring to it when stuck as well as looking at sites that specialize in C# since I'm no expert at it.

Anywho, I wanted to make a script mod that keeps the game from charging Sims to take photos. I found the class I wanted to modify in ILSpy (can't afford Reflector) and had my script refer to the CameraTuning class.


using Sims3.UI;
using Sims3.SimIFace;
using Sims3.Gameplay.Skills;
using Sims3.Gameplay.Objects;
using Sims3.Gameplay.Objects.HobbiesSkills;
using System;
using System.Collections.Generic;
using System.Text;

namespace fwayFreePhotos
{
public class freePhotos
{
[Tunable]
protected static bool kInstantiator;
[Persistable(false)]
public class CameraTuning : Sims3.Gameplay.Skills.CameraTuning
{
[Tunable]
public int AdditionalCostToTakePhoto = 0;
}
}
}


I have the package all set up with "kInstantinator" in an XML file and the S3SA. I have a feeling that I'm doing something wrong at this point. After loading up my game I directed my sim to take a photo with a camera. The cost of the photo still came out to 22 Simoleons. After taking the photo, the interaction just stuck there and the Sim was standing doing nothing. I was wondering if I had to pull all of the calls.

I had CameraTuning refer to Sims3.Gameplay.Skills.CameraTuning because the CameraTuning in that line was referring back to my script. Should CameraTuning be referred to after freePhotos? Or is there an underlying problem? I also noticed that when I loaded my dll in ILSpy the script came out looking like this:


{
[Tunable]
public new int AdditionalCostToTakePhoto;
}


What is going on? The = 0 isn't showing up, but I can somewhat understand why "new" appeared.

Buzzler
19th Jun 2011, 5:09 PM
Anywho, I wanted to make a script mod that keeps the game from charging Sims to take photos.In that particular case, a tuning mod might be better suited. It is possible to do the same thing with a scripting mod, but it usually only makes sense if you you only want to change single fields from big-ish XMLs or make lots of changes spread over a lot of classes.

Now what your code does is define a new CameraTuning class, but it doesn't assign that anywhere. That's why it's not used. That your sim gets stuck after taking a photo is probably caused by the photography bug that emerged with the Generations patch.

To change the AdditionalCostToTakePhoto field with a scripting mod, use the mod frame from the pure scripting tutorial and in the OnWorldFinished() method, overwrite the fields like that:

CameraCheap.kCameraTuning.AdditionalCostToTakePhoto = 0;
(kCameraTuning may not be accessible by default. If that's the case, you need to alter the core libraries you compile against like explained in the core modding tutorial to change the access modifier to public.)

What is going on? The = 0 isn't showing up, but I can somewhat understand why "new" appeared.The "new" is actually not ok. Are you using the latest version of ILSpy? You can probably find the assignment in the static constructor (.cctor()).

fway
20th Jun 2011, 8:54 PM
In that particular case, a tuning mod might be better suited. It is possible to do the same thing with a scripting mod, but it usually only makes sense if you you only want to change single fields from big-ish XMLs or make lots of changes spread over a lot of classes.

Now what your code does is define a new CameraTuning class, but it doesn't assign that anywhere. That's why it's not used. That your sim gets stuck after taking a photo is probably caused by the photography bug that emerged with the Generations patch.

To change the AdditionalCostToTakePhoto field with a scripting mod, use the mod frame from the pure scripting tutorial and in the OnWorldFinished() method, overwrite the fields like that:

CameraCheap.kCameraTuning.AdditionalCostToTakePhoto = 0;
(kCameraTuning may not be accessible by default. If that's the case, you need to alter the core libraries you compile against like explained in the core modding tutorial to change the access modifier to public.)

The "new" is actually not ok. Are you using the latest version of ILSpy? You can probably find the assignment in the static constructor (.cctor()).

I did make a tuning mod for this, but if I choose to change the photo filter the price of the filter still stays, however instead of being 16 simoleons, it becomes 6. I felt overriding with a scripting mod will get rid of the price.

Do you mean replace OnWorldFinished() with


AdditionalCostToTakePhoto(int i)
{
i = 0
}


Right?

Wouldn't it make more sense to use CameraTuning? This is where AdditionalCostToTakePhoto is located.

I am using the latest version of ILSpy.

P.S. I did remove my mod from the game and I do have the Photography bug. :faceslap: I'll wait for that to get patched (if ever...), or hope that another save won't have this bug. Without this being fixed I can't tell if my mod is working, so I have EA to thank.

Buzzler
20th Jun 2011, 9:25 PM
I did make a tuning mod for this, but if I choose to change the photo filter the price of the filter still stays, however instead of being 16 simoleons, it becomes 6. I felt overriding with a scripting mod will get rid of the price."photo filter"? There are three XMLs for the cheap, medium and expensive camera and surely there's one for the cell phone as well. Also, note how it is called "additional"? ;) The base costs are defined in Photography_0xc7b5d2f8b46b5305.

The cost for a photo gets calculated in Photography.GetCostToTakePhoto() BTW.

Do you mean replace OnWorldFinished() with {...} Right?I fail to see what good that would do.

Wouldn't it make more sense to use CameraTuning? This is where AdditionalCostToTakePhoto is located.Yes and no. ;) CameraTuning is a class, a blueprint so to speak. By defining a new CameraTuning class (like in your first post), you accomplish nothing, or at least nothing useful in this context. What you want to do (trust me on that ;) ) is change an actual entity, an instance, of the CameraTuning class.

Have a look at the CameraCheap class and there at the CameraTuning property. public override CameraTuning CameraTuning
{
get
{
return kCameraTuning;
}
}The name of the property is CameraTuning and it's supposed to return an instance of the CameraTuning class. As you see it returns kCameraTuning which is a static, tunable field of CheapCamera. All instances of CheapCamera return this same field (unlike beds for example which have individual tuning instances). And if you look at the static constructor, you see how that field gets instantiated:static CameraCheap()
{
kCameraTuning = new CameraTuning();
}Thus if you assign zero to CheapCamera.kCameraTuning.AdditionalCostToTakePhoto like shown in my previous post, that will apply to all cheap cameras, i.e. instances of CheapCamera. You need to do the same for the other camera classes.

HTH