LUAObject

From SimsWiki
Jump to: navigation, search
This article is imported from the old MTS2 wiki. You can help Sims2Wiki by cleaning it up. It's original page with comments can be found at http://old_wiki.modthesims2.com/LUAObject
LUA files relating to sprites and automata are covered by certain principles. They may contain any of the following.

Specification:


File Block
(Helper Data) -- This data such as a function or an if command are either helpers or control agents for the file. IE a file failing an if command will not execute

dofile("filename.lua")  -- This means that filename.lua must be parsed before this script is executed. This command may be repeated for other files. The dofiles look for hashed IIDs representing the name.


Automata Group - For files containing automata

automata_group.pedestrian = -- Name of the group to create
{
 _parent = (data) -- The parent data to this automata group if any. This causes inheritance of properties.
group_id = "0x8a1e1740", -- Occupant group as defined in the lua's
anims = { -- Animations for this automata to use if any
walk = 0,
wait = "0x0C",
woohoo = "0x07",
whoop = "0x0A",
hop_clap = "0x0B",
clap = "0x09",
booyah = "0x08",
panic_run = "0x0D",
tantrum = "0x06",
reject = "0x04",
phooee = "0x05",
noway = "0x03",
kissmy = "0x02",
booer = "0x01",
},

class_id = "0x896e75af", -- Class ID of the automata. Often or always kept in the savegames while the automata is in use.

models = { -- Additional s3d models to use if any
sprite_model("0x0001000"),
sprite_model("0x0002000"),
sprite_model("0x0003000")
},

} -- End group


Attractor Block - drawing nearby sprites
-- create an attractor that attracts and repels school kids
attractor.schoolkids_attractor = 
{
-- attraction strength from -100 to 100 (negative values repel)
strength = { 80, 0 }, -- this example falls off to 0 at max radius
-- strength = 80, -- this example would be at constant strength 80 throughout the radius
-- strength = { -80, -80, -80, 20 }, -- and this example repels for 3/4 of the radius, then attracts at the outer edge

radius = 50, -- influence radius, in meters
automata = { "child" }, -- automata_groups this attractor affects
calendar = { monday, tuesday, wednesday, thursday, friday },
time_of_day = {
[7] = 0.0, -- start to ramp up at 7 AM...
[8] = 1.0, -- to max attraction strength at 8 AM
[8.5] = 0.3, -- then taper off
[9.0] = 0.0,
[14.9] = 0.0, -- suddenly...
[15.0] = -1.0, -- ...go home at 3PM (negative values repel)
[15.5] = 0.0
},

behavior = { -- behavior is always expressed as a table of tables, since there can be more than 1
{ 
radius = 15, -- when automata are within 10 meters...
state = BehaviorState.DISAPPEAR, -- they should disappear as if going into the building
},
{
radius = 30, -- when automata are within 30 meters...
state = BehaviorState.BEE_LINE, -- they should break from paths and head straight towards the building
},
},
}

Generator Block -- Generating objects

-- create a generator that creates school kids
generator.schoolkids_generator = 
{
automata = { "child" }, -- create children

occupancy_pct = 0.2, -- generate 20% of school's occupancy...
rate = 2, -- ...two times...
rate_scale = RateScale.PER_MINUTE, -- ...per game minute

-- generate at random distances between 10 and 50 meters away.
-- if this generator is linked to a time_of_day clock, then negative values will cause the
-- automata to be generated towards the inside of the range, and positive values will create
-- them towards the outside of the range (so that they will mimic an attached attractor)
radius = { 10, 50 },

-- copy times from schoolkids_attractor
calendar = { monday, tuesday, wednesday, thursday, friday },
time_of_day = {
[7] = 0.0, -- start to ramp up at 7 AM...
[8] = 1.0, -- to max attraction strength at 8 AM
[8.5] = 0.3, -- then taper off
[9.0] = 0.0,
[14.9] = 0.0, -- suddenly...
[15.0] = -1.0, -- ...go home at 3PM (negative values repel)
[15.5] = 0.0
},
}

Occupant Block - Occupant Data
-- Finally, create a "school" occupant group.  Each occupant that belongs to this group will have
-- a "schoolkids_attractor" and "schoolkids_generator" attached to it.

occupant_group.school = 
{
group_id = "0x8a1ddfb4", -- this should be a GUID defined in ingred.ini's "occupant groups" value map

-- alternatively, you could create an occupant group without giving it its own GUID or changing a property in
-- the exemplars.  Since all school buildings have the "school coverage radius" property, you could uncomment the
-- following line.
-- Any time an occupant is created and it has that property, then it will be made a part of the "school" occupant
-- group and have a "schoolkids_attractor" and "schoolkids_generator" attached to it
--
-- property_check = { "0x691b42b3" }, -- "School Coverage Radius"

controllers = {
"schoolkids_attractor",
"schoolkids_generator"
},
}

End Block
-- verify_all_templates() -- When un-commented this tells the script to verify its validity against the templates file. This clogs down the program however
end -- This ending command is included where non-standard data such as functions or if statements are used
Personal tools
Namespaces

Variants
Actions
Navigation
game select
Toolbox