Menu

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.

Show posts Menu

Messages - Diarandor

#916
Development / Re: Carrying custom entities
September 22, 2015, 02:50:26 AM
"item_fall" is the sound for the bounces (you can use the one of the bomb, I think it is "bomb").
The hero is frozen in the throw function (in generic_portable.lua) and unfrozen when the throwing animation of the hero has finished. Something is not working correctly. The unfreeze is called in as this callback:

  hero:set_animation("throw", function()
    hero:set_animation("stopped"); hero:set_invincible(false); hero:unfreeze()
  end)

so maybe the problem is that the "throw" animation has not finished (does it have an end?).

EDIT: Ok, the problem is that there is not a default throw animation (I created one for my heroes but there is not one for Link). Just create one, and the code may work then.

EDIT 2: the "throw" animation has to be in the normal tunic ("tunic1"), not the carrying one.
#917
Development / Re: Carrying custom entities
September 22, 2015, 02:39:00 AM
Or maybe the best solution is that you create a github repository and put the data there and I will try to find what is not working. Sorry for the trouble.
#918
Development / Re: Carrying custom entities
September 22, 2015, 02:27:04 AM
Try to use my hud scripts temporarily (hud, action_icon and attack_icon), I put them in https://github.com/Diarandor/portable_entities/tree/master/scripts/hud
Just to see if it works. There may be some differences in the code of these three scripts.

EDIT: we have a problem with the hud. That may be what is obstructing the throw of the entity. But part of the problem could also be in the function "on_command_pressed()". Maybe this code is not nested correctly there:


  if command == "attack" then
      local attack_effect = game:get_custom_command_effect("attack")
      if attack_effect == "custom_carry" then
        game:get_hero().custom_carry:throw(); return true
      end
  end

This bunch of code is what starts the throwing function of the carried entity (in generic_portable.lua). Maybe it's not being executed that part of code, but I am not sure.
#919
Development / Re: Carrying custom entities
September 22, 2015, 02:17:27 AM
I didn't thought on changing the animation in that event (I thought that the animation would be restarted to the initial frame when the hero changes position). If that works then we will not need to create the new carrying sprite for the hero. That's a great improvement, thanks!!!

EDIT: Ok, as you say it will not be so easy because we still have problems with the stopped animation which is changed by the engine. So maybe we are not getting rid of the new tunic after all...  :o

EDIT2: I didn't say it, but with the code I use, the item is thrown with the attack button (I keep the action button to allow talking while carrying something). Have you tried to throw the item with the attack button?
#920
I have tried it now and you are right, the Solarus editor does not detect the change unless you press enter key (or something like that). If you press enter after changing the window title, then you can save the change and it works fine.

EDIT: I agree that this should be considered a bug.
#921
Development / Re: Carrying custom entities
September 22, 2015, 01:52:48 AM
Yes, that may be the problem. I have this in the game_manager.lua script:
  local custom_command_effects = {}
  -- Returns the current customized effect of the action or attack command.
  -- nil means the built-in effect.
  function game:get_custom_command_effect(command)
    return custom_command_effects[command]
  end
  -- Overrides the effect of the action or attack command.
  -- Set the effect to nil to restore the built-in effect.
  function game:set_custom_command_effect(command, effect)
    custom_command_effects[command] = effect
  end

I thought you had it, but I think I was wrong. You will need it to paste it in the game manager.
#922
Development / Re: Carrying custom entities
September 22, 2015, 01:32:17 AM
It is very strange that the hud icon flips and shows nothing. What I get is the word "lift" written in the hud. Can you try to lift the entity and throw it?

EDIT: I have put the hud.lua, action_icon.lua and attack_icon.lua scripts in my repository. If the hud is still not working, try to use temporarily my scripts and tell me what you get.
#923
Development / Re: Carrying custom entities
September 22, 2015, 01:28:19 AM
Another thing you will need: the sprites for the shadow of the thrown entity (I am not using the default one), and also the sprites to destroy the entity when falling on holes/water/lava (a falling effect or a splash). I have put them in
https://github.com/Diarandor/portable_entities/tree/master/sprites/things
Copy the files ground_effects.dat and ground_effects.png to your sprite folder (you can change them later for your own sprites).

(The sprite for the shadow is created in the function "entity:on_throw()" and for the other effects in the function "entity:check_on_ground()". You may need this if you change your sprites name/folder.)
#924
Development / Re: Carrying custom entities
September 22, 2015, 01:26:18 AM
Using "hero:set_animation("carrying_stopped")" won't work because the engine will automatically change to the "walking" animation when you walk and not the "carrying_walking", and the same with "stopped".
#925
Development / Re: Carrying custom entities
September 21, 2015, 02:57:35 AM
In the "game:on_command_pressed(command)" you have already added:

if attack_effect == "custom_carry" then
  -- THIS IS NEEDED FOR THE GENERIC_PORTABLE.LUA SCRIPT!!!!
  game:get_hero().custom_carry:throw(); return true
end

Add this line before the code above (I omited it by mistake):

local attack_effect = game:get_custom_command_effect("attack")

Just to make it more clear, you will have inside the function "game:on_command_pressed(command)" something like:

  -- Deal with attack command.
  if command == "attack" then
    local attack_effect = game:get_custom_command_effect("attack")
    if attack_effect == "custom_carry" then
      game:get_hero().custom_carry:throw(); return true
    end
    -- Maybe more code here (in case you had some code). DELETE THIS LINE
  end

