Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - MetalZelda

Pages: [1] 2 3 ... 34
1
Your scripts / Re: Turtle Rock (Alttp) Pipe system
« on: September 07, 2017, 10:01:33 am »
Code: [Select]
movement:set_target(map:get_entities(target)(1))
Wait such thing is possible ?

2
Development / Re: Multiple ground sprites?
« on: September 01, 2017, 12:13:42 am »
Should be fairly possible with greyscaled sprite

This is the cheapest solution I have in mind

3
Development / Re: How to use: chest:on_opened() ?
« on: July 11, 2017, 06:40:12 pm »
Thank for the answere
With this code
Code: [Select]
function sword_chest:on_opened(sword, 1, "sword_chest_save")
  hero:unfreeze()
  chest_open = chest_open + 1
  test()
end

I have another error
Error: Failed to load script 'maps/dungeons/tuto/place_holder': [string "maps/dungeons/tuto/place_holder.lua"]:5: <name> or '...' expected near '1'

I don't understand why...

Do like this
Don't know if this will work because I never use chest:on_opened() but that's the way to go


Code: Lua
  1. function sword_chest:on_opened(item, variant, savegame)
  2.  
  3.   if item:get_name() == "sword" then
  4.  
  5.   end
  6. end

4
Development / Re: How to use: chest:on_opened() ?
« on: July 11, 2017, 02:23:55 pm »
http://www.solarus-games.org/doc/latest/lua_api_chest.html#lua_api_chest_on_opened

The first argument need to be an item, what you've done is that the first argument is a string

5
General discussion / Re: Le défi de Zeldo : La vengeance du bingo
« on: July 03, 2017, 01:51:22 am »
From what I've seen this is a big Zelda-1 like labyrinth
Looks like it has been made by ZeldoRetro

Reminds me of Darunia's Cavern from Parallel Worlds as well

