Welcome to
Mod The Sims
Online: 2684
News:
Have an account? Sign in:
pass:
If you don't have an account, why not sign up now? It's free!
Other sites: SimsWiki
Reply  Replies: 9 (Who?), Viewed: 2172 times.
Search this Thread
Old 11th Mar 2008, 09:54 AM DefaultWhat is the idiom for an object to run a BHAV when a Sim enters the room? #1
szielins
Original Poster

Lab Assistant

Join Date: May 2006
Posts: 88
Thanks: 3314 in 55 Posts
14 Achievements

View My Journal


Say I have a rug or something; I want it to react when a Sim enters the room. That is, the Sim enters the room, and a BHAV in the rug gets run.

For the life of me, I can't figure out what the idiom for this is. The closest I've gotten is to set the action in the rug's Object Functions for "awareness"-- but that won't have time to react if the room is small and the Sim runs through. I can see that portals (in Function - Portal - SG) invoke the global "Trigger - Sim Enters Room" (0x021D), which itself invokes the Message primitive (0x0077). That implies there's some way to set up the rug to receive messages broadcast to all objects in the room-- via some sort of registered message handler, I presume-- but I can't find an example of anything that seems to do that. (There's a global-- "CT - Message Handler"-- it's a do-nothing, which gave me hope it was there to catch all messages not handled by specifying a "CT - Message Handler" earlier in scope-- but just creating a private BHAV with that name in the rug didn't seem to do anything. At least it never got called-- so I figure there may have to be an actual registration somewhere...)

What should I be reading to become Enlightened?
Last edited by szielins : 11th Mar 2008 at 11:18 AM.
Old 11th Mar 2008, 12:01 PM #2
Inge Jones
Mad Poster

Join Date: Sep 2004
Posts: 6,857
Thanks: 7427 in 17 Posts
18 Achievements


You could use the door's portal function to look for a rug in the destination room, set an attribute on that rug and then notify the rug out of idle. The rug then tests the attribute and if it is set to the right value, runs its little routine.

simlogical
Please do not PM me with questions about modding. Please post in an appropriate forum and send me a link to the thread if you would like me to try and help.
Old 12th Mar 2008, 08:25 AM #3
szielins
Original Poster

Lab Assistant

Join Date: May 2006
Posts: 88
Thanks: 3314 in 55 Posts
14 Achievements

View My Journal


That could, indeed, solve the immediate problem-- but since it'd entail either building a/an custom portal(s) to contact the rug directly or changing a fairly critical semiglobal (which I'm loath to do-- it's incompatibility-bait), that mitigates against doing it for cheapie little throwaways. (Say, a stern portrait that winces momentarily whenever an additional Sim enters the room, and changes to a broad smile only when totally alone. Doesn't give the player more than a slight chuckle, might be worth having if it's a cool portrait otherwise-- but I wouldn't want to dirty a core function with the changes necessary to get it done.) I'm hoping this is a solved-long-ago problem and I'm just ignorant. (Uh, let me rephrase that. I'm hoping it's a solved-long-ago problem in addition to my being ignorant...)

I mean, does anyone do anything with 0x0077 Message and message handlers at all, or...? I've never seen it in a BHAV, but I haven't looked at very many of them...
Old 12th Mar 2008, 08:51 AM #4
Inge Jones
Mad Poster

Join Date: Sep 2004
Posts: 6,857
Thanks: 7427 in 17 Posts
18 Achievements


Well if the Sim is definitely going to have to walk over the rug, you could try doing something with its allow intersect function (I think there might be a walkover function too but my memory is hazy) Anyway look in the OBJf and see if there is anything you could try using.

simlogical
Please do not PM me with questions about modding. Please post in an appropriate forum and send me a link to the thread if you would like me to try and help.
Old 13th Mar 2008, 04:57 AM #5
J. M. Pescado
Fat Obstreperous Jerk

Join Date: Oct 2004
Posts: 3,153
Thanks: 8591 in 38 Posts
14 Achievements


I do not believe there is any method for doing this other than bruteforcing. If you want the rug to test for overrun, you could just rig the rug, so every tick or two, the rug performs a "set to next object on tile" for every tile of itself, to see if anyone is on it, and then performing an action if a sim is detected as one of these objects. You'd then want to store that sim's ID somewhere, probably an array, so that the same sim will not trigger the object again until he leaves (and then, as part of the process, clean the array of sims that did NOT appear, because they moved away).

Lots of fun, but this is the approach I'm currently using for my in-testing "GO AWAY" mat.

Woah. I have another funny symbol by my name. When did THAT happen?

Grant me the serenity to accept the things I cannot change, the courage to change the things I cannot accept, and the wisdom to hide the bodies of those I had to kill because they pissed me off.
Old 13th Mar 2008, 08:40 AM #6
szielins
Original Poster

Lab Assistant

Join Date: May 2006
Posts: 88
Thanks: 3314 in 55 Posts
14 Achievements

View My Journal


