PDA

View Full Version : Add item to Inventory?


Phaenoh
13th Nov 2011, 9:16 PM
Ok, I hate the search function, it never seems to find me anything useful anymore.

I'm sure this is a relatively simple question, but my google-kung-fu has failed me. I'm working on a Major right now, and I want it to automatically purchase a few class supplies for me each time my sim makes it to the next semester. What BHAVs do I need to create an object in the inventory? I don't actually know where I need to stick them yet, but I imagine I can find it out easy enough.

xiaoyun
14th Nov 2011, 3:34 AM
This will put item of guid 0x8B2ED8D9 (which is some chair) into current active sim inventory
(It uses only primitives so should be any EP compatible)


; get current active sim nID to temp(0)
0 [prim 0x0002] Expression(StackObjectID 0x0000:=Global 0x0003 (SelectedPersonID)) T:1 F:F
0x0002 : 0000030000050A060000000000000000 T:1 F:F

1 [prim 0x0002] Expression(Temp0x0000:=StackObject's persondata 0x001F(neighborid)) T:2 :F:F
0x0002 : 00001F00000508130000000000000000 T:2 F:F

; guid of item which we want give to sim
2 [prim 0x002A] Create New Object Instance (GUID 0x8B2ED8D9,
place: out of world (put new object id in Stack Object),
Create object normally,
fail if tile is non-empty: False,
pass Temp 0 to main: False,
move in a new Sim: False,
copying design mode materials from object in Temp 5: False) T:3 F:E
0x002A : D9D82E8B0600FF010000000001000000 T:3 F:E

3 [prim 0x0033] ManageInventory(AddTokenAndInstanceInfoofStackObject (includecontainedobjects),
Category: 0x0C - visible non-memory,
Inventory (singular): Neighbor: Temp 0x0000) T:4 F:E
0x0033 : 13080000109199730F0C190000190000 T:4 F:E

4 [prim 0x0012] Remove Object Instance (Stack Object,
return immediately: False,
cleanup all: False) T:T F:E
0x0012 : 01000200000000000000000000000000 T:T F:E

Phaenoh
19th Nov 2011, 3:24 AM
I'm using the code from adding the diploma to the inventory at the end and I stuck my code in in the same function that does that, but I don't think it's even being called.

Echo
19th Nov 2011, 12:17 PM
I'm using the code from adding the diploma to the inventory at the end and I stuck my code in in the same function that does that, but I don't think it's even being called.

Which BHAVs are you working on? Function - Next Semester? If so, then it's almost certainly not getting called. The call sequence for that is:
TTAB -> Interaction - At Class -> Function - Grading -> Function - Next Semester. As is, the game will still be calling the original, semi-global versions of the functions.

(Also, I think you're missing some BHAVs. "Function - Next Semester" has a whole bunch of broken 0x1??? range BHAV references in it. Your pie menu resources are also still in the global group, although I'm not sure if that was intentional?)

Phaenoh
19th Nov 2011, 10:15 PM
I reimported the BHAVs that were broken and tried to link everything up properly and rewrote the add to inventory bit like was suggested above and nothing happened when she became a sophomore.

Echo
20th Nov 2011, 6:32 AM
Could you show me one of the supplies objects that you're trying to spawn?

Phaenoh
20th Nov 2011, 9:06 PM
'The Stacks' from FT, 0x73EB1B68. No custom objects, just things from FT or UNI or base. One career reward, the Architecture Drafting Desk, 0xB3FD5372

The code right now is some chair that xiaoyun suggested.

xiaoyun
20th Nov 2011, 10:01 PM
Sorry for no reply earlier :cry:
I lost this thread somewhere and though it was solved allready,
but i see echo came to the rescue <waves> :)

Any findings ?

I think if we would agree to make global hook into this as a entry point (?)
then it would be enought to extract (0x7F17E3A4) 0x0000200C and leave it global.
Then make another copy of it but local one. (so we have two bhav's now)
Then at begining of global one, check major type - if its custom (its related to Uni majors project btw?)
then call our local modified clone which will give gifts related to this custom major ect,
and if its original major then just let it continue on unmodified global bhav.

Phaenoh
21st Nov 2011, 10:05 PM
I'd rather not make this a global mod. It should be able to be self contained. Any idea why my code isn't working?

xiaoyun
22nd Nov 2011, 7:32 AM
I allready knew the answer so it was rather question than solution. ;)

Ok, im just looking into this now and will tell you soon what i have found.

Echo
22nd Nov 2011, 7:46 AM
Alas, I don't have free time, so that doesn't help me a lot. ;) My reason for asking is that you're running a "CT" function on it from the major. Does your spawned object have a "CT - Init" BHAV in it? If not, you probably want to cut that line out.

If that doesn't work, then it's time to verify that the code is actually being run. Stick some "return error"s in there, and make sure you actually get the errors you're expecting.

xiaoyun
22nd Nov 2011, 8:20 AM
You very rite Echo from begining :) The code is not being run.
I was worried about it too, thats where from my previous idea came.

EDIT :
I turn enthusiastic too fast...
This really need alot of breakpoints, and since loading time of simpe + game for each break point
(including not that small amount of code) it would need really a lot of time and effort and i think
it would be better to just find another way.