6
Your scripts / Re: fog: Add fog to your map !
« on: July 02, 2017, 05:11:21 pm »
I created a much simpler way to add fog to your maps, using a singular overlay that is built right into my tileset, that uses parallax scrolling.  Simply take it, and (if you like, any one of the semi-transparent tiles located at the top of the tileset, fit it over the entire map, making sure it is on the highest layer, separate from all other tile patterns.  You may choose to make it dynamic (in case you want to have a script attached to it, for instance, creating a fog overlay for before the hero obtains the master swordd, and then having it destroyed or not created when he has it).

That's another way to use it, this script is for permanent overlays from map creation to map destruction (I might update it one day)
This is also for minish cap styled fog, like sunrays or fire haze (ie. with opacity variation)
But I think both of our methods can be replaced by shaders when this will be possible  :P

7
Development / Re: Trouble porting a script
« on: July 02, 2017, 03:47:13 pm »
Somehow I got the thing to work properly, I don't even know how

Code: Lua
  1. function submenu:set_cursor_position(command)
  2.   -- Initialize variables for the weightings on the vertical and horizontal
  3.   -- directions
  4.   local wv, wh = 0, 0
  5.   -- The weightings for the secondary and primary axis relative to input
  6.   local w1, w2 = 1, 2
  7.  
  8.   local input = -1
  9.   if command == "right" then
  10.     input = 0
  11.   elseif command == "up" then
  12.     input = 1
  13.   elseif command == "left" then
  14.     input = 2
  15.   elseif command == "down" then
  16.     input = 3
  17.   end
  18.  
  19.   if input == -1 then return end
  20.  
  21.   -- Setup the weightings for each direction
  22.   if  (input == 1 or input == 3) then
  23.         wv, wh = w1, w2
  24.   elseif (input == 0 or input == 2) then
  25.         wv, wh = w2, w1
  26.   end
  27.  
  28.   local width = sol.video.get_quest_size()
  29.   width = width / 2 - 160
  30.  
  31.   local current_x = self.cursor_position.x
  32.   local current_y = self.cursor_position.y
  33.  
  34.   -- Create default value for the closest item's distance
  35.   local closest_index = -1
  36.   local closest_distance = 9999999
  37.   local index = self:find_item(self:find_item_axis(current_x, current_y))
  38.  
  39.   for i, item in ipairs(self.items) do
  40.     local item_x = item.x
  41.     local item_y = item.y
  42.    
  43.     --  Skip if it is the old item or is in the opposite direction
  44.     if index ~= i and (input ~= 3 or item_y >= current_y) and (input ~= 2 or item_x <= current_x) and (input ~= 0 or item_x >= current_x) and (input ~= 1 or item_y <= current_y) then
  45.       -- Get the distance of the current item and the new one
  46.       local dist_h = math.abs(item_x - current_x)
  47.       local dist_v = math.abs(item_y - current_y)
  48.        
  49.       if (wh ~= w1 or w2 * dist_h >= dist_v) and (wv ~= w1 or w2 * dist_v >= dist_h) then
  50.         -- # Get the distance multiplied with their weightings
  51.         local dist = (dist_h * wh + dist_v * wv)
  52.        
  53.         -- # Set at closest item if appropriate
  54.         if (dist < closest_distance) then
  55.           closest_distance = dist
  56.           closest_index = i
  57.         end
  58.       end
  59.     end
  60.   end
  61.  
  62.   if closest_index == -1 then return end
  63.  
  64.   local item = self.items[closest_index]
  65.   local x = item.x
  66.   local y = item.y - 5 
  67.        
  68.   self.cursor_position = {x = x, y = y + 5}
  69.   self.cursor_sprite_x = x + width
  70.   self.cursor_sprite_y = y
  71.   self.game:set_custom_command_effect("action", item.effect)
  72.  
  73.   self:set_caption(self.caption_text_keys[caption_item])  
  74.   self.game:set_value(self.menu .. "_last_index", closest_index)
  75. end

There is still some problem regarding some items but that's because I use some wizzard stuffs, for example, you need a separate item for each tunic variant, else it will be stuck on the tunic.

What makes this useful is, the simpliciity of menu customisation, you just have to put a x and y value for your item, the script determine the input pressed and stuffs, instead of using cursor position stuffs

This was my Quest status menu before the change


Notice how it is done ... Manually by stuffs

Now, it just looks like this


All of my menues now run this code

The pro is that it is easier to make and place objects in the menues, the cons is that every objects need to be an item

8
Development / Re: Trouble porting a script
« on: June 29, 2017, 05:54:36 pm »
Do  you have a sample project available? It's a bit hard to troubleshoot from the forum.

Also double-check that I negated those if statements correctly.

I will upload a sample demo tomorrow, i'm currently very busy

9
Development / Re: Trouble porting a script
« on: June 25, 2017, 09:44:27 pm »
This kinda work, it is better than last time because now the cursor and item change.

However, this is messy, it only loops through 2 items, the distance system works but it only loops between 2 items, light be the command stuff but it looks ok ...

Code: Lua
  1. function submenu:set_cursor_position(command)
  2.   local width = sol.video.get_quest_size()
  3.   width = width / 2 - 160
  4.  
  5.   local current_x = self.cursor_position.x
  6.   local current_y = self.cursor_position.y
  7.        
  8.   -- Create default value for the closest item's distance
  9.   local closest_index = -1
  10.   local closest_distance = 9999999
  11.   local index = self:find_item(self:find_item_axis(current_x, current_y))
  12.        
  13.   -- Initialize variables for the weightings on the vertical and horizontal direction
  14.   local wv, wh = 0, 0
  15.        
  16.   -- The weightings for the secondary and primary axis relative to input
  17.   local w1, w2 = 1, 2
  18.        
  19.   -- Setup the weightings for each direction
  20.   if  (command == "down" or command == "up") then
  21.     wv, wh = w1, w2
  22.   elseif (command == "left" or command == "right") then
  23.         wv, wh = w2, w1
  24.   end
  25.  
  26.   for i, item in ipairs(self.items) do
  27.     local x = item.x
  28.         local y = item.y
  29.        
  30.         --  This isn't the old item or the opposite direction
  31.         if index ~= i or (command ~= "down" and y > current_y) or (command ~= "left" and x < current_x) or (command ~= "right" and x > current_x) or (command ~= "up" and y < current_y) then
  32.           -- Get the distance of the current item and the new one
  33.           local dist_h = math.abs(x - current_x)
  34.           local dist_v = math.abs(y - current_y)
  35.          
  36.           if (wh ~= w1 or w2 * dist_h > dist_v) and (wv ~= w1 or w2 * dist_v > dist_h) then
  37.             local dist = (dist_h * wh + dist_v * wv)
  38.                
  39.                 -- Set at closest item if appropriate
  40.             if (dist < closest_distance) then
  41.                   closest_distance = dist
  42.                   closest_index = i
  43.             end
  44.           end    
  45.         end
  46.   end
  47.  
  48.   local item = self.items[closest_index]
  49.   local x = item.x
  50.   local y = item.y - 5 
  51.        
  52.   self.cursor_position = {x = x, y = y + 5}
  53.   self.cursor_sprite_x = x + width
  54.   self.cursor_sprite_y = y
  55.   self.game:set_custom_command_effect("action", item.effect)
  56.  
  57.   local caption_item = item.item .. "_" .. self.game:get_item(item.item):get_variant()
  58.  
  59.   self:set_caption(self.caption_text_keys[caption_item])  
  60.   self.game:set_value(self.menu .. "_last_index", tostring(x) .. "," .. tostring(y + 5))
  61. end

index prints the right item index in the array so this is not the culprit there
Hmmm, that's the 1st time a ruby script port grinds my gears

10
Development / [SOLVED] Trouble porting a script
« on: June 25, 2017, 04:40:28 pm »
Hello.

So, I am porting a RUBY script to lua.
This script will allow easier pause menu creation, replacing cursor position by user defined positions. Like so

Code: Lua
  1. local elements = {
  2.   config = {save = true},
  3.   {"rupee_bag", 68, 78, "info"},
  4.   {"bomb_bag", 68, 104, "info"},
  5.   {"quiver", 68, 130, "info"},
  6.   {"deku_nuts_bag", 68, 156, "info"},
  7.   {"bombchu_bag", 68, 182, "info"},
  8.   {"sword", 217, 84, "action"},
  9.   {"tunic", 209, 180, "action", variant = "_1"},
  10.   {"tunic", 233, 180, "action", variant = "_2"},
  11.   {"tunic", 257, 180, "action", variant = "_3"},
  12.   {"glove", 209, 132, "info"},
  13.   {"shield", 233, 132, "info"},
  14.   {"climb_ring", 257, 132, "info"},
  15.   {"sword_biggoron", 249, 84, "action"},
  16. }

The 2nd and 3rd index is used to place an item on the X and Y axis, as well as the cursor

This is the RUBY script I'm trying to port

Code: Ruby
  1. # Initialize variables for the weightings on the vertical and horizontal
  2.       # directions
  3.                         wv, wh = 0, 0
  4.       # The weightings for the secondary and primary axis relative to input
  5.                         w1, w2 = 1, 2
  6.       # Initialize a variable for the direction and get the direction
  7.       # pressed by the user
  8.       input_dir = 0
  9.       input_dir = 2 if Input.repeat?(Input::DOWN)
  10.       input_dir = 4 if Input.repeat?(Input::LEFT)
  11.       input_dir = 6 if Input.repeat?(Input::RIGHT)
  12.       input_dir = 8 if Input.repeat?(Input::UP)
  13.       # Do nothing if no button was pressed
  14.       return if input_dir == 0
  15.       #get the item
  16.       item = self.item
  17.       #if the item is left toggle and the input direction is left
  18.       if item == :left_toggle && input_dir == 4
  19.         #move to the left window
  20.         return $scene.move_window(6)
  21.       #elsif the item is right toggle and the input direction is right
  22.       elsif item == :right_toggle && input_dir == 6
  23.         #move to the right window
  24.         return $scene.move_window(4)
  25.       end
  26.       # Setup the weightings for each direction
  27.                         if  (input_dir == 2 or input_dir == 8)
  28.                                 wv, wh = w1, w2
  29.                         elsif (input_dir == 4 or input_dir == 6)
  30.                                 wv, wh = w2, w1
  31.                         end
  32.       # Get the xy position of the current item
  33.                         cxy = @xy_pos[@index]
  34.       # Create default value for the closest item's distance (absurdly large)
  35.       closest_index = -1
  36.                         closest_distance = 9999999
  37.       # Loop through every item
  38.                         for i in 0...@xy_pos.size
  39.                                 # Skip if it is the old item or is in the opposite direction
  40.                                 if @index == i or
  41.                                    (input_dir == 2 and @xy_pos[i][1] < cxy[1]) or
  42.                                    (input_dir == 4 and @xy_pos[i][0] > cxy[0]) or
  43.                                    (input_dir == 6 and @xy_pos[i][0] < cxy[0]) or
  44.                                    (input_dir == 8 and @xy_pos[i][1] > cxy[1])
  45.                                         next
  46.                                 end
  47.         # Get the distance from the last highlighted item to this tested one
  48.                                 dist_h = (@xy_pos[i][0] - cxy[0]).abs
  49.                                 dist_v = (@xy_pos[i][1] - cxy[1]).abs
  50.         # If it is really against the primary axis
  51.         if (wh == w1 and w2 * dist_h < dist_v) or
  52.             (wv == w1 and w2 * dist_v < dist_h)
  53.           next
  54.         end
  55.         # Get the distance multiplied with their weightings
  56.                                 dist = dist_h * wh + dist_v * wv
  57.         # Set at closest item if appropriate
  58.                                 if (dist < closest_distance)
  59.                                         closest_distance = dist
  60.                                         closest_index = i
  61.                                 end
  62.                         end
  63.       # Do nothing if nothing was selected
  64.       return if closest_index == -1
  65.       @index = closest_index
  66.       #move cursor
  67.       move_cursor

@xy_pos is already defined in the elements variable, @cxy is the current cursor position, they are already defined

The only problem, RUBY have a skip iterator whereas I can't find the closest thing for lua

This is my attempt in Lua, which still fails, the cursor will still highlight the current item forever

Code: Lua
  1. function submenu:set_cursor_position(command)
  2.   local width = sol.video.get_quest_size()
  3.   width = width / 2 - 160
  4.  
  5.   local current_x = self.cursor_position.x
  6.   local current_y = self.cursor_position.y
  7.        
  8.   -- Create default value for the closest item's distance
  9.   local closest_index = -1
  10.   local closest_distance = 320
  11.        
  12.   -- Initialize variables for the weightings on the vertical and horizontal direction
  13.   local wv, wh = 0, 0
  14.        
  15.   -- The weightings for the secondary and primary axis relative to input
  16.   local w1, w2 = 1, 2
  17.        
  18.   -- Setup the weightings for each direction
  19.   if (command == "down" or command == "up") then
  20.     wv, wh = w1, w2
  21.   elseif (command == "left" or command == "right") then
  22.         wv, wh = w2, w1
  23.   end
  24.  
  25.   for i = 1, #self.items do
  26.     local item = self.items[i]
  27.         local item_x = item.x
  28.         local item_y = item.y
  29.         local current_item_index = self:find_item(self:find_item_axis(self.cursor_position.x, self.cursor_position.y))
  30.        
  31.         --  Skip if it is the old item or is in the opposite direction
  32.         if current_item_index == i or (command == "down" and item_y < current_y) or (command == "left" and item_x > current_x) or (command == "right" and item_x < current_x) or (command == "up" and item_y > current_y) then
  33.           -- tried goto
  34.         end
  35.        
  36.         -- Get the distance of the current item and the new one
  37.         local dist_h = math.abs(item_x - current_x)
  38.         local dist_v = math.abs(item_y - current_y)
  39.                
  40.         if (wh == w1 and w2 * dist_h < dist_v) or (wv == w1 and w2 * dist_v < dist_h) then
  41.           goto matched
  42.         end
  43.        
  44.         ::matched::
  45.     -- # Get the distance multiplied with their weightings
  46.         local dist = (dist_h * wh + dist_v * wv)
  47.                  
  48.         -- # Set at closest item if appropriate
  49.         if (dist < closest_distance) then
  50.           closest_distance = dist
  51.           closest_index = i
  52.         end
  53.   end
  54.        
  55.   local item = self.items[closest_index]
  56.   local x = item.x
  57.   local y = item.y - 5 
  58.        
  59.   self.cursor_position = {x = x, y = y + 5}
  60.   self.cursor_sprite_x = x + width
  61.   self.cursor_sprite_y = y
  62.   self.game:set_custom_command_effect("action", item.effect)
  63.  
  64.   local caption_item = item.item .. "_" .. self.game:get_item(item.item):get_variant()
  65.   if item.item == "tunic" then
  66.     caption_item = "tunic_" .. self:get_tunic_variant()
  67.   end
  68.  
  69.   self:set_caption(self.caption_text_keys[caption_item])  
  70.   self.game:set_value("equipment_last_index", position)
  71. end
  72.  
  73.  

Is there a Lua equivalent of "next" ?

Next = https://www.tutorialspoint.com/ruby/ruby_loops.htm
Jumps to the next iteration of the most internal loop. Terminates execution of a block if called within a block (with yield or call returning nil).

11
Development / Re: Zelda Roth Reproduced Intro Help
« on: June 25, 2017, 01:03:35 pm »
In most case, if frescos returns nil, this is because your surface isn't created because the file has not been found

12
Your scripts / [Cursor] Majora's Mask / Project Zelda Engine cursor
« on: June 25, 2017, 12:59:44 pm »
This is a straight port of a RUBY script. Made by MaximusMaxy, from Project Zelda Engine
This script allow to have an animated cursor for your pause menu, like Majora's Mask, of course, it can be adapted for other stuffs

This is an alternative solution for avoiding a spriteset creation (frame by frame cursor animation), this script calculate the animation for you.

You need:

-> a cursor png (1 part or 4 sides) which you should save in /sprites/menus/src/pause_submenus/cursor.png (You can change the file bellow
-> using 4 side cursor ? Just set use_rotation to false
-> Using 1 part cursor ? Set use_rotation to true

What can you do ?

-> You can modify the radius of the circle (minimum, maximum)
-> You can modify the speed of the animation (speed, where 1 = super slow and 9 = 1 lightyear per sanic)
-> Disable the rotation system and only keep the offset system
-> Disable the fading animation that occurs when the animation is drawn

Code: Lua
  1. function submenu:create_cursor()
  2.   -- Set the minimum and maximum radius of the rotation
  3.   local minimum, maximum = 10, 12
  4.  
  5.   -- Speed of the animation (1 = slow, 9 = fast)
  6.   local speed = 5
  7.  
  8.   -- Use the rotation system or just the zoom ? (true = use the rotation, false = just the zoom)
  9.   local use_rotation = true
  10.  
  11.   -- Use the fading option
  12.   local use_fade = true
  13.  
  14.   -- Cursor file
  15.   local cursor = sol.surface.create("menus/src/pause_submenus/cursor.png")
  16.   local cursor_width, cursor_height = cursor:get_size()
  17.  
  18.   -- Determine the region parts depending on use_rotation state
  19.   if not use_rotation then
  20.     cursor_width = cursor_width / 2
  21.     cursor_height = cursor_height / 2
  22.   end
  23.  
  24.   -- Don't touch this
  25.   local count = 0
  26.  
  27.   function submenu:draw_cursor(dst_surface, x, y)
  28.     -- Increment the rotation
  29.     count = (count + speed) % 360
  30.  
  31.     -- Compute the sin and cos of the rotation
  32.     local sin = math.sin(count * math.pi / 180)
  33.     local cos = math.cos(count * math.pi / 180)
  34.  
  35.     -- Compute the zoom scaling
  36.     local offset = minimum + (maximum - minimum) / 2 + (maximum - minimum) / 2 * sin
  37.        
  38.         -- Update the cursor opacity
  39.         if use_fade then
  40.           cursor:set_opacity(205 - (0.5 + sin) * 100)
  41.         end
  42.        
  43.         -- Not using the rotation system, no rotation
  44.         if not use_rotation then
  45.           cos, sin = 1, 1
  46.         end
  47.        
  48.         local rotation_w = use_rotation and 0 or cursor_width
  49.         local rotation_h = use_rotation and 0 or cursor_height
  50.  
  51.         -- Draw the cursors
  52.         -- Upper Right
  53.     cursor:draw_region(rotation_w, 0, cursor_width, cursor_height, dst_surface, x + (sin * offset), y + (cos * -offset))
  54.        
  55.         -- Lower Left
  56.     cursor:draw_region(0, rotation_h, cursor_width, cursor_height, dst_surface, x + (sin * -offset), y + (cos * offset))
  57.        
  58.         -- Lower Right
  59.     cursor:draw_region(rotation_w, rotation_h, cursor_width, cursor_height, dst_surface, x + (cos * offset), y + (sin * offset))
  60.        
  61.         -- Upper Left
  62.     cursor:draw_region(0, 0, cursor_width, cursor_height, dst_surface, x + (cos * -offset), y + (sin * -offset))
  63.   end
  64. end
  65. submenu:create_cursor()

This is plug and play, at least if you use the MoS submenu system, you just have to call submenu:draw_cursor(dst_surface, x, y) in yout submenu script

You can also delete the rotation system for a zooming cursor, all you need to zoom is the local "offset"

13
Development / Re: Item command held on item?
« on: June 21, 2017, 12:34:22 pm »
To make the hero controllable just call item:set_fiinished()

But, you might want to control the hero and having the item to work. I would link a menu to this item and control everrything from this menu, you will have access to on_command_pressed / released.

That's what I do for my bow, hookshot and other stuffs

14
Development / Re: [QUESTION] Traversable prickles?
« on: June 21, 2017, 12:31:48 pm »
Maybe using dynamic tiles metatable and apply bad ground if id = spikes

http://www.solarus-games.org/doc/latest/lua_api_dynamic_tile.html#lua_api_dynamic_tile_get_pattern_id

Since dynamic tiles are entities, you can redefine it's behavious on creation time

15
Development / Re: Simulating a command when the hero is frozen ?
« on: June 18, 2017, 11:46:44 pm »
Oh well, Haven't seen that the spin attack is canceled when the input is release, which is an event of an input press, this is fixed

Pages: [1] 2 3 ... 34