Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Virtual gardener
staff: administrator
Original Poster
#1 Old 10th May 2021 at 12:32 PM Last edited by Lyralei : 13th Jul 2021 at 1:27 PM. Reason: Named it custom because that just sounds cooler :p
Default (Finished) Custom OpportunityLoader
Hey everyone!

I was talking to some people about adding your own custom opportunities and been using the Skill's way of parsing the xml file as a reference  After a lot of wrestling (And you might have known that if you saw the first version of this thread ;p) It's currently working flawlessly!

Before we get to the code, I really want to thank Arsil for creating a function that lets you add Enum Values to Enums! This isn't usually possible due to the nature of Enums

Here's the code for loading (And even specifically firing a particular opportunity, which can also be written to work for EA's own Opportunity!)

NOTE: THIS is SUPER long! So make sure to mentally prepare yourself for that :p



And of course, an example use! Sims:



Objects:



I've added the Solution with it's examples and code in the thread as well! And the example package so you know how to use it with the XML!

If you have any questions about adding your own custom opportunity or my code sets your computer on fire, then let me know too!
Attached files:
File Type: zip  OpportunityLoader.zip (366.0 KB, 17 downloads)
Description: Source Code VSproject
File Type: zip  OpportunityLoaderExample.zip (15.5 KB, 15 downloads)
Description: Example package
Advertisement
Field Researcher
#2 Old 13th May 2021 at 8:27 AM
There is a function to add enums?
Could you give me the link to that? I would really like to create custom Commodity Types to use in Ituns.
Virtual gardener
staff: administrator
Original Poster
#3 Old 13th May 2021 at 12:14 PM Last edited by Lyralei : 13th May 2021 at 12:26 PM.
Quote: Originally posted by KittyTheSnowcat
There is a function to add enums?
Could you give me the link to that? I would really like to create custom Commodity Types to use in Ituns.
No problem! 

It's actually inlined in the code, but here it is again, since it's a loooot of code, so It's hard to miss:

Code:
         // Arsil's enum function.
        public static void AddEnumValue<T>(string key, object value) where T : struct
        {
            Type typeFromHandle = typeof(T);
            EnumParser enumParser;
            if (!ParserFunctions.sCaseInsensitiveEnumParsers.TryGetValue(typeFromHandle, out enumParser))
            {
                enumParser = new EnumParser(typeFromHandle, true);
                ParserFunctions.sCaseInsensitiveEnumParsers.Add(typeFromHandle, enumParser);
            }
            EnumParser enumParser2;
            if (!ParserFunctions.sCaseSensitiveEnumParsers.TryGetValue(typeFromHandle, out enumParser2))
            {
                enumParser2 = new EnumParser(typeFromHandle, false);
                ParserFunctions.sCaseSensitiveEnumParsers.Add(typeFromHandle, enumParser2);
            }
            if (!enumParser.mLookup.ContainsKey(key.ToLowerInvariant()) && !enumParser2.mLookup.ContainsKey(key))
            {
                enumParser.mLookup.Add(key.ToLowerInvariant(), value);
                enumParser2.mLookup.Add(key, value);
            }
        }

// Usage would be something like:
// Do convert "MyCustomCommodityType" to a FNV64 in S3PE (Tools > FNV64) and then the converter below will convert it to a 16-numeric decimal for you 
AddEnumValue<OpportunityNames>("MyCustomCommodityType", Convert.ToUInt64(0x5BC056891B5FA161, 16));
Again, this is Arsil's way of parsing a custom Enum, so all credits goes to him! And Zoe for pointing it out :p 
Instructor
#4 Old 4th Sep 2022 at 9:20 AM Last edited by FloTheory : 4th Sep 2022 at 11:09 AM.
Hi Lyralei, thank you to both Arsil and you for joining forces and giving us this new means to create custom opportunities !
I'm loading up your solution in SharpDevelop and It doesn't build because of "PostInit" apparently.

The first thing that comes to my mind is : are you using custom libraries maybe ?

Edit : problem solved thanks to MissPat who gave me your custom DLLs !
Screenshots
Back to top