PDA

View Full Version : Tutorial: Sims 3 Localized Coding


Buzzler
18th Feb 2011, 08:03 PM
The Tutorial

The tutorial is located in the wiki: Tutorial:Sims_3_Localized_Coding

Questions

If you have questions concerning the tutorial, this thread is the place to ask them.

cmomoney
18th Feb 2011, 08:58 PM
Another good one, Buzzler. Keep up the good work. :)

Enirei
25th Mar 2011, 12:00 AM
I'm new at modding and I'm getting errors about cannot change access modifiers when I copy the code given in the tutorial and try to build it to get the dll. I set up the Assembly file as shown in the Tutorial:Sims 3 Pure Scripting Modding (http://www.simswiki.info/wiki.php?title=Tutorial:Sims_3_Pure_Scripting_Modding) .

This is my code in my SayHello class:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sims3.Gameplay.Interactions;
using Sims3.Gameplay.Actors;
using Sims3.Gameplay.Autonomy;
using Sims3.SimIFace;
using Sims3.UI;


namespace Enirei
{
class SayHello : ImmediateInteraction<Sim, Sim>
{
public static readonly InteractionDefinition Singleton = new Definition();

public override bool Run()
{
string message = Localization.LocalizeString("Enirei/LocalizedMod/SayHello:Message", new object[] { base.Target });
base.Actor.ShowTNSIfSelectable(message, StyledNotification.NotificationStyle.kSimTalking);
return true;
}

[DoesntRequireTuning]
private sealed class Definition : ImmediateInteractionDefinition<Sim, Sim, SayHello>
{
public override string GetInteractionName(Sim a, Sim target, InteractionObjectPair interaction)
{
return Localization.LocalizeString("Enirei/LocalizedMod/SayHello:InteractionName", new object[0]);
}
public override string[] GetPath(bool isFemale)
{
return new string[] { Localization.LocalizeString(isFemale, "Enirei/LocalizedMod/SayHello:Path", new object[0]) };
}
public override bool Test(Sim actor, Sim target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
{
return !isAutonomous;
}
}

}
}

I changed TwoBTech to Enirei since that was the namespace I was using.

Any help or suggestions that could be given would be greatly appreciated. Thanks.
Any help that could be gi

Buzzler
25th Mar 2011, 12:04 AM
Enirei, change the access modfiers of the overridden methods from public to protected and it should compile.

Enirei
25th Mar 2011, 04:11 AM
Thanks :)

Enirei
25th Mar 2011, 07:02 PM
Another thing is happening that I'm not sure about. I make the stbl file and add it to the package as in the tutorial. I put the package in to test it but I don't seem to have the say hello interaction. I look at the preview for the stbl file and it shows this:
Unknown1: 0x0000
Unknown2: 0x0000
Unknown3: 0x00000000
Key: 0xEFCFE0322BC7EB08 = Value: 'Say Hello'
Key: 0x233597618807DF5A = Value: '{MA.Whiny}{FA.Grumpy} Interactions'
Key: 0x7E6CB1745A6AB764 = Value: 'Hello, {0.SimName}!'

Again, any help/suggestions would be greatly appreciated.

Buzzler
25th Mar 2011, 07:22 PM
The FNV64 hash of "Enirei/LocalizedMod/SayHello:Message" is 0x3345B37043CBFBB2. I don't see that listed. When you change the string keys, e.g. from "TwoBTech/LocalizedMod/SayHello:Message" to "Enirei/LocalizedMod/SayHello:Message", you need to change that in the text file as well, not only in the code.

Enirei
25th Mar 2011, 08:14 PM
Oops. I had typed and retyped that part, when I re-pasted it, I forgot to change it again. Saved the package and noticed something when I looked at the STBL file. It says:
Error reading resource 220557DA:00000000:06F1866BA6BEEEC3
Front-end Distribution: 10-1104-1243
Library Distribution: 10-1104-1243

Source: mscorlib
Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Exception has been thrown by the target of an invocation.
----
Stack trace:
at System.RuntimeMethodHandle._InvokeConstructor(Object[] args, SignatureStruct& signature, IntPtr declaringType)
at System.RuntimeMethodHandle.InvokeConstructor(Object[] args, SignatureStruct signature, RuntimeTypeHandle declaringType)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at s3pi.WrapperDealer.WrapperDealer.WrapperForType(String type, Int32 APIversion, Stream s)
at s3pi.WrapperDealer.WrapperDealer.GetResource(Int32 APIversion, IPackage pkg, IResourceIndexEntry rie, Boolean AlwaysDefault)
at S3PIDemoFE.MainForm.browserWidget1_SelectedResourceChanged(Object sender, ResourceChangedEventArgs e)
----

Source: mscorlib
Assembly: mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
Unable to read beyond the end of the stream.
----
Stack trace:
at System.IO.__Error.EndOfFile()
at System.IO.BinaryReader.FillBuffer(Int32 numBytes)
at System.IO.BinaryReader.ReadUInt64()
at StblResource.StblResource.Parse(Stream s)
at StblResource.StblResource..ctor(Int32 APIversion, Stream s)
----
Any help/suggestions?
Thanks for being patient with me.

Buzzler
25th Mar 2011, 08:30 PM
Now that is interesting. I've seen that a couple times and reported it to Peter Jones, but since I was unable to re-enact it and nobody seemed to have these issues, I thought the cause was my computer. Seems like it's a general issue after all. You might want to report that over at Simlogical. Since the issue can't be provoked, Peter probably won't be able to do much about it unless he stumbles over it by chance. Still, is the right thing to tell him.

The solution is pretty simple, though. Just delete the resource and add a fresh one in its place.

Enirei
25th Mar 2011, 09:25 PM
The thing is that I've gotten this result after deleting and adding a fresh one multiple times... T.T I seem to have bad luck with modding.

Question: how come in your Clean House for everyone mod you don't have an stbl file, instead an itun and and xml?

Buzzler
25th Mar 2011, 09:36 PM
The thing is that I've gotten this result after deleting and adding a fresh one multiple times... T.T I seem to have bad luck with modding.Whoa, seriously? Off you go to Simlogical to report that error and upload the exact files (package and stbl) to re-enact that error! You can also upload them here (package and source txt file) and I'll have a look if there's a workaround.

Question: how come in your Clean House for everyone mod you don't have an stbl file, instead an itun and and xml?I don't need string tables in that mod, because I'm using strings the game already has. The ITUN is the interactions's tuning; the XML is for instantiating the mod and a couple tunable values to configurate the mod without having to change the code.

Enirei
25th Mar 2011, 10:56 PM
Okay. I just created an account with Simlogical. Should I post it under sp3e downloads and support?

Here's a zip with my package, my text file, and my stbl file. Thanks.

Buzzler
26th Mar 2011, 07:48 AM
Okay. I just created an account with Simlogical. Should I post it under sp3e downloads and support?Seems like the right place, yes. Make sure to post the error message from above as well.

Here's a zip with my package, my text file, and my stbl file. Thanks.Hmm, I can't re-enact that error as always. I delete the STBL resource, then create the new one (actually I imported the STBL) and it's there without error. What are you doing exactly?

Enirei
26th Mar 2011, 05:14 PM
I create a new resource, set it as an STBL, the group 0x0 and the instance 0x06F1866BA6BEEEC3. Then I do "replace" with the STBL that I created.

Okay. I just tried it as importing the STBL and not doing the replace and it seemed to work just fine for building the package. Also, if I decide I want to do the replace function on the STBL I did the import on, it works fine... So it seems to not like me if I do a replace on an empty STBL resource. Weird.

I can't seem to find the interaction anywhere now when I load the game. Further testing in this area is needed.

Buzzler
26th Mar 2011, 05:29 PM
Perhaps there's a bug with the replace function?That may very well be the case.

Enirei
26th Mar 2011, 06:24 PM
I posted it to Simlogical. My testing seems to show it does not like doing a Replace on an empty STBL file created by Add Resource. When I did the import and then wanted to replace that file later on, it worked fine. Though as of right now I can't find the new interaction within the pie menu. T.T Mod creating does not agree with me it seems.

Thanks for your patience.

Buzzler
26th Mar 2011, 07:44 PM
Though as of right now I can't find the new interaction within the pie menu.I just looked at your code in Reflector. You only have the interaction, but it just sits there and doesn't get used. The point of the localized coding tutorial is not to get you started in script modding, but to get you started in writing localized code *after* you started script modding. Please refer to Tutorial:Sims_3_Object_Modding to see how an interaction gets added to an object.

Enirei
26th Mar 2011, 08:36 PM
gack! I thought I was forgetting something. Thanks.

jtravers88
9th Apr 2011, 10:38 PM
The tutorials for pure scripting are great.

What I can't find a clue on how to do is dictating what submenu in the pie menu that an interaction should go.

For instance, the Say Hello example defaults to the main menu when clicking a target sim. How would you specify that you want your interaction button to appear under Friendly, Mean, Funny, or Romantic?

I can't see anything in any xml or the core that gives a clue how to do this.

It's probably something simple...

Buzzler
9th Apr 2011, 11:19 PM
How would you specify that you want your interaction button to appear under Friendly, Mean, Funny, or Romantic?You can do that with the GetPath() method. If you want an interaction to show up under "Friendly" for example, you make GetPath() return new string[]{"Friendly"}; Localized of course, since this is the localized coding Q&A thread you're in. ;)

jtravers88
9th Apr 2011, 11:38 PM
You can do that with the GetPath() method. If you want an interaction to show up under "Friendly" for example, you make GetPath() return new string[]{"Friendly"}; Localized of course, since this is the localized coding Q&A thread you're in. ;)

I knew GetPath probably had something to do with it. But I couldn't find an example of "Friendly" or "Romantic" anywhere in this fnc declaration of any definition.

Thanks I'll try that out.

Buzzler
9th Apr 2011, 11:52 PM
I knew GetPath probably had something to do with it. But I couldn't find an example of "Friendly" or "Romantic" anywhere in this part of any definition.You will hardly find any hardcoded strings in the game code anyway. The Friendly/Mean/etc. paths belong to the social interactions. These are parsed and built from an XML resource and use a single blueprint interaction. You will not find a Chat interaction in the code for example.

jtravers88
10th Apr 2011, 02:08 AM
You will hardly find any hardcoded strings in the game code anyway. The Friendly/Mean/etc. paths belong to the social interactions. These are parsed and built from an XML resource and use a single blueprint interaction. You will not find a Chat interaction in the code for example.

Friendly and Friendly... don't work.

It adds a new selection to the top level of the pie menu, even if identical to the Friendly that already exists.

Twallan puts two interactions under the Friendly... in his woohooer mod. Gauge Attraction and Check Attraction. So far I haven't tracked down what causes it.

Buzzler
10th Apr 2011, 02:33 PM
Yeah, I ran into that a couple times myself.

Try
new string[]{ CommodityData.Get(str).GetChangeToneText() }
str can be "Friendly", "Insulting", "Funny" or "Amorous" for your purpose.

("Friendly" + Localization.Ellipsis) might work as well, but it would be better to use localized code from the start.

smochina4000
7th Sep 2011, 10:34 AM
How can I make a mod like "Driving cars cost money" ,"cell phones cost money"? It is possible? Thank you!

Buzzler
8th Sep 2011, 04:39 PM
smochina4000, that is way off topic in this thread. Please read the pure scripting tutorial to get going and then refer to the modding discussion forum to get direction.

smochina4000
8th Sep 2011, 07:56 PM
Thank you! OK, I will search more.

jtravers88
17th Sep 2011, 02:43 AM
I just looked at your code in Reflector. You only have the interaction, but it just sits there and doesn't get used. The point of the localized coding tutorial is not to get you started in script modding, but to get you started in writing localized code *after* you started script modding. Please refer to Tutorial:Sims_3_Object_Modding to see how an interaction gets added to an object.

He is doing a sim to sim interaction, not sim to object. How do you add an interaction in that case?

Buzzler
17th Sep 2011, 08:51 AM
He is doing a sim to sim interaction, not sim to object. How do you add an interaction in that case?Read the pure scripting tutorial to make the basic frame for a object-less mod.

Then, in the OnWorldFinished method, you can find all objects you want to add the interaction to by calling
Sims3.Gameplay.Queries.GetObjects<T>(); where T is any class that is a GameObject, e.g. Fridge. It returns an array of T.

To add your interaction to it, you call every object's AddInteraction method. Don't forget to check whether the object already has the interaction or you'll end up with your interaction being present multiple times.


Again, this is completely off-topic in this thread, so if you have further questions, please use Modding Discussion.

sarita_22_35
6th May 2012, 03:06 PM
I would like more advanced codding tutorials, learning things about sims 3 Class Libreries, have access to the function description and code my own packages as I want. I have so many ideas and don't know how to start.....