SLua: parcelstats

parcelstats.lua
-- get parcel and region stats
 
 
local function log(msg)
    ll.Whisper(PUBLIC_CHANNEL, msg)
end
 
local function test_flag(flags, flag, flag_name) : string
    if bit32.btest(flags, flag) then
        return flag_name .. "=TRUE\n";
--   else
--       return flag_name .. "=FALSE";
    end
    return ""
end
 
--  By Aryn Gellner
--  pos - position (in region coordinates) to check against.
--  * Additional Land Owner Test added by Ruthven Willenov, simplified by Strife
--  http://wiki.secondlife.com/wiki/LlSameGroup
 
local function is_rezzable(pos:vector)
    local parcel_flags = ll.GetParcelFlags(pos)
    if bit32.btest(parcel_flags, PARCEL_FLAG_ALLOW_CREATE_OBJECTS) then
        return true  -- Anyone can rez. No further checks are needed.
    end
 
    -- Ok, not just anyone can rez. Maybe they share an owner or the land allows for group rezzing.
    -- So lets get the parcel owner_id and group_id
 
    local details = ll.GetParcelDetails(pos, {PARCEL_DETAILS_OWNER, PARCEL_DETAILS_GROUP})
 
    if ll.List2Key(details, 0) == ll.GetOwner() then
        return true  -- Owner can always rez.
    end
 
    -- Since what we are going to return is a boolean just return the result of the boolean expression.
    return bit32.btest(parcel_flags, PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS) and ll.SameGroup(llList2Key(details, 1))
end
 
local function show_object_details(id:string)
    local details = ll.GetObjectDetails(
        id,
        ({
            OBJECT_NAME,
            OBJECT_DESC,
            OBJECT_POS,
            OBJECT_ROT,
            OBJECT_VELOCITY,
            OBJECT_OWNER,
            OBJECT_GROUP,
            OBJECT_CREATOR
        })
    )
 
    ll.Whisper(PUBLIC_CHANNEL,
        string.format("UUID: %s", tostring(id))
                    .. "\nName: '"          .. ll.List2String(details, 0)
                    .. "'\nDescription: '"  .. ll.List2String(details, 1)
                    .. "'\nPosition: "      .. ll.List2String(details, 2)
                    .. "\nRotation: "       .. ll.List2String(details, 3)
                    .. "\nVelocity: "       .. ll.List2String(details, 4)
                    .. "\nOwner: "          .. ll.List2String(details, 5)
                    .. "\nGroup: "          .. ll.List2String(details, 6)
                    .. "\nCreator: "        .. ll.List2String(details, 7)
    )
end
 
local function show_parcel_flags(pos:vector)
    local flags = ll.GetParcelFlags(pos)
    local ret = "\n"
        .. test_flag(flags, PARCEL_FLAG_ALLOW_SCRIPTS, "PARCEL_FLAG_ALLOW_SCRIPTS")
        .. test_flag(flags, PARCEL_FLAG_ALLOW_CREATE_OBJECTS, "PARCEL_FLAG_ALLOW_CREATE_OBJECTS")
        .. test_flag(flags, PARCEL_FLAG_USE_ACCESS_GROUP, "PARCEL_FLAG_USE_ACCESS_GROUP")
        .. test_flag(flags, PARCEL_FLAG_ALLOW_GROUP_SCRIPTS, "PARCEL_FLAG_ALLOW_GROUP_SCRIPTS")
        .. test_flag(flags, PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS, "PARCEL_FLAG_ALLOW_CREATE_GROUP_OBJECTS")
        .. test_flag(flags, PARCEL_FLAG_ALLOW_ALL_OBJECT_ENTRY, "PARCEL_FLAG_ALLOW_ALL_OBJECT_ENTRY")
        .. test_flag(flags, PARCEL_FLAG_ALLOW_GROUP_OBJECT_ENTRY, "PARCEL_FLAG_ALLOW_GROUP_OBJECT_ENTRY")
    return ret
end
 
local function show_parcel_details(pos:vector)
    local details = ll.GetParcelDetails(
        pos,
        {
            PARCEL_DETAILS_ID,
            PARCEL_DETAILS_NAME,
            PARCEL_DETAILS_DESC,
            PARCEL_DETAILS_OWNER,
            PARCEL_DETAILS_GROUP
        }
    )
    local ret = "\n"
        .. "UUID: " .. ll.List2String(details, 0) .. "\n"
        .. "Name: " .. ll.List2String(details, 1) .. "\n"
        .. "Desc: " .. ll.List2String(details, 2) .. "\n"
        .. "Owner: " .. ll.List2String(details, 3) .. "\n"
        .. "Group: " .. ll.List2String(details, 4) .. "\n"
    return ret
end
 
local function show_region_flags()
    local flags = ll.GetRegionFlags()
    local ret = "\n"
        .. test_flag(flags, REGION_FLAG_FIXED_SUN, "REGION_FLAG_FIXED_SUN")
        .. test_flag(flags, REGION_FLAG_SANDBOX, "REGION_FLAG_SANDBOX")
        .. test_flag(flags, REGION_FLAG_DISABLE_PHYSICS, "REGION_FLAG_DISABLE_PHYSICS")
        .. test_flag(flags, REGION_FLAG_BLOCK_FLY, "REGION_FLAG_BLOCK_FLY")
        .. test_flag(flags, REGION_FLAG_ALLOW_DIRECT_TELEPORT, "REGION_FLAG_ALLOW_DIRECT_TELEPORT")
    return ret
end
 
local function show_region_env()
    local ret = ""
        .. "Estate: " .. ll.GetEnv("estate_name") .. "\n"
        .. "Region product: " .. ll.GetEnv("region_product_name") .. "\n"
        .. "Start time: " .. ll.GetEnv("region_start_time") .. "\n"
        .. "Sim version: " .. ll.GetEnv("sim_version") .. "\n"
        .. "Sim hostname: " .. ll.GetEnv("simulator_hostname") .. "\n"
    return ret
end
 
function touch_start(total_number)
    log(string.format("\nis_rezzable? %s", tostring(is_rezzable(ll.GetPos()))))
    local id = ll.DetectedKey(0)
    show_object_details(id);
    log(show_region_env());
    log(show_region_flags());
    log(show_parcel_details(ll.GetPos()));
    log(show_parcel_flags(ll.GetPos()));
end
 
local function main()
    log("")
end
 
main()