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 - Dragon_noir

#1
Development / Re: Collision tests and movement
June 11, 2015, 04:33:37 PM
Thanks guys ;)

The pushing problem is solved. I indeed forgot to set pushed as false again ;)

The reason i had the on_update() function in there was because I took example of Christopho's minecart.lua script and he used it there. I wanted the action button to appear to let players know you can interact with this item ( same as the blocks do)



#2
Development / Re: Collision tests and movement
June 10, 2015, 05:31:22 PM
I've also created a custom entity to act as a block.

It works pretty well, but the only problem i have is, once the entity is pushed once, it doesn't react anymore (i can't push it a second time and the action icon doesn't appear anymore).

here's the code i have so far:


local boulder_small = ...
local map = boulder_small:get_map()
local game = boulder_small:get_game()
local hero = map:get_hero()
local x, y, layer = boulder_small:get_position()
local sprite = boulder_small:get_sprite()

local hero_facing_boulder_small = false
local action_command_boulder_small = false
local pushed = false

boulder_small:set_traversable_by("hero", false)
boulder_small:set_traversable_by("enemy", false)
boulder_small:set_traversable_by("custom_entity", false)

-- Show an action icon when the player faces the boulder.
boulder_small:add_collision_test("facing", function(boulder_small, other)

  if other:get_type() == "hero" then
  if other:get_animation() == "pushing"
    and pushed == false then
      pushed = true
      hero:freeze()
      boulder_small:go()
  hero:go()     
  end

    hero_facing_boulder_small = true

    if boulder_small:get_movement() == nil
      and game:get_command_effect("action") == nil
      and game:get_custom_command_effect("action") == nil then
      action_command_boulder_small = true
      game:set_custom_command_effect("action", "grab")     
    end
  end
end)

-- Remove the action icon when stopping facing the boulder.

function boulder_small:on_update()

  if action_command_boulder_small and not hero_facing_boulder_small then
    game:set_custom_command_effect("action", nil)
    action_command_boulder_small = false
  end

  hero_facing_boulder_small = false
end

--Makes the boulder move.

function boulder_small:go()

  local movement = sol.movement.create("path")
  local direction = hero:get_direction()
  sprite:set_animation("rolling")
  sprite:set_direction(direction)

    if direction == 0 then  
      sprite:set_animation("rolling")
      sprite:set_direction(0)
      movement:set_path({0, 0})
    end

    if direction == 1 then   
      sprite:set_animation("rolling")
      sprite:set_direction(1)
      movement:set_path({2, 2})
    end

    if direction == 2 then   
      sprite:set_animation("rolling")
      sprite:set_direction(2)
      movement:set_path({4, 4})
    end

    if direction == 3 then   
      sprite:set_animation("rolling")
      sprite:set_direction(3)
      movement:set_path({6, 6})
    end

  movement:start(boulder_small)

  function movement:on_finished()
    boulder_small:stop()
  end
end

--When boulder stops.

function boulder_small:stop()
  sprite = boulder_small:get_sprite()
  sprite:set_animation("stopped")
  hero:unfreeze()
end

-- Makes the hero move.
function hero:go()
 
  local m = sol.movement.create("straight")
  local direction = hero:get_direction()

    if direction == 0 then  
      m:set_angle(0)
  hero:set_animation("pushing")
    end

    if direction == 1 then   
      hero:set_animation("pushing")
  m:set_angle(math.pi / 2)
    end

    if direction == 2 then   
      hero:set_animation("pushing")
  m:set_angle(math.pi)
    end

    if direction == 3 then   
      hero:set_animation("pushing")
  m:set_angle(3 * math.pi / 2)
    end

  m:start(hero)
end



Any help is welcome :)
#3
Development / Custom entity and stairs
June 05, 2015, 04:56:35 PM
I've made a custom entity representing a npc following the hero.

But it doesn't go up and down the stairs.

Is there a way to make it so?
#4
Development / Re: NPC asking question
May 29, 2015, 06:42:35 PM
Yes i got it working now. Thanks.
#5
Development / NPC asking question
May 28, 2015, 07:43:49 PM
I can't get my dialog to show arrows to ask a question.

I thought I had to use "$?" in front of the text in the dialog.dat file.
#6
Development / Re: Shooting fire
May 26, 2015, 07:48:40 PM
Ok thanks :D

That part is working now.

Now i'm trying to add an animation but it doesn't work.
I've defined the animation in tunic1, but nothing happens

i've also added those lines of code to the file :


  local tunic = hero:get_tunic_sprite_id()
  hero:set_tunic_sprite_id(tunic)
  hero:set_animation("ice_rod")
#7
Development / Re: Shooting fire
May 26, 2015, 06:32:43 PM
Thanks those were helpfull.

It's kind of working now.

local item = ...
item_fire = nil

function item:on_created()

  item:set_savegame_variable("possesion_fire_wand")
  self:set_assignable(true)

end