Maybe it help what i have found until now -
Lets suppose that it really have to use pie menu then OBJD's 0x0007 looks ok,
Life time would be - it "start self" then init, enters main loop which is allready in MajorGlobals and is shared betwin all majors,
(i assume "function - main" should keep which stack it run in (our) so theoreticaly at this point importing everything would
change not much) then its like : main --> sub - process() --> here it looks like still runing in own stack, checking for sim
and push interaction and alternatively calls another Sub - Goto Class(), (only these two trees use push interaction in MajorGlobals)
So not a bad idea would be import these 4 functions to have it localy main() / sub process() / sub - goto class()
and additionally "function - next semester" to have ability to alter it as private.
(Ofcourse there are also other ways to force other objects to do what we want than just push interaction but then theres more and more...)
Anyway what confuse me is line 0x3 in sub - goto class() which is not really clear to me and shows theres something "more".
and this "more" i think really would need breakpoints to find.
Anyway, more i analyze it more feeling i have that this "mayor creation method" is like a container
and is not really accurate as controller.

Theres no impossible things to do (but if effect will be worth the effort is another story)
So, theres 2 ways i would consider if i would want to accomplish what we want here,
1 - change the way how additional majors are build to fit it better to "live object" form, or
2 - make a separate controller which (in addition to this mod) would monitor if sim went to exam,
then after he back, evaluate his performance and give him what we want ect.
(and ofcourse it would destroy self / not run in any other lot than college)
I think the 2nd way would be more pleasant and give true feeling of unbounded creativity and new ideas,
than digging for hours in maxis code to find out which exacly "just one parameter" is wrong >,<

Phaenoh
22nd Nov 2011, 9:48 PM
Ok, I have proof that my code is being run. I changed some text box entries on the local level.

I'm trying a new object, seeing if that helps. Now I'm aiming for that little wooden sim sculpture. Its a basegame object. It doesn't have a CT - Init line in it, nor in its painting semi-globals.

Well that was interesting. I added a couple extra messages and it seems like the object is being created and added just fine, just not to my sim's inventory. I had a text box use $me in it and it popped up with this random townie. I bet he has a little wooden sculpture in his inventory now. ;) How do I make it use my sim instead?

xiaoyun
24th Nov 2011, 2:05 AM
Wow, Grats !

Because $Me refers to "thread" in which current function is running and this not necessarily must be your sim (or even any sim)
You may try to "find" sim by yourself and refer to him with SO instead of $Me

First browse every sim on lot
0x001F Set to Next (Stack Object,person)
then think about something that is unique in your sim, and get only the one which "have this unique something" or look for another sim.

"family member" can be unique to playable sims, (theyre not visitors nor NPC)
0x0002 Expression (SO person data(Person Type) == Const 0x0104:0x00 ("Family Member"))

but there can be more playable (family members) sims on lot then maybe current selected sim
0x0002 Expression (Global (Selected Person ID) == SO person (neighbor id))

just something like this.

Echo
24th Nov 2011, 2:59 AM
I had a text box use $me in it and it popped up with this random townie.
Well that's unexpected! Do you, by any chance, have an error log from this point in the code? I'd be very curious to see how that could happen.

Phaenoh
24th Nov 2011, 8:22 AM
So I'm thinking the problem is in the first line of the code in the 'Purchase Wooden Sim' command lines. -> get current active sim nID to temp(0)

Echo
24th Nov 2011, 8:27 AM
I think you and I are looking at different versions of the Purchase Wooden Sim BHAVs... Because I can't see that line anywhere. :)

Is Delilah your sim?

Phaenoh
24th Nov 2011, 5:13 PM
My mistake, I thought I was running xiaoyun's suggested code from above, but I guess not. Yes, Delilah O'Feef is my testing sim.

Here's my current mess of code.

xiaoyun
24th Nov 2011, 7:40 PM
Actualy since it run in sim thread, it turned to require only one line to work :bunny:
(check attached file)


Btw, while giving item, you attempted to reffer to wooden doll by group ID,
while you must provide GUID from wooden doll's OBJD file.

Phaenoh
25th Nov 2011, 5:08 AM
Rock on! That works! Thank you. I'll go through and do that with the rest of them and hopefully I don't run into any other problems with it.

Later: So everything is running perfectly, with one exception. Something wonky is happening with the first semester skill requirements and I can't seem to track it down. Even if my sim accomplishes all the required skills, the meter doesn't unlock the top tier. I went back and checked my numbers and it seems fine, so I don't really know what's going on. All the other semesters are fine.

xiaoyun
25th Nov 2011, 6:31 PM
I have made completly new clean game (AGS), without any mods, not even downloads folder, then made new student and send him to college, and seems like i still cant raise this above white line even on default maxis major.
This may be not mod fault, rather i dont know how to play it or something wrong with game itself. Try with completly clean game if its the same for you.
Thats really strange.

Phaenoh
26th Nov 2011, 6:33 AM
I didn't have that experience. All my normal Uni majors work normally.

On a second, larger note. Any ideas how I can implement this type of inventory adding based on semester into the original majors? I tried just importing in those BHAVs, but I ran into the problem that all majors seem to share TTABs and everything else. How do I tell each major to use its new related BHAV Interaction - Next Semester?

Phaenoh
2nd Dec 2011, 6:33 AM
I've been thinking about this for some time now and I'm still rather stuck on it. It can't just be as easy as cloning each major, Fixing Integrity to be custom, and then importing the Pie Menu and related BHAVs from it without changing their group numbers? I haven't had the time to be able to test that theory yet, its finals week and i should totally be working on my projects, but I can't seem to get this out of my head. But that couldn't work either, because all the majors share the same pie menu functions and changing it in one would replace it with that for all the others and I want different ones for each. But if I give them custom groups, then they won't be called in the first place. I'm just confused....