The code above makes the hero throw the carried custom entity when pressing the attack button. You can modify the code to do it with the action button instead, or with both the attack and action buttons.
#926
Development / Re: Carrying custom entities
September 21, 2015, 02:17:03 AM
Also, I haven't explained yet the aim of this part of code:

    -- Modify metatable of hero to make carried entities follow him with hero:on_position_changed().
    local hero_metatable = sol.main.get_metatable("hero")
    function hero_metatable:on_position_changed()
      if self.custom_carry then
        local x, y, layer = self:get_position()
        self.custom_carry:set_position(x, y+2, layer)
      end
    end

To make a custom entity follow the hero when carried, its position is changed when the event "hero:on_position_changed()" is called. When a custom entity has been lifted by the hero, a reference to that entity is stored in "hero.custom_carry" (this is automatically done in the generic_portable.lua script), so that the function above can move that entity position too.

Note that, by default, custom entities are drawn in Z-order (the creation order), which does not allow to draw the entity above the hero since the hero is drawn in Y-order (an entity with bigger Y-coordinate is drawn above the others with smaller Y-coordinate). In the generic_portable.lua entity, I chose Y-order to drawn a custom entity carried by the hero; and since we position the carried entity using "self.custom_carry:set_position(x, y+2, layer)" (see the function above), the carried entity will be drawn after the hero (above the hero). Obviously, the sprite of the carried entity is shifted with "drawable:set_xy(x,y)" to draw the carried entity in the correct position, which is done in the generic_portable.lua script.

This is a bit technical, but I did not find another workaround and probably there is not another solution to draw the custom entity above the hero (and in the same layer).

If you are already using the event "hero:on_position_changed()" you would need to combine the code above with yours to avoid overriding one function with the other.
#927
Yes, it's possible. Just make your inventory script to show the sprite you want, which is not necessarily the same sprite for the entity in the overworld.
#928
Development / Re: Carrying custom entities
September 21, 2015, 01:13:15 AM
I forgot to explain about this with details, sorry. The point is that, to show the hero with the carrying animations when carrying a custom entity, the only way is to create a new sprite in the editor (a carrying sprite) for the hero and change it. The stopped and walking animations for this new sprite must be the carrying_stopped and carrying_walking of the normal tunic (probably "tunic1" in your case).

The function to change tunics, from the normal one ("tunic1") to the carrying one ("tunic_carrying1") and vice-versa, is this one, that you have already pasted on your game_manager script, but you will need to modify it a bit to make it compatible with your tunic names:


local hero_tunic_sprites_id = {[1] = "tunic1", [2] = "tunic_carrying1"} -- Tunic names.
function hero_metatable:set_carrying(boolean)
  local i = 0; if boolean then i = 1 end
  self:set_tunic_sprite_id(hero_tunic_sprites_id[i])
end

(I have changed the code in the line where I wrote now "self:set_tunic_sprite_id( ... )". I had written "hero:set_tunic_sprite_id( ... )" instead of "self:set_tunic_sprite_id( ... )", which was not correct.)

If you have several tunics in your game, you need to modify that code above to make the function "hero:set_carrying(boolean)" to display the hero with carrying tunic or normal one. This function is automatically called from the generic_portable.lua script when you lift a custom entity, so don't worry too much about the details. Just make the function above change tunics as I explained, and modify it to adapt it to your tunic names.
#929
Development / Re: Carrying custom entities
September 20, 2015, 11:40:21 PM
Yes, you right. Just change the tunic of the hero to the new tunic (used for lifting custom entities).
#930
Development / Re: Carrying custom entities
September 20, 2015, 04:58:38 PM
-The last error was my fault (I had that part of code in my hero_manager.lua script, to choose the tunic depending on the hero I had, and I didn't test the simplified new code which was new and untested). It should work with your change.

-For the two first errors, first try with the code I have in my scripts:
in the action_icon.lua I have this function:

  function action_icon:compute_icon_region_y()

    local y
    if action_icon.effect_displayed ~= nil then
      -- Create an icon with the name of the current effect.
      local effects_indexes = {
        ["validate"] = 1,
        ["next"] = 2,
        ["info"] = 3,
        ["return"] = 4,
        ["look"] = 5,
        ["open"] = 6,
        ["action"] = 7,
        ["lift"] = 8,
        ["throw"] = 9,
        ["grab"] = 10,
        ["stop"] = 11,
        ["speak"] = 12,
        ["change"] = 13,
        ["swim"] = 14,
["talk"] = 12,
["custom_lift"] = 8,
["custom_carry"] = nil,
        ["custom_jump"] = nil,
      }
      if effects_indexes[action_icon.effect_displayed] ~= nil then
        action_icon.icon_region_y = 24 * effects_indexes[action_icon.effect_displayed]
      end
    end
  end

and in the attack_icon.lua I have this function like this:

  function attack_icon:compute_icon_region_y()

    if attack_icon.effect_displayed ~= nil or not game:is_dialog_enabled() then
      if attack_icon.effect_displayed == nil then
        -- Show an empty icon.
        attack_icon.icon_region_y = 0
      elseif attack_icon.effect_displayed == "sword" then
        -- Create an icon with the current sword.
        attack_icon.icon_region_y = 96 + 24 * attack_icon.sword_displayed
      elseif attack_icon.effect_displayed ~= nil then
        -- Create an icon with the name of the current effect.
        local effects_indexes = {
          ["save"] = 1,
          ["return"] = 2,
          ["validate"] = 3,
          ["skip"] = 4,
  ["custom_carry"] = 5,
          ["custom_jump"] = nil,
        }
        if effects_indexes[attack_icon.effect_displayed] ~= nil then
          attack_icon.icon_region_y = 24 * effects_indexes[attack_icon.effect_displayed]
        end
      end
    end
  end


Tell me what you get with these new changes when you have time to test again. We are getting close to make it work (when we make the hud work, the rest will be a piece of cake).