function item:on_using()

  local movement = sol.movement.create("straight")
  local game = self:get_game()
  local map = self:get_map()
  local hero = item:get_map():get_entity("hero")
  local x, y, layer = hero:get_position()
  local direction = hero:get_direction()

  --hero:set_animation("ice_rod")

  if direction == 0 then
    x = x + 16
    movement:set_angle(0)
  elseif direction == 1 then
    y = y - 16
    movement:set_angle(math.pi / 2)
  elseif direction == 2 then
    x = x - 16
    movement:set_angle(math.pi)
  elseif direction == 3 then
    y = y + 16
    movement:set_angle(3 * math.pi / 2)
  end

  if item.fire == nil or not item.fire:exists() then

      --sol.audio.play_sound("")
      --sol.audio.play_sound("magic_bar")
      --game:remove_magic()

  item_fire = map:create_custom_entity{
name = "fire",
x = x,
y = y,
layer = layer,
    direction = direction,       
    sprite = "entities/fire2"
    }
      self.created = true

  end

  movement:set_speed(160)
  --movement:set_max_distance(320)
  item_fire:set_position(x, y, layer)
  movement:start(item_fire)

  item_fire:add_collision_test("sprite", function(item_fire, other)

    if other:get_type() == "enemy" then

      other:hurt(8)
  item_fire:remove()
 
    end
  end)
   

 
    sol.timer.start(1000, function()
  item_fire:remove()
    end)

  item:set_finished()
end


just a few bugs:

- Sometimes the fire doesn't disappear.
- The fire continues to go against diagonal walls (cliffs)
- This: movement:set_max_distance(), doesn't seem to work (makes no difference if the line of code is in the file or not.)
- I can't seem to be able to add an animation to the hero when i use the fire wand (even though it's in the assets).
#8
Development / Re: Shooting fire
May 26, 2015, 04:17:47 PM
Where can i find examples of custom entities scripts?
#9
Development / Re: Shooting fire
May 26, 2015, 03:51:11 PM
I've already been to the site but i can't learn by just reading about it. I learn by doing.

I know you can't write all the scripts for everyone :p.

But i did what the documentation said.

"direction (number): Direction of the custom entity, between 0 (East) and 3 (South). This direction will be applied to the entity's sprites if possible."

I know the error lies with the direction.

I tried : -direction(0)
             -direction = 0
             -direction = hero:get_direction()

As i said before i've only been trying to code for a coupe of months (March) I mostly used C#. I only know the basics of programming i just fail to use them correctly :(

edit: Nevermind i found the error. (stupid comma :p)
#10
Development / Re: Shooting fire
May 26, 2015, 03:21:19 PM
I don't really know how to code custom entities, and don't really understand the documentation :/

i tried this (in the fire wand script, instead of map:create fire()):

item.fire = map:create_custom_entity{
name = "fire",
x = x,
y = y,
layer = layer,
          direction(0)       
          sprite = "entities/fire2"
      }
      self.created = true



but i get an error:

Error: Failed to load script 'items/fire_wand': [string "items/fire_wand.lua"]:60: '}' expected (to close '{' at line 54) near 'sprite'
Error: In items/fire_wand: attempt to call a string value
Error: In on_started: [string "scripts/menus/pause_inventory.lua"]:41: Item 'fire_wand' is not saved
Error: In on_draw: [string "scripts/menus/pause_inventory.lua"]:203: Item 'fire_wand' is not saved
#11
Development / Re: Shooting fire
May 26, 2015, 02:34:57 PM
I also tried to loop the animation.

It now goes the distance (160) but the animation doesn't end.

And it messes up the lamp :(
#12
Development / Re: Shooting fire
May 26, 2015, 02:31:42 PM
"Check the animations of sprite "entities/fire""

If i change the animation, it would also change it for other items using it, like the lamp, wouldn't it?

"and make sure that there is no obstacle that stops the fire too soon."

I tried it on an empty map and it only moves 32 pixels.

It just ends  the animation after it travels 32 pixels.
#13
Development / Re: Shooting fire
May 26, 2015, 07:09:20 AM
So i was trying to create a fire wand and this is the code i have so far:


local item = ...
item.fire = nil

function item:on_created()

  item:set_savegame_variable("possesion_fire_wand")
  self:set_assignable(true)

end

function item:on_using()

  local movement = sol.movement.create("straight")
  local game = self:get_game()
  local map = self:get_map()
  local hero = item:get_map():get_entity("hero")
  local x, y, layer = hero:get_position()
  local direction = hero:get_direction()

  if direction == 0 then
    x = x + 16
    movement:set_angle(0)
  elseif direction == 1 then
    y = y - 16
    movement:set_angle(math.pi / 2)
  elseif direction == 2 then
    x = x - 16
    movement:set_angle(math.pi)
  elseif direction == 3 then
    y = y + 16
    movement:set_angle(3 * math.pi / 2)
  end

  if item.fire == nil or not self.fire:exists() then

      --sol.audio.play_sound("")
      --sol.audio.play_sound("magic_bar")
      --game:remove_magic()

      -- Create the fire.
      item.fire = map:create_fire{
name = "fire",
x = x,
y = y,
layer = layer,
      }
      self.created = true

  end
  movement:set_speed(120)
  movement:set_max_distance(160)
  self.fire:set_position(x, y, layer)
  movement:start(item.fire)
  item:set_finished()
end


The problem i seem to have, is that the animation of the fire is only 3 frames and disappears too fast.
#14
Development / Shooting fire
May 25, 2015, 12:58:24 AM
Is it possible to make an item shoot fire (like the fire wand from alttp)?
#15
Development / Re: Hookshot
May 24, 2015, 12:58:37 AM
Is there a way to make 2 hookshots with different lengths (Ex: 1 that does half the screen and 1 that goes all the way across the screen)?

I've looked through the documentation but couldn't find any methods for the hookshots where i could set a specific length.