Tenoukii 0 Report post Posted April 14, 2011 Hey (: My first full script request for this project, and it's a light script :D Basically, I need a script that creates a circle of light around an event with options such as Flicker, Shadow, Brightness, Radius size ect... I think I've heard of one, but I can't remember :sweatdrop: I have googled, and the only one I could find wasn't very good (sorry to whoever made it!) So if someone could find/make a really good super simple one for me, that would be great :D Thank-cho Share this post Link to post Share on other sites
brewmeister 3 Report post Posted April 15, 2011 If you don't mind waiting a little while, a few of us are 'gang-banging' a day-night-light script here... http://www.hbgames.org/forums/viewtopic.php?f=155&t=74395 It doesn't have 'flickering' or 'shadows' in the requirements as of now, but suggestions & ideas are welcome. We're using 'subtraction' images to make 'light' holes in the night darkness, so you can affect the brightness that way. Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 If you don't mind waiting a little while, a few of us are 'gang-banging' a day-night-light script here... http://www.hbgames.org/forums/viewtopic.php?f=155&t=74395 It doesn't have 'flickering' or 'shadows' in the requirements as of now, but suggestions & ideas are welcome. We're using 'subtraction' images to make 'light' holes in the night darkness, so you can affect the brightness that way. LOL @ gang-banging haha But, is this script you guys are working on only with overlays and by mucking around with them? I guess with RMXP there may not be too much better of a way to create lights or dynamic lighting. Although, I haven't looked into the other dynamic lighting scripts so maybe there is. Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 (edited) Alright, I'll take this one on! So far I have brightness and radius as variables within the script. I'll change this to being in a comment in just a second. For now (since I'm at work :D), here is what I have. Play around with it if you'd like - feel free to make any changes. And if you would like me to continue and add flicker/shadows, let me know! Also, please note that I tend to use too many comments with my code. I do this for both my benefit and anyone who is a beginner and would like to learn a thing or two. #=============================================================================== # Lighting Script # By Descendant of Orr # Version 0.1 #------------------------------------------------------------------------------- # Begin Light class #------------------------------------------------------------------------------- class Light attr_accessor :light attr_accessor :event def initialize(event) @light = Sprite.new @light.bitmap = RPG::Cache.picture("light.png") @light.visible = true @light.z = 1000 @event = event end end #------------------------------------------------------------------------------- # End Light class #------------------------------------------------------------------------------- # Begin Spriteset_Map class #------------------------------------------------------------------------------- class Spriteset_Map #------------------------------------------------------------------------------- # Alias calls # Redefined methods: Spriteset_Map.initialize # Spriteset_Map.dispose # Spriteset_Map.update #------------------------------------------------------------------------------- alias light_initalize initialize alias light_dispose dispose alias light_update update #------------------------------------------------------------------------------- # Lighting variables # Will be changed to comment variables #------------------------------------------------------------------------------- SIZE = 3 BRIGHTNESS = 3 # 1-10; 1 being the brightest EXPAND_RATE = 5 # in percent of original size EXPAND_ITERATION = 5 # number of times to expand #------------------------------------------------------------------------------- # Spriteset_Map.initialize # Creates an array to house the Light class # Calls the setup_lights method to find all Light sources on the map # Calls Spriteset_Map's original initialize method #------------------------------------------------------------------------------- def initialize @light_effects = [] @current_size = SIZE * 100 @total_expand = 0 @expanding = true setup_lights light_initalize end #------------------------------------------------------------------------------- # Spriteset_Map.dispose # Calls Spriteset_Map's original dispose method # Loops through all lights in @light_effects and disposes each # Reinitializes @light_effects #------------------------------------------------------------------------------- def dispose light_dispose for effect in @light_effects effect.light.dispose end @light_effects = [] end #------------------------------------------------------------------------------- # Spriteset_Map.update # Calls Spriteset_Map's original update method # Draws each Light if in_range? #------------------------------------------------------------------------------- def update light_update if @expanding @total_expand += EXPAND_RATE @current_size = SIZE * 100 + @total_expand @expanding = !@expanding if @total_expand == EXPAND_RATE * EXPAND_ITERATION else @total_expand -= EXPAND_RATE @current_size = SIZE * 100 + @total_expand @expanding = !@expanding if @total_expand == -2 * EXPAND_RATE end for effect in @light_effects next if not in_range?(effect.event) effect.light.x = (effect.event.real_x - @current_size - $game_map.display_x) / 4 effect.light.y = (effect.event.real_y - @current_size - $game_map.display_y)/ 4 effect.light.zoom_x = (@current_size) / 100.0 effect.light.zoom_y = (@current_size) / 100.0 end end #------------------------------------------------------------------------------- # Spriteset_Map.setup_lights # For each event, if the first command is a comment, and the comment is # "Light," a new Light class is created and set to its correct position # NOTE: Need to pull SIZE, BRIGHTNESS, FLICKER, & SHADOW from comments as well #------------------------------------------------------------------------------- def setup_lights for event in $game_map.events.values next if event.list == nil for i in 0...event.list.size if event.list[i].code == 108 and event.list[i].parameters == ["Light"] light_effects = Light.new(event) light_effects.light.zoom_x = (SIZE * 100) / 100.0 light_effects.light.zoom_y = (SIZE * 100) / 100.0 light_effects.light.opacity = 255 / BRIGHTNESS @light_effects.push(light_effects) end end end for effect in @light_effects effect.light.x = (effect.event.real_x - (SIZE * 100) - $game_map.display_x) / 4 effect.light.y = (effect.event.real_y - (SIZE * 100) - $game_map.display_y) / 4 end end #------------------------------------------------------------------------------- # Spriteset_Map.in_range? # Assuming a 4:3 resolution, finds Light events that are in range # NOTE: I should probably fine tune these numbers #------------------------------------------------------------------------------- def in_range?(object) screen_x = $game_map.display_x - 256 screen_y = $game_map.display_y - 256 screen_width = $game_map.display_x + (256 * 12) screen_height = $game_map.display_y + (256 * 9) return false if object.real_x <= screen_x return false if object.real_y <= screen_y return false if object.real_x >= screen_width return false if object.real_y >= screen_height return true end end #------------------------------------------------------------------------------- # End Spriteset_Map class #------------------------------------------------------------------------------- EDIT: Attached Light file...silly me :D Edited April 15, 2011 by Descendant of Orr Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 (edited) Hey (: Firstly, the amount of comments is good. They're handy and make it easy to understand ^_^ Secondly, it says theres an error on line 71 (undefined method) and Lastly, Thank you :D EDIT: If anyone knows of a script that changes the maps colour tone (gradually) based on the clock on your computer? (Day & Night script I believe) I think I had one before, but can't remember exactly. (atrocious memory :sweatdrop: ) Thanks :D Edited April 15, 2011 by Tenoukii Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 Very nice! I just tried it out and its very effective! I know you are at work right now (tsk tsk not working :P haha jk) Although you will need to upload the "Light.png" file, and with the RPG::Cache module you do not need to include file extensions..however it really doesn't make a difference. And if I may make a suggestion, I think you should add flickering and a "glow" effect (with either built in methods within the RPG::Sprite class or by causing the light picture to slowly expand/contract IMO it would look much nicer) and then, I believe you should submit this script for everyone because I think a nice simple lighting system such as this one could be very useful to anyone :) I hope you don't mind me dissecting your code, just some suggestions. Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 Line 71 doesn't have any methods in it...Can you attempt to run the game again, and then when it fails open up the script editor - then tell me what line it stopped on and of what script. with the RPG::Cache module you do not need to include file extensions..however it really doesn't make a difference. And if I may make a suggestion, I think you should add flickering and a "glow" effect (with either built in methods within the RPG::Sprite class or by causing the light picture to slowly expand/contract IMO it would look much nicer) and then, I believe you should submit this script for everyone because I think a nice simple lighting system such as this one could be very useful to anyone :) I hope you don't mind me dissecting your code, just some suggestions. See, I learn something I didn't know. I have always included file extensions in my scripts. I will attempt an expanding/contracting effect and see how it looks. And I don't mind you dissecting my code at all! Feel free to do so whenever! Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 This is what I get :S Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 Cool, I am glad I could teach ya something :) Doesn't make a difference, but it saves guessing what filetype without having to check i guess :P And it's strange you get that error. I copied the script right over, and it worked fine (i made my own Light.png file) and that's the only issue I can think of, but that should give a "File Not Found" error of some kind rather than method not found... Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 (edited) It makes it seem like @light_effects isn't defined in your instance of the script, which is strange. Try this new version. It flickers automatically (contracts/expands). I need to work on the speed/amount, and add it to commenting as well. I need to re-comment some other parts, and the coding is sloppy, but I'm still at work...I should probably get some work done ;D #=============================================================================== # Lighting Script # By Descendant of Orr # Version 0.1 #------------------------------------------------------------------------------- # Begin Light class #------------------------------------------------------------------------------- class Light attr_accessor :light attr_accessor :event def initialize(event) @light = Sprite.new @light.bitmap = RPG::Cache.picture("light.png") @light.visible = true @light.z = 1000 @event = event end end #------------------------------------------------------------------------------- # End Light class #------------------------------------------------------------------------------- # Begin Spriteset_Map class #------------------------------------------------------------------------------- class Spriteset_Map #------------------------------------------------------------------------------- # Alias calls # Redefined methods: Spriteset_Map.initialize # Spriteset_Map.dispose # Spriteset_Map.update #------------------------------------------------------------------------------- alias light_initalize initialize alias light_dispose dispose alias light_update update #------------------------------------------------------------------------------- # Lighting variables # Will be changed to comment variables #------------------------------------------------------------------------------- SIZE = 3 BRIGHTNESS = 3 # 1-10; 1 being the brightest EXPAND_RATE = 3 # in percent of original size EXPAND_ITERATION = 8 # number of times to expand #------------------------------------------------------------------------------- # Spriteset_Map.initialize # Creates an array to house the Light class # Calls the setup_lights method to find all Light sources on the map # Calls Spriteset_Map's original initialize method #------------------------------------------------------------------------------- def initialize @light_effects = [] @current_size = SIZE * 100 @total_expand = 0 @expanding = true setup_lights light_initalize end #------------------------------------------------------------------------------- # Spriteset_Map.dispose # Calls Spriteset_Map's original dispose method # Loops through all lights in @light_effects and disposes each # Reinitializes @light_effects #------------------------------------------------------------------------------- def dispose light_dispose for effect in @light_effects effect.light.dispose end @light_effects = [] end #------------------------------------------------------------------------------- # Spriteset_Map.update # Calls Spriteset_Map's original update method # Draws each Light if in_range? #------------------------------------------------------------------------------- def update light_update if @expanding @total_expand += EXPAND_RATE @current_size = SIZE * 100 + @total_expand @expanding = !@expanding if @total_expand == EXPAND_RATE * EXPAND_ITERATION else @total_expand -= EXPAND_RATE @current_size = SIZE * 100 + @total_expand @expanding = !@expanding if @total_expand == -3 * EXPAND_RATE end for effect in @light_effects next if not in_range?(effect.event) effect.light.x = (effect.event.real_x - @current_size - $game_map.display_x) / 4 effect.light.y = (effect.event.real_y - @current_size - $game_map.display_y)/ 4 effect.light.zoom_x = (@current_size) / 100.0 effect.light.zoom_y = (@current_size) / 100.0 end end #------------------------------------------------------------------------------- # Spriteset_Map.setup_lights # For each event, if the first command is a comment, and the comment is # "Light," a new Light class is created and set to its correct position # NOTE: Need to pull SIZE, BRIGHTNESS, FLICKER, & SHADOW from comments as well #------------------------------------------------------------------------------- def setup_lights for event in $game_map.events.values next if event.list == nil for i in 0...event.list.size if event.list[i].code == 108 and event.list[i].parameters == ["Light"] light_effects = Light.new(event) light_effects.light.zoom_x = (SIZE * 100) / 100.0 light_effects.light.zoom_y = (SIZE * 100) / 100.0 light_effects.light.opacity = 255 / BRIGHTNESS @light_effects.push(light_effects) end end end for effect in @light_effects effect.light.x = (effect.event.real_x - (SIZE * 100) - $game_map.display_x) / 4 effect.light.y = (effect.event.real_y - (SIZE * 100) - $game_map.display_y) / 4 end end #------------------------------------------------------------------------------- # Spriteset_Map.in_range? # Assuming a 4:3 resolution, finds Light events that are in range # NOTE: I should probably fine tune these numbers #------------------------------------------------------------------------------- def in_range?(object) screen_x = $game_map.display_x - 256 screen_y = $game_map.display_y - 256 screen_width = $game_map.display_x + (256 * 12) screen_height = $game_map.display_y + (256 * 9) return false if object.real_x <= screen_x return false if object.real_y <= screen_y return false if object.real_x >= screen_width return false if object.real_y >= screen_height return true end end #------------------------------------------------------------------------------- # End Spriteset_Map class #------------------------------------------------------------------------------- EDIT: Changed the expand rate and iterations to make it smoother. Play around with the numbers to find what you like best Edited April 15, 2011 by Descendant of Orr Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 Cool stuff man :alright: I had made some mods myself and added the flicker/expansion and what not in an update method within Light class itself. If you would like to see what I did I can post it :) I am assuming you don't mind if I use this script as a base for my game? Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 Something doesn't want me to have this script D: I get the same error (on line 81 this time) and it's undefined[blahblah] - (instead of each) Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 By all means, play with it, change it, use it, I don't care. Tenoukii, would you be willing to put this script in a brand new game and see if it works? If it doesn't, could you package that game, unencrypted, and send it to me? Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 Hmm.. works in a new game. Could it be conflicting with another script? Or would that be a different error? (My scripting knowledge = -100% ^_^ ) Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 Hmm.. works in a new game. Could it be conflicting with another script? Or would that be a different error? (My scripting knowledge = -100% ^_^ ) That's the reason I asked you to open the script editor and tell me what Script it was on after the error. That will tell you if it is my script causing the error or not. This is a standalone script that doesn't overwrite any default class. Unless you have another script that completely reworks Spriteset_Map, I doubt it is a compatibility issue! Also, yeah - I should have probably put SIZE, BRIGHTNESS, etc. as parts of my Light object class...don't know what I was thinking :) Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 It opened on your script which is why I'm confused lol. I don't believe I have a script that does that... Which sorts of script would most likely do that? (Yes. Scripting Moron, all up in the interweb [Die Antwoord ;D] Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 (edited) Actually I just clued in, it may be the Caterpillar script you are using! It completely overwrites the Spriteset_Map Initialize method. I can't see any issues however (maybe you can see the issue descendant?) CATERPILLAR SPRITESET_MAP SCRIPT #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- def initialize # Make viewports @viewport1 = Viewport.new(0, 0, 640, 480) @viewport2 = Viewport.new(0, 0, 640, 480) @viewport3 = Viewport.new(0, 0, 640, 480) @viewport2.z = 200 @viewport3.z = 5000 # Make tilemap @tilemap = Tilemap.new(@viewport1) @tilemap.tileset = RPG::Cache.tileset($game_map.tileset_name) for i in 0..6 autotile_name = $game_map.autotile_names[i] @tilemap.autotiles[i] = RPG::Cache.autotile(autotile_name) end @tilemap.map_data = $game_map.data @tilemap.priorities = $game_map.priorities # Make panorama plane @panorama = Plane.new(@viewport1) @panorama.z = -1000 # Make fog plane @fog = Plane.new(@viewport1) @fog.z = 3000 # Make character sprites @character_sprites = [] for i in $game_map.events.keys.sort sprite = Sprite_Character.new(@viewport1, $game_map.events[i]) @character_sprites.push(sprite) end @character_sprites.push(Sprite_Character.new(@viewport1, $game_player)) $game_party.followers.each do |char| @character_sprites << Sprite_Character.new(@viewport1, char) end # Make weather @weather = RPG::Weather.new(@viewport1) # Make picture sprites @picture_sprites = [] for i in 1..50 @picture_sprites.push(Sprite_Picture.new(@viewport2, $game_screen.pictures[i])) end # Make timer sprite @timer_sprite = Sprite_Timer.new # Frame update update end Although, in what order do you have your scripts? (specifically the caterpillar scripts/ this light script) There may be an issue there, and the way the scripts are interpreted. Edited April 15, 2011 by kellessdee Share this post Link to post Share on other sites
Descendant of Orr 1 Report post Posted April 15, 2011 That's exactly what it is!!! My initialize never gets called because my script is above the Caterpillar one! I alias Spriteset_Map's intialize, but then mine doesn't get called so @light_effects is never created. Because of that there is no each (for the effects) on line 71 for the nil class @light_effects(because it doesn't exist). Share this post Link to post Share on other sites
Tenoukii 0 Report post Posted April 15, 2011 (edited) All my scripts in the order: SDK Part 1 UMS Timer Edit Mission Script Horizontal Command Window Party Switchers Pathfinding Light Script ATB Caterpillar EDIT: Works now... put it under the caterpillar :D Thanks, its an awesome script. (Y) Edited April 15, 2011 by Tenoukii Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 15, 2011 haha yea i was reading then when you mentioned there wouldn't be any compatibility issues unless there was another script that overwrote Spriteset_Map it was like *BAM* I remembered helping tenoukii with how to turn the caterpillar script on and off! So yea, tenoukii to reiterate what descendant is saying, make the light script go AFTER the caterpillar and try that instead Share this post Link to post Share on other sites
brewmeister 3 Report post Posted April 19, 2011 (edited) LOL @ gang-banging haha 12 yr. old humor... <_< But, is this script you guys are working on only with overlays and by mucking around with them? I guess with RMXP there may not be too much better of a way to create lights or dynamic lighting. Although, I haven't looked into the other dynamic lighting scripts so maybe there is. It's the only way I can think of to 'accurately' represent a light source. Rather than "adding white" to an image, a light should really "subtract black", otherwise a bright light washes out the image instead of making it clearer. This was the issue that Star started the whole 'gang-bang' with. the only other way I can think of would be to write a 'dodge' effect for the sprite (in addition to 'normal', 'add' or 'subtract') Then maybe the sprite would have the correct effect on the underlying image. If you want to combine this with day/night, where the 'darkness' is applied with an overlying image, then you're back to subtracting the inverse of the light from the overlay. Another thought would be to add light methods to the Tone class. But I think that would end up being the same as what we are trying, just on a different object. Be Well Edited April 19, 2011 by brewmeister Share this post Link to post Share on other sites
kellessdee 48 Report post Posted April 19, 2011 Leave my 12 yo humor alone that's how I get through life hehehe jk (well not kidding about my 12 yo humor, that's true, but you can make fun of it all you want :D) yea and I guess there's only so much one can do working with a 2d environment. I guess making a real-time "dynamic" lighting script in rmxp would be just as effective & possibly less efficient...considering really the most one could to make something "real-time" would be either drawing transparent pixels/rectangles to seem like light... Share this post Link to post Share on other sites