Replies: 26 (Who?), Viewed: 3865 times.
Page 1 of 2
Inventor
Original Poster
#1 Old 8th Dec 2014 at 12:10 PM Last edited by Arsil : 23rd Jan 2015 at 1:05 PM.
Default [SOLVED] Assigning start and end hours to a Role
PREMISE: I'm making custom cash registers that inherit from the ShoppingRegister class.
That class implements the interface IRoleGiver that allows to assign a Sim to the rolegiving
object (automatically or using NRaas Register).

Roles are defined in the NpcRoles _XML. The merchant role has no starting and ending hour,
so the employee will work 24/7 (I hope this is an expression used also in English, it means
24 hours a day, every day of the week). I don't want to override that XML for two reason:
- I'll still end up with fixed hours (I want every single register to have its own opening/ending hours)
- Compatibility with other mods that override that resource (I don't know if there are such mods,
but even theoretically I don't like the idea of overriding a resource if not strictly necessary).

There's an important exception to this behaviour: if the register is in a lotType/venue with
opening/closing hours (LN bars or UL CoffeeShop for example) then the employee will start
and stop working following the venue hours.

I'm making my custom cash registers basegame compatible, so I don't want the users to
be forced to use a certain lot type nor I want to override the Venues _XML for the same reasons
I don't want to override the NpcRoles _XML. OT: But out of curiosity I'd like to know if it's possibile
to add custom lotTypes/venues without editing/overriding that resource, in a similar way
we add new recipes/ingredients. For my mod it would be nice to have a Market venue
usable in a not Vacation world for example, but it would be nice also to have your own
custom venues in general... sorry I'm wandering off as always.

Let's go back and talk about IRoleGiver. The more interesting part to me are its 3 methods:
- PushRoleStartingInteraction
- AddRoleGivingInteraction
- RemoveRoleGivingInteraction
Thank goodness they are implemented as virtual methods in ShoppingRegister, so you
can override them. What I tried was put conditions in my PushRoleStartingInteraction so
the TendRegister interaction is used only if the time is right. I verified that my version
of the method is used, but the employee keeps working all the time.

I also tried modifying in the same way AddRoleGivingInteraction (I'm not sure I understand
its purpose, it removes all buying interaction from the queue of the employee and then adds
a new one) but this didn't work either.

Then I tried writing my own version of the TendRegister interaction, adding the time
check in the Test method of the interaction definition but this makes the employee
"go crazy" (he tries repeatedly to use the interaction and then cancels it, so he gets stuck).

Then I discovered the IRoleGiverExtended interface that includes working hours. I implemented
its method GetRoleTimes in my class but that's not enough, maybe there's something else to do
to make it work. Call me naive, I hoped that was sufficient to make it work ^^
I think this (along with understanding how the venue type influences the role) is the best chance
to get what I want, but I still have to understand how it works.


It's not that I want at any cost to use the official EA role/system for my cash registers, but
I'd like to do it that way. By the way, that system has a few issues, even using NRaas Register:
- if the employee is invited to a party he will lose his role and his "link" to the register;
- if a member of his household celebrates a birthday, the employee (only if selectable?)
goes to celebrate and loses his role.
- probably other situations
Also the fact that the role blocks motives when active can be a bit annoying, above all the
energy motive (sims wont ever need to sleep). This is an issue especially if you assign
selectable sims to the registers, but I think my mod is more suited for unselectable sims
(or at least that's how I plan to use it in my gameplay). Would be nice to add custom roles,
but they are tied to an "enum" so I doubt it's possible.
I could try to implement my own system to send employers to work (like the industrial oven or
ani_'s "Produce Stand") but I'd rather use the same system of the official registers for consistency.

My custom food store register is ready (I plan to make at least another kind of register)
but I'd like to add configurable working hours (and with them an option to wear the career
outfit) to complete it.

Someone has experience with this stuff or wants to help me? I have a feeling it's possible.
EDIT: if needed, I'll upload the package here, even if that means spoiling it :P
Advertisement
Instructor
#2 Old 8th Dec 2014 at 12:55 PM
But wait: didn't the savvy seller mod at official Sims 3 offer similar stuff?
Not discouraging you, I'm only saying to see if there's really need to work on so much. I didn't have time to read all of it so I don't know whether there are things that differ with what is on the market.
Inventor
Original Poster
#3 Old 8th Dec 2014 at 1:52 PM Last edited by Arsil : 8th Dec 2014 at 2:35 PM.
Good point. I personally don't like how that premium content works and I think is more suited if you want to start
a business with your selectable sims (and anyway ani_'s overhaul or her other mods are much better than that).

As always, I'm doing this mod for myself and I just wanted configurable registers to make markets/stores/stands/kiosks
that my sims can use as customers, not as workers/employees. Anyway, before working on it I asked and received
ani_'s permission because I knew there was the risk to end up with similar mods, not in the implementation but in
the purpose. Her permission is what matters to me, I couldn't care less if my mod is similar to a premium content
item, not to mention that not everybody has it (me for example, I only saw how it works in reviews/videos).

EDIT: While doing further researches, I found a "goto" in the code. A GOTO! Last time I saw one was when
I programmed in Basic on a Commodore 64! (yeah, I'm kinda old). I'm just kidding, I know sometimes there
is a good reason to use them but it was still shocking.
Test Subject
#4 Old 8th Dec 2014 at 3:52 PM Last edited by Blackcatluna : 8th Dec 2014 at 4:44 PM.
I'm working on a custom role at the moment too

Here's the methods I used to create my own work hours, based on the methods used for the bartender, with the time deltas and the default work hours for community lots without opening hours both made tunable.

This one is in the role's class

Code:
public static void GetDJRoleTimes(out float startTime, out float endTime, Lot.MetaAutonomyType venueType)
         {             
             startTime = kDJRoleDefaultStartTime;
             endTime = kDJRoleDefaultEndTime;
             Bartending.BarData barData;
             if (Bartending.TryGetBarData(venueType, out barData) && barData.HasHours())
             {
                 startTime = barData.HourOpen - kDJRoleStartTimeDelta;
                 endTime = barData.HourClose + kDJRoleEndTimeDelta;
             }
         }


This one is in the role giver's class

Code:
public void GetRoleTimes(out float startTime, out float endTime)
         {
             if (base.LotCurrent == null)
             {
                 startTime = 0f;
                 endTime = 0f;
                 return;
             }
              DJRole.GetDJRoleTimes(out startTime, out endTime, base.LotCurrent.GetMetaAutonomyType);
         }


I didn't tested mine in game yet, but I hope this will help!

If you want to unfreeze some of the role npc's motives you will probably have to override StartRole() and maybe overriding IsSimGood() will be necessary too if it keeps returning false while the sim is in a party because it's likely that it's the cause of the dissappearing roles.

There's also some custom roles made by misukisu at Virtual Artisan and they work very well with Register. It's definitly worth a look if you want to learn how to make your own ones.
Inventor
Original Poster
#5 Old 8th Dec 2014 at 4:44 PM
Thanks! I'll check that later. I was hoping to not need to create a new role, but, hey, if I have to...
Can I ask you how do you plan to add your custom role to the game?

By the way, I discovered the trick to use the CODE tag without having the annoying interline:
you just have to write "code" all lowercase.
Test Subject
#6 Old 8th Dec 2014 at 5:24 PM Last edited by Blackcatluna : 8th Dec 2014 at 5:57 PM.
Sure, here's how I plan to do it.

I have to make a new role class derived from an existing one or maybe derive it from Role then override the Type method to make it return an existing RoleType otherwise it won't work because the role giver's RoleType method uses the RoleType enums to link itself to a role.

Since I want to turn one of EA's objects into a role giver, I will also derive my new role giver's class from the object and IRoleGiver then derive clones of the derived classes of the original object (if there are any) from my role giver class, then override their OBJKs in my package so that they link to them to make them functional.

After that, if all the necessary code is there for the things to do when the role starts, the things to do when the role ends, the interactions, etc....it should work by itself when you add the role giver item to a lot.
Inventor
Original Poster
#7 Old 8th Dec 2014 at 9:35 PM
Thanks again Blackcatluna, please let me know if that works, ok? ^^

OT and dumb question: I added another class to my code to be used for a second kind of cash register.
I assigned the class to the OBJK but in game I can't click on the object, I can see the object name
when the mouse hovers on it but when I click no interactions shows up. This happened to me
before but I don't remember the cause of the problem, I'm sure I'm missing something trivial.
Test Subject
#8 Old 8th Dec 2014 at 11:38 PM
Did you forgot to derive your second cash register's class from the original one by chance?
Inventor
Original Poster
#9 Old 9th Dec 2014 at 11:09 AM Last edited by Arsil : 9th Dec 2014 at 11:32 AM.
Nope. Here's how I organized it:

- I made an abstract class, AbstractStoreRegister, that inherits from ShoppingRegister (which is abstract too),
ans I use it as a common class for the features that all my custom cash registers share.
- Then I made the FoodStoreRegister class that inherits from AbstractStoreRegister and assigned it to the
OBJK of the first register.

All works fine till this point.

- Then I duplicated the OBJD and OBJK resources of the first register (all other resources are shared),
changed their IID, updated the reference to the OBJK's TGI in the OBJD, created a new catalog
name/description (both as keys and as hashes in the OBJD), added those keys/translations to the
STBLs and set as script name in the OBJK another class, InventoryStoreRegister, this too derived
from AbstractStoreRegister, but in game this doesn't seem to work, it has no interactions,
not the common/shared ones nor its specific ones.

I must have skipped a step somewhere.
Test Subject
#10 Old 9th Dec 2014 at 7:37 PM
I think that you also need to change the OBJKIndex in the materials in the OBJD and it seems like the OBJK needs to share its IID with the OBJD to work well too.
Inventor
Original Poster
#11 Old 9th Dec 2014 at 9:25 PM
Registers have no Materials block in the OBJD, they use 2 TXTC and a _XML for the complate
(I'll save you how many headaches that caused to me). OBJD and OBJK have the same IID
(but I don't think that's mandatory). I also tried cloning the object properly with S3OC to see if
my "manual cloning" was flawed, but that was not the problem.

I'm starting to run out of ideas and get a bit demoralized. I've made no progress with the working
hours either and I couldn't pinpoint yet how/where the lot's opening/closing hours "override" the
role starting/ending hours.

Enough with the whining, I'll take a break and try again with a fresh mind. Your support is very
much appreciated and I'm looking forward to hear more about you DJ-Role, seems interesting.
Test Subject
#12 Old 10th Dec 2014 at 12:06 AM Last edited by Blackcatluna : 10th Dec 2014 at 12:51 AM.
Thanks!
I found it odd that it wasn't included in showtime at all, it would have been great for dance clubs

The lot's opening/closing hours are actually the barData.HourOpen (Bartending.BarData.HourOpen) and barData.HourClose (Bartending.BarData.HourClose) in GetDJRoleTimes's if block that checks if the lot has opening hours. Along with two tunable floats they are used in the calculation of the role's work hours (startTime and endTime) but if the if block returns false, the default hours above will be used instead. After that, the GetRoleTimes method will tell to the role giver that these are the moments where they should start and end the role and that no one should come if the object has no current lot.

Also, with that unusual file structure it would be very helpful if you upload your package too, maybe I could find something.
Inventor
Original Poster
#13 Old 10th Dec 2014 at 11:36 AM Last edited by Arsil : 23rd Jan 2015 at 1:06 PM.
Here it is. If you want I'll post the sourcecode too, but that is a mess,
it's full of commented code I used while experimenting.

If you want to test it in game, my 2 registers are between the other registers
(Build/Community/Misc in the Catalog, placeable only on Community lots).

The "change to career outfit" option doesn't work either (I want to "link" it to the working hours option).

In theory doesn't require any EP and should be basegame compatible (v1.67).

I think the first register, FoodStoreRegister, is working fine, but the second one,
InventoryStoreRegister, is still in a early phase of development, so even if
"unlocked" it will not work.

WARNING: Don't use this in a savegame you care about, it's still experimental.

EDIT: Attachment removed since now the mod is officially available for download.
Inventor
Original Poster
#14 Old 10th Dec 2014 at 6:37 PM
In the meantime I tried to add a custom venue to the game, using an instantiator and
a method to read data from a xml (with the definitions copy/pasted from a WA Market
venue), but that didn't work. I had also prepared the icons and the STBL, too bad

Test Subject
#15 Old 10th Dec 2014 at 9:02 PM Last edited by Blackcatluna : 10th Dec 2014 at 9:15 PM.
Thanks for the upload!

I just tried to test your mod in game but for some reason both registers didn't appeared in the Build mode catalog at all...After that I recategorised them in Electronics/Misc but I still couldn't find them there either.

Something must be wrong with the OBJDs

And for your custom MetaAutonomyType I imagine that to make it work you will have to make a script similar to the one used in this tutorial :
Tutorial : Sims 3 New LTW

SimsMX also used this tutorial to make his hypochondriac trait. I tried to add a new RoleType that way too but it didn't worked, you really have to take an existing one sadly (that also means that if you don't override most of the methods used in the base role class your role will also take the RoleData of the type you use).
Inventor
Original Poster
#16 Old 10th Dec 2014 at 9:07 PM
They are available only on community lots.

Oh, nothing is going right on the TS3 side,
but at least John C. McGinley is back on air.

Damn it, I fail also with rhymes.
Test Subject
#17 Old 10th Dec 2014 at 9:20 PM Last edited by Blackcatluna : 10th Dec 2014 at 9:42 PM.
What's odd is that they weren't in the catalog when I edited community lots either, I checked that too while I tested
Inventor
Original Poster
#18 Old 10th Dec 2014 at 9:46 PM Last edited by Arsil : 12th Dec 2014 at 1:29 PM.
I don't know what to say, I just tried the package I uploaded and they are there (I don't
think they need WA EP, one of my main goals was to make them basegame compatible).
EDIT: Screen shot removed. See post #22.

I'll read the tutorial you linked more carefully later, but I haven't found
any enum for the venues (that's what you meant?).

Anyway, thanks for all the time you are dedicating to me ^^
Test Subject
#19 Old 10th Dec 2014 at 10:36 PM
You're welcome
I'll keep testing to see if I can fix it, I will give you news soon if I find anything else.

For your custom venue you will need the MetaAutonomyType enums. They are at Sims3.Gameplay.Core.Lot. They may sound like they are only there for the sims' autonomy but they are used as the game's venue types too.
Inventor
Original Poster
#20 Old 11th Dec 2014 at 11:51 AM Last edited by Arsil : 11th Dec 2014 at 12:02 PM.
I see. The entries on that enum seem to correspond to the values of the tag <CommercialLotSubType>
(that also use the prefix kEPn_) of <CommuntyiTypes> blocks (the typo is on purpose, that's how is
spelled on the xml and also in the STBL keys) in the Venues _XML. Example: Market --> kEP1_Market.

The good news is that for what I'd like to do (add a market lot usable on non-vacation worlds) I can re-use
the Market enum entry. There are 4 market venues defined with <Venue> blocks, 2 (normal and small) are
specific for France and 2 (normal and small) for any other vacation worlds that are not France, so I think
you can add more of them without worrying about enum entries.

The weird thing is that I see no connection between <Venue> blocks and their respective <CommuntyiTypes>
blocks or between <Venue> blocks and those enum entries.

Understanding how this works and actually being able to add a custom lot/venue is not my priority, to me
it's more important to add working hours to the registers (and "unlock" that damn second register), but I
have to say that now I'm intrigued by all this.
Test Subject
#21 Old 12th Dec 2014 at 1:42 AM Last edited by Blackcatluna : 12th Dec 2014 at 1:58 AM.
Ohh so that's what you were trying to do!
I know an even easier way to allow you to make a market venue outside vacation worlds, no need to create a new enum, just type this in the cheat console while you're in edit town in order:

testingcheatsenabled true
enableLotLocking on

After that you will be able to turn a lot into any venue type without restriction and even make diving areas and tombs in your home world with it

Sorry, I'm afraid I haven't found anything new for your role yet, I didn't had much time to test it today
Inventor
Original Poster
#22 Old 12th Dec 2014 at 10:19 AM Last edited by Arsil : 12th Dec 2014 at 12:00 PM.
Quote:
Originally Posted by Blackcatluna
Ohh so that's what you were trying to do!
I know an even easier way to allow you to make a market venue outside vacation worlds, no need to create a new enum, just [CUT]


I didn't know that cheat, good to know, but mine is just curiosity if a new venue can be added with a pure
script mod (I could simply override the venues xml to disable the world restrictions on markets if I just
wanted to achieve that result). And maybe creating a new enum isn't needed. I hope so.

I updated the upload of my mod in post #13, now you should find the registers. I'm very sorry, that
package was messed up by a S3OC renumbering or something like that and I have no idea why I
could still see them even after clearing every cache files (world included) and starting a new game.
If you are so kind to download that again and give it a try (even just to give me some feedback on the mod).
Test Subject
#23 Old 12th Dec 2014 at 10:56 PM Last edited by Blackcatluna : 13th Dec 2014 at 4:02 AM.
Quote:
Originally Posted by Arsil
I updated the upload of my mod in post #13, now you should find the registers. I'm very sorry, that
package was messed up by a S3OC renumbering or something like that and I have no idea why I
could still see them even after clearing every cache files (world included) and starting a new game.
If you are so kind to download that again and give it a try (even just to give me some feedback on the mod).


Thank you! I'll test it again

Edit: Yep I found them in community/misc like expected. I tested the food register a bit and apart from a "null value was found" error when I closed the receipe selection window that didn't happened again afterwards, everything looks fine. The roles were also filled by the game without problem, with the role sims routing there and all, but it seems like they never leave after the closing hours. The inventory register, of course, still has no interactions either.

One more edit: I changed the inventory register's OBJK's script class to the food register's one and the food register's interactions appeared just fine on the inventory register in game after that so I'm pretty sure that the issue comes from the inventory register's script class itself.
Inventor
Original Poster
#24 Old 13th Dec 2014 at 9:25 AM
Quote:
Originally Posted by Blackcatluna
"null value was found" error when I closed the receipe selection window that didn't happened again afterwards

I couldn't reproduce it, but I'll try to make the code more robust.

Quote:
it seems like they never leave after the closing hours.

Right. If the register is indoors they are kicked out of the building (but stay on the lot),
keep being paid and seem unable to do anything autonomously, they just wait till they
can reach the register again. Sometimes, after being kicked out, they also lose the
motives' lock (not sure how to reproduce this) and that is restored at a apparently
random time.

Quote:
I changed the inventory register's OBJK's script class to the food register's one and the food register's interactions appeared just fine on the inventory register in game after that so I'm pretty sure that the issue comes from the inventory register's script class itself.

Yep, we had the same idea, I did that very test yesterday. The problem is in the code,
maybe it's because it's not complete and doesn't fulfil all requirements to be qualified
as a General register type. Honestly I'm not even sure if the concept for that register
is good, because not all items are drag-and-drop-able.
Field Researcher
#25 Old 23rd Dec 2014 at 11:49 AM
Quote:
Originally Posted by Arsil
EDIT: While doing further researches, I found a "goto" in the code. A GOTO! Last time I saw one was when
I programmed in Basic on a Commodore 64! (yeah, I'm kinda old). I'm just kidding, I know sometimes there
is a good reason to use them but it was still shocking.


Just a note that what you're looking at is a Reflection-based decompilation of the binary .NET code, not the true source code. EA's in-house code most likely doesn't have the goto there -- it was probably automatically inserted as an optimisation by the compiler when they compiled it. =)
Page 1 of 2
Back to top