| Search this Thread |
|
|
|
|
MogHughson
Original Poster
Miss BHAVing
|
This tutorial assumes that you are comfortable using SimPE for BHAV programming. Screenshots are taken from SimPE v0.72.1.33855 The Problem Creation of a new object, using the Create New Object Instance primitive [0x002A] allows you to create a specific object, by GUID. However, you must know the GUID ahead of time. What if you want to create a new object of a particular type, for example, any chair, any bed, any car, but just want a random one from those in the catalog, rather than providing a specific GUID. What then? The Set to Next primitive [0x001F] seems like a good way for finding random things - you can cycle through all sorts of things with this primitive, Pets, jobs, Sims, objects of a particular type, BUT for almost all of the Set to Next operations, the objects being cycled through are already instantiated on the lot (if you look in a .log file you will see them in the Lot Dump). The solution There is one Set to Next operation that can find things that are not instantiated and that is what this tutorial is about. We will be looking at how to use the slightly oddly named Set to Next (influence) operation. ![]() As with all uses of the Set to Next primitive, first ensure that the variable that is going to hold the next thing is zeroed out first (otherwise you won't be starting at the beginning). Also make sure you do this outside any loop you might place your Set to Next instruction in, or you will suffer from the "Too many iterations" error. In my case this is a local variable (Local[1]) which I have labelled "Selected Item". ![]() Now, this Set to Next (influence) operation expects Temp[0] to be set to the selection criteria (What's it selecting on?). In this case we want to find all things set to the constant defined in Global BCON 0x0106 for the vehicle category (value 0x0003), so we set this value in Temp[0]. ![]() You can also select on a sub-set of the items Selector Category by setting Temp[1] to a value. If you want all items in the Selector Category, set Temp[1] to -1. ![]() Having set up the expected inputs, we can now call the Set to Next primitive. As is normal for the Set to Next primitive, it will return True if it found something and False if it did not. This is how you know you've come to the end of the set of items when you call Set to Next in a loop. ![]() Upon its return, Set to Next (influence) places the GUID of the item found in Temp[2] and Temp[3]. If you want to select a random item, you will need to put this into a loop and go round for a random number of iterations. I am assuming that if you are reading this tutorial, you have already enough BHAV programming knowledge to do this, if not, there are other tutorials that will teach you about this. What is it selecting on? This Set to Next (influence) operation is selecting upon the OBJD's 0x004B 'Selector Category' field. Although you could put any number in here, and set the matching number in Temp[0] before calling Set to Next (influence), in order to avoid clashes with other mods, or indeed with any future Maxis changes, where possible, the values from global BCONs which determine the category value should be used, namely:
![]() Maxis in-game uses This isn't actually used very much in the game by Maxis. You will find that many objects do not even have their Selector Category set, so part of using this with Maxis objects will have to include fixing that as part of any object that needs them. Those that we know of incude:
Attached is a package which is a modification of the Accessory Spawner (has it's own unique GUID and can be found in Hobbies - Knowledge) which produces a pie-menu of all objects in the catalog which have their Selector Category filled in. Clicking on the pie-menu that is produced will attempt to spawn an instance of the item, which may not always work. The objects main intention was simply to enumerate all the items which were already catgorized with a Selector Category. It's probably also useful for spotting any miscategorized items. The object itself is Base Game compatible however, the instruction in question is not, so all you can do with this in the Base Game is illustrate exactly the error you will receive attempting to use this instruction in the Base Game. If you use this object without Pets or a newer than Pets EP, you will be provided with the GUIDs of the objects in each selection criteria - not as useful for working out what they are but at least illustrating that the instruction can be used. If you use the object with Pets or higher, you will get a nice description of the object. Credits I can claim no credit myself for discovering this behaviour. All the credit goes to tunaisafish, Dizzy and Numenor for setting me on the right tracks when I needed to do exactly this. My thanks to them, and I hope I have captured all their notes in this tutorial for future reference. If there is anything that should be said about this instruction, let me know and I'll add it here. |
|
|
Last edited by MogHughson : 14th Mar 2009 at 12:47 AM.
Reason: Added Base Game Compatible Object
|
|
8 users say thanks for this.
[ Click here to view a longer list ] |
|
|
|
#2 |
|
Numenor
The ModFather
|
Excellent work! Thank you for collecting all the info in a nicely illustrated tutorial.Few notes about the game compatibility (of this tutorial and the attached Accessory Spawner object).
|
|
I've finally started my Journal. Information only, no questions. My latest activity: CEP 9.2.0! - AnyGameStarter 2.1.1 (UPD) - Scriptorium v.2.2f - Photo & Plaques hide with walls - Magazine Rack (UPD) - Animated Windows Hack (UPD) - Custom Instrument Hack (UPD) - Drivable Cars Without Nightlife (UPD) - Courtesy Lights (FIX) - Custom Fence-Arches - Painting-TV - Smarter Lights (UPD) I *DON'T* accept requests, sorry.
|
|
|
|
|
|
|
#3 |
|
GeneralOperationsDirector
|
I`m going to try that hacked Accessory Spawner in my testing neighborhood. It sounds interesting! |
|
This Space Intentionally Left Blank
|
|
|
|
|
|
|
#4 |
|
MogHughson
Original Poster
Miss BHAVing
|
Example object updated (as per Numenor's hints) to be usable in any version of the game, although of course it has slightly different behaviour depending on what EPs you have. See notes in main thread. |
|
|
|
![]() |










Thank you for collecting all the info in a nicely illustrated tutorial.
Twitter
del.icio.us
StumbleUpon
Google