Quote:
Originally Posted by J. M. Pescado
I do not believe there is any method for doing this other than bruteforcing.


Drat.

That you're taking a poll-rug-tiles-every-tick approach suggests to me that perhaps I'm also not alone in not being able to get "Walk Over" in OBJf to do anything? (When I tried, the routine simply never got run under any circumstances. Even after I faint-hoped making the rug multi-tile friendly and tossing the Maya footprint...)
Old 13th Mar 2008, 10:30 AM #7
Echo
Duck



Join Date: Dec 2004
Posts: 3,918
Thanks: 48072 in 48 Posts
26 Achievements

View My Journal


Hey

Well I can't help you much with a "walk over" check. The "walk over" is actually, I believe, linked to the "can be stepped over" and only works for very small objects that are specifically step-overable. (I have a feeling that's how the death by flies is set up btw!) BUT I can probably point you in the right direction as far as running something when a sim enters a room. Whenever a sim enters a room the door triggers a message to all the objects in the room. The message is of type Const 0x012B:0x02 (0x03EB). (Yep, you were well on the right track with your first thoughts!)

I've never actually done this myself so my explaination may not be foolproof, but I've seen it in a few objects so it should be accurate enough to get you started. You can set your object to receive messages by giving it a function in the "Message Handler" line of the objf. That function can take up to 5 parameters, but for your purpose you probably only really care about the first two which are, respectively, message id and the stack object at the time the message was sent. You'll need to check if the message ID is the one I said above. If it's not, just exit straight away - this is not a message that is of any importance to you. If it is, then you need to run your code. I'm not certain whether param 0x01 (the caller's stack object) is going to be the door or the sim, so you might need to check that. Either way, that much should be enough to get your object to react to a sim entering if nothing else.
Old 13th Mar 2008, 12:04 PM #8
J. M. Pescado
Fat Obstreperous Jerk

Join Date: Oct 2004
Posts: 3,153
Thanks: 8591 in 38 Posts
14 Achievements


Quote:
Originally Posted by Echo
Well I can't help you much with a "walk over" check. The "walk over" is actually, I believe, linked to the "can be stepped over" and only works for very small objects that are specifically step-overable.
And it's very unreliable. I've seen things like, say, trash piles, where sims intermittently and randomly decide to just clip through it instead of stepping over it, and they do this more often than not, meaning this is a very unreliable mechanism.

Quote:
Originally Posted by Echo
(I have a feeling that's how the death by flies is set up btw!) BUT I can probably point you in the right direction as far as running something when a sim enters a room. Whenever a sim enters a room the door triggers a message to all the objects in the room. The message is of type Const 0x012B:0x02 (0x03EB). (Yep, you were well on the right track with your first thoughts!)
Useful information to know. I wouldn't rely on this as a means of detecting room entry, because it would only fire on a door transition, which not all room entries consist of: It would miss stair transitions, teleportations, or walking over a floor divider.

Grant me the serenity to accept the things I cannot change, the courage to change the things I cannot accept, and the wisdom to hide the bodies of those I had to kill because they pissed me off.
Old 13th Mar 2008, 02:06 PM #9
szielins
Original Poster

Lab Assistant

Join Date: May 2006
Posts: 88
Thanks: 3314 in 55 Posts
14 Achievements

View My Journal


Testing seems to indicate no messages flying around as the result of entering through an arch, either-- which strikes me as odd, since it was via eyeballing an arch that I first found the Trigger thing-- but hey. At least this can handle the specific case that was annoying me-- getting something to happen even if the Sim runs through a small room quickly. As long as one remembers to document that one's widget such-and-thus only reliably detects Sims walking or running into the room via a door of conventional design, it'll have uses.

Although something seems unexpectedly off about its ability to cache data and recall it correctly-- for no reason I can fathom-- the attached object at least demonstrates the OBJf Action "Message Handler" initiating code after a doors' use of the 0x077 Message primitive. It prints out its parameters for all messages it receives.

Thanks to all for looking into this question!
Download - please read all instructions before downloading any files!
File Type: zip szielins_DEMO_messageHandler_Mat_MiscMisc.package.zip (24.8 KB, 3 downloads) - View custom content
Last edited by szielins : 13th Mar 2008 at 02:43 PM.
Old 13th Mar 2008, 10:29 PM #10
szielins
Original Poster

Lab Assistant

Join Date: May 2006
Posts: 88
Thanks: 3314 in 55 Posts
14 Achievements

View My Journal


Subtlety: the data available to the message hander includes what door the Sim is entering through-- but at the instant the Const 0x012B:0x02 message is delivered, the Sim is not actually in the room with the message-receiving object. The Sim is still in transit-- and check that Sim's "room" field, and it'll contain the room the Sim is leaving. (The message handler is running in the transiting Sim's stack, so "My" is set to the Sim about to enter the room with the object receiving the message.)
Last edited by szielins : 13th Mar 2008 at 10:49 PM.
Reply


Section jump:


Powered by MariaDB Some icons by http://dryicons.com.