View Full Version : What is the idiom for an object to run a BHAV when a Sim enters the room?
11th Mar 2008, 09:54 AM
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?
11th Mar 2008, 12:01 PM
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.
12th Mar 2008, 08:25 AM
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...
12th Mar 2008, 08:51 AM
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.
J. M. Pescado
13th Mar 2008, 04:57 AM
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?
13th Mar 2008, 08:40 AM
I do not believe there is any method for doing this other than bruteforcing.
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...)
13th Mar 2008, 10:30 AM
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. :)
J. M. Pescado
13th Mar 2008, 12:04 PM
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.
(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.
13th Mar 2008, 02:06 PM
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!
13th Mar 2008, 10:29 PM
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.)
vBulletin v3.0.14, Copyright ©2000-2013, Jelsoft Enterprises Ltd.