--------------------------------------------------------------------------
- Lua notes (update):

Opcode: 0x7E
Operands: STR# (2 bytes), index + 1 (2 bytes), flags (2 bytes)

+ 0: STR# is usually 0x130
+ 2: index = file name of chunk to call (without the extension)
+ 4: flags - +1 = extern script, +2 = private, +4 = semi-global, +8 = pass in params
+ 6: param 0 owner
+ 7: param 0 value
+ 9: param 1 owner
+10: param 1 value
+12: param 2 owner
+13: param 2 value

Note: Flag +1 clear means you define the script in the description of the
indicated string.

Here are some examples pulled from objects.package:

- kMsgImposterUpdateNeeded:

nMessaging.PostMessage(221)

- Cleanup Lot:

nBusinessLotsController.cleanupLot(GetPrimitiveParameter(0))

- Cleanup Neighborhood:

nBusinessLotsController.cleanupNeighborhood(GetPrimitiveParameter(0))

- OpenBirth:

local numPKs = GetPrimitiveParameter(0)
nUI.OpenProgressDialog(4276996822)
nUI.ShowProgressDialogControl(1, false)
nUI.ShowProgressDialogControl(2, false)
nUI.ShowProgressDialogControl(3, false)
nUI.ShowProgressDialogControl(4, false)
nUI.ShowProgressDialogControl(numPKs, true)

- CloseBirth:

nUI.CloseProgressDialog()

- GetBestCraftableObjectForJob:

SetTemp(0, nEmployeeManagement.getBestCraftableObjectForJob(GetPrimitiveParameter(0), GetPrimitiveParameter(1)))

- CountUniversities:

local nm = NeighborhoodManager.new(); local cn = nm:getNumNeighborhoodsOfType("university"); SetTemp(0,cn)

- CountDowntowns:

local nm = NeighborhoodManager.new(); local cn = nm:getNumNeighborhoodsOfType("downtown"); SetTemp(0,cn)

- FuriousAgeLerp:

SetLocal(5, GetLocal(4)*GetLocal(1) / GetLocal(2))

- FuriousCalcRelMod:

local relStrength = GetTreeParameter(0) * GetTreeParameter(1) / 100
if relStrength < GetTreeParameter(2) then
   SetTemp(0, GetTreeParameter(2) )
else
   SetTemp(0, relStrength)
end

- FuriousPersonalityBonus:

local niceness = GetLocal(1)
local bonus
if niceness > 500 then
	bonus = ((niceness - 500) * GetConstant(328, 1)) / -500
else
	bonus = ((500 - niceness) * GetConstant(328, 0)) / 500
end
bonus = bonus + 100
SetTreeParameter(2, GetTreeParameter(2) * bonus / 100)
SetTreeParameter(3, GetTreeParameter(3) * bonus / 100)

- Array into Locals:

local arrayNum = GetLocal(0)
local groupNIDS  = GetObjectArrayCopy( GetStackObjectId(), arrayNum)
for i,v in ipairs(groupNIDS) do
	SetLocal(i-1,v)
end

- DoesSimHaveAGroup:

local Sim = CachedPerson.new(GetTreeParam(0))
local myGUID = Sim:getGuid()

local inventory = Inventory.new(0) -- Get global inventory
local tokenCount = inventory:countTokens()

local tokens = inventory:getTokensByGUID(-279938591)

DebugPrint( tostring(getn(tokens)) .. " Tokens Found")
local found = 0

SetScriptReturnValue(false)
for k,token in pairs(tokens) do
	local propCount = token:countProperties()
	DebugPrint("Token " .. tostring(k) .. " has " .. tostring(propCount) .. " properties")
	for property = 3,propCount,2 do
		local thisGUID = token:getPropery(property + 1) * 65534
		if (thisGUID > 0) then
			thisGUID = thisGUID +  token:getPropery(property) 
		else
			thisGUID = thisGUID - token:getPropery(property) 
		end
		if (thisGUID == myGUID) then
			SetScriptReturnValue(true)
			found = 1
			break
		end
	end
	if (found == 1) then break end
end

- Calculate Ratio:

SetTemp(0,math.round((GetPrimitiveParameter(1) / GetPrimitiveParameter(2)) * GetPrimitiveParameter(0)))

- mystery function (?):

--This will check to see if the GUID passed in is a badge or not.
local guid = CreateObjectGUID(GetPrimitiveParameter(0), GetPrimitiveParameter(1))
if (GetObjectDefinitionField(guid, ObjDef["Selector Category"]) == 121) then 
   SetScriptReturnValue(true)
else
   SetScriptReturnValue(false)
end

- Shop Rank:

local lotId = GetPrimitiveParameter(0)
local bizInfo  = BusinessInfo.new(lotId)
DebugPrint(bizInfo:getRank())
SetTemp(0, bizInfo:getRank())

