Author Topic: [UPDATE 1.2] Dash Required Blockade  (Read 1681 times)

YoshiMario2000

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
[UPDATE 1.2] Dash Required Blockade
« on: October 28, 2016, 03:52:51 am »
Today I present to you, the Rock pile script for rock stacks from alttp or other entities with similar behaviors.

Requires the multi-event script which one can find HERE! http://forum.solarus-games.org/index.php/topic,784.0.html

Code: (lua) [Select]
-- Rockstack script ment for rock piles similar to those in alttp.
--
-- Requires the muti-event script for full functionality.
-- which can be found here;
--
-- This script is a custom entity script and provides the functions:
-- custom_entity:keep_existing() which tells the script to respawn the
-- rockstack after being destoryed.
--
-- custom_entity:get_value() which will return the value of where this
-- entity's destoryed mem state is stored in the save data.
--
-- custom_entity:lift_requirement(lvl)
-- lvl - sets the lifting ability that the hero needs
-- inorder to topple the rockstack.
--
-- Made by yoshimario2000.
-- Version 1.2

-- Local required varables for this script to function properly.

local entity = ...
local game = entity:get_game()
local map = entity:get_map()
local hero = entity:get_game():get_hero()
local name = entity:get_name()

local exist_kep = false
local lvl_chk = 0

local underlayer = map:has_entity(entity:get_name() .. "_destroy")
local remains_exist = map:has_entity(entity:get_name() .. "_remains")

--
function lift_requirement(lvl)
  if lvl >= 0 then
    lvl_chk = lvl
  else
    lvl_chk = 0
  end
end

-- Call if you wish for this entity to respawn after leaving the map.
function keep_existing()
  exist_kep = true
end

-- Call to get the game var state of this entity.
function get_value()
  local map_id_new = string.gsub(entity:get_map():get_id(), "/", "__")

  return map_id_new .. "_" .. entity:get_name() .. "_destoryed"
end

--

local function destroy_self()
  if remains_exists then
    map:get_entity(entity:get_name() .. "_remains"):set_enabled(true)
  end
  if underlayer then
      map:get_entity(entity:get_name() .. "_destroy"):set_enabled(false)
  end

  -- If your sprite has a diffrent animation for being destoryed, change the string "destroy"  into that animation id.
  entity:get_sprite():set_animation("destroy", function()
    print("setting game value: " .. get_value())

    -- code for checking if to continue existing afterwards.
    if not exist_kep then
      game:set_value(get_value(), true)
    end
    entity:set_enabled(false)
  end)
end

-- Event called when the custom entity is initialized.
function entity:on_created()
  entity:set_modified_ground("wall")

  -- code for self removale if the rockstack has already been rammed.
  if game:get_ability("lift") >= lvl_chk then
    if game:get_value(get_value()) then
      if underlayer then
        map:get_entity(entity:get_name() .. "_destroy"):remove()
      end
      entity:remove()
    end
  end
end

-- If you wish to preform the checks another way, please feel free to do so.
-- this was the best way that I could come up with personally though.
map:register_event("on_update", function()
  if map:has_entity(name) then
    if entity:overlaps(hero, "facing") and hero:get_state() == "running" then
      destroy_self()
    end
  end
end)

To use this script, put the code into a .lua file in the entities folder of your quest's data.

Feel free to change some of the code around to better fit how you wish for the code to be run.

Edit: Updated for a few bug fixes and improvements in functionality.
« Last Edit: November 01, 2016, 11:09:33 pm by YoshiMario2000 »
This signature was way too long before, but now it's short!
Also, I am Still Alive!
On ad Off I go!

Do you ever get the feeling that the fandom of a product(s) ruin the potential that you could have had to enjoy the product?

ffomega

  • Full Member
  • ***
  • Posts: 223
    • View Profile
    • Solarus Resource & Tutorial Site
Re: [UPDATE 1.1] Dash Required Blockade
« Reply #1 on: November 01, 2016, 05:26:18 pm »
Could you maybe show us an example or maybe how to implement it? If you can I'd love to add this file to my Full Hyrule entities pack, which includes 8 different dash rock types to use.

Also, if there is a way, could this script be modified to be a "Lift Level Required" blockade like the large rocks in LttP?
« Last Edit: November 02, 2016, 10:45:27 am by ffomega »
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

YoshiMario2000

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: [UPDATE 1.1] Dash Required Blockade
« Reply #2 on: November 01, 2016, 10:53:15 pm »
Could you maybe show us an example or maybe how to implement it?
The way that I had implemented the script was by putting it into the entities folder. I guess I never explained how to set it up properly.

If you can I'd love to add this file to my Full Hyrule entities pack, which includes 8 different dash rock types to use.
There are few edits I would make when using your entities pack. In order for your rocks in the pack to look correct, the origin for the animations needs to be adjusted a bit. Specifically, an origin of x = 16, y = 13. The destroy animation has to have it's own origin of x = 16 and y = 21 to look correct when using this script as of solarus 1.5.0.

Also, if there is a way, could this script be modified to be a "Left Level Required" blockade like the large rocks in LttP?
Yes, this should be simple to implement. Just a few additional lines of code to add a check for that are necessary for the script, and another function to preform in the Lua file of the map that the entity is on.

I'll start working on the improvement right away.
This signature was way too long before, but now it's short!
Also, I am Still Alive!
On ad Off I go!

Do you ever get the feeling that the fandom of a product(s) ruin the potential that you could have had to enjoy the product?