-- Light System -- Author: Jeff the Intern -- Revisions -- New Script 06/18/08 - J.McNab -- Custom UI 07/03/08 - J.McNab --CONSTANTS DEFAULT_LIGHT_SPRITE = 1 DEFAULT_LIGHT_COLOR_RED = 255 DEFAULT_LIGHT_COLOR_GREEN = 255 DEFAULT_LIGHT_COLOR_BLUE = 255 DEFAULT_LIGHT_COLOR_ALPHA = 1 DEFAULT_LIGHT_SCALE_X = 1.0 DEFAULT_LIGHT_SCALE_Y = 1.0 DEFAULT_LIGHT_OFFSET_X = 1.0 DEFAULT_LIGHT_OFFSET_Y = 1.0 DEFAULT_LIGHT_ROTATE_WITH_OBJECT = 0 SELF_SCRIPT = '12071:12' -- Properties Define Properties() --All light IDs --NOTE: each light_id index points to a specific attribute in light properties(light_color_red, light_color_blue, etc) light_id = 0 PersistProperty('light_id') --Table of various sprite Ids that can be used as lights. light_sprite_id = '12071:404' ExposeProperty('light_sprite_id', 'Sprite for the light', 'spriteId') PersistProperty('light_sprite_id') -- Light color attributes light_color = {red = 255, green = 255, blue = 255, alpha = 1} ExposeProperty('light_color', 'What color is the light?', 'color') PersistProperty('light_color') -- Light Scale light_scale_x = '1.0' ExposeProperty('light_scale_x', 'X-scale of Light') PersistProperty('light_scale_x') light_scale_y = '1.0' ExposeProperty('light_scale_y', 'Y-scale of Light') PersistProperty('light_scale_y') -- Light Offset light_offset_x = '0.0' ExposeProperty('light_offset_x', 'X-offset of Light') PersistProperty('light_offset_x') light_offset_y = '0.1' ExposeProperty('light_offset_y', 'Y-offset of Light') PersistProperty('light_offset_x') -- Light rotation light_rotate_with_object = 0 ExposeProperty('light_rotate_with_object', 'Rotate the light with the object?', 'checkbox') PersistProperty('light_rotate_with_object') --Is the light off light_on = 0 ExposeProperty('light_on', 'Is the light on?', 'checkbox') PersistProperty('light_on') --Can the light be turned on and off light_useable= 1 ExposeProperty('light_useable', 'Can the light be turned on and off?', 'checkbox') PersistProperty('light_useable') user = "_object_" script_description = 'Light Source' script_long_description = 'This object will emit a light' -- script_icon ='12071:436' end --Attach script Trigger attach() --Attach a default light to the template using the sprite_id light_system_add_light(self) end Trigger detach() light_system_remove_light(self) end Trigger destroyed() light_system_remove_light(self) end Trigger enter() DetachLight(self, self.light_id) if(self.light_id ~= 0) then light_system_add_light(self) end end Trigger left(placeId) DetachLight(self, self.light_id) end -- Turn off a light Trigger light_system_turn_off() self.light_on = 0 light_system_update_light(self) end -- Turn on a light Trigger light_system_turn_on() self.light_on = 1 light_system_update_light(self) end -- Toggle the light state on/off Trigger use() if(self.light_useable == 1) then if(self.light_on > 0) then SendTo(self, 'light_system_turn_off', 0, object) else SendTo(self, 'light_system_turn_on', 0, object) end end end Trigger set_script_param(script_id, name, value) SendTo(self, 'light_system_update', 100) end Trigger light_system_update() light_system_update_light(self) end -- Add a light to the object function light_system_add_light(object) local light_alpha = 0 if(object.light_on == 1) then light_alpha = object.light_color.alpha end local origin_x = {0, 0, stylesheet.sprites[object.spriteId].scaleX * 64/2} local origin_y = {0, -stylesheet.sprites[object.spriteId].scaleY * 64/2, stylesheet.sprites[object.spriteId].scaleY * 64/2} offset_x = origin_x[object.spriteOrigin]/64 offset_y = origin_y[object.spriteOrigin]/64 object.light_id = AttachLight(object, object.light_sprite_id, object.light_color.red, object.light_color.green, object.light_color.blue, light_alpha, object.light_scale_x, object.light_scale_y, object.light_offset_x + offset_x, object.light_offset_y + offset_y, object.light_rotate_with_object) end function light_system_remove_light(object) DetachLight(object, object.light_id) end function light_system_update_light(object) light_system_remove_light(object) light_system_add_light(object) end function add_floats(float_one, float_two) local sum = tonumber(float_one) + tonumber(float_two) return tostring(sum) end