-- Place Instancing -- Author: Jeff the Intern -- Creation Date: 08/15/08 -- NOTE: Script adds behavior to place to make instance -- Constants -- Properties Define Properties() max_players = 25 ExposeProperty('max_players', 'The maximum number of players in the place.') PersistProperty('max_players') script_description = 'Place Instancing' script_long_description = 'Add this behavior to your world to allow place instancing. Only works with the world object' script_icon = '12071:442' end Trigger attach() end Trigger detach() end -- Triggers Trigger goto_instance(player,place_id) -- Does an instance of this place already exist for this world local myInstance = find_open_instance_by_id(self,place_id) Debug('Send %s to %s', player.name, place_id) if myInstance == 0 then -- If it is full then create a new instance myInstance = InstancePlace(place_id) end UserGotoPlace(player, myInstance) end Trigger left_instance(player) if player.place then if player.place.instanceId == 0 then return end -- If we are the last one here then turn out the lights. if player.place.numUsers == 1 then DeletePlaceInstance(player.place) end end end -- Functions function find_open_instance_by_id(self, place_id) for i, place in pairs(self.places) do local place_str = string.gsub(place.placeId, '(.+):', '') if place_str == tostring(place_id) then if place_is_full(self, place) == 0 and place.instanceId ~= 0 then return place end end end return 0 end function place_is_empty(place) if place.numUsers == 0 then return 1 else return 0 end end function place_is_full(self, place) if place.numUsers >= self.max_players then return 1 else return 0 end end