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

YoshiMario2000

  • Jr. Member
  • **
  • Posts: 72
    • 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
  1. -- Rockstack script ment for rock piles similar to those in alttp.
  2. --
  3. -- Requires the muti-event script for full functionality.
  4. -- which can be found here;
  5. --
  6. -- This script is a custom entity script and provides the functions:
  7. -- custom_entity:keep_existing() which tells the script to respawn the
  8. -- rockstack after being destoryed.
  9. --
  10. -- custom_entity:get_value() which will return the value of where this
  11. -- entity's destoryed mem state is stored in the save data.
  12. --
  13. -- custom_entity:lift_requirement(lvl)
  14. -- lvl - sets the lifting ability that the hero needs
  15. -- inorder to topple the rockstack.
  16. --
  17. -- Made by yoshimario2000.
  18. -- Version 1.2
  19.  
  20. -- Local required varables for this script to function properly.
  21.  
  22. local entity = ...
  23. local game = entity:get_game()
  24. local map = entity:get_map()
  25. local hero = entity:get_game():get_hero()
  26. local name = entity:get_name()
  27.  
  28. local exist_kep = false
  29. local lvl_chk = 0
  30.  
  31. local underlayer = map:has_entity(entity:get_name() .. "_destroy")
  32. local remains_exist = map:has_entity(entity:get_name() .. "_remains")
  33.  
  34. --
  35. function lift_requirement(lvl)
  36.   if lvl >= 0 then
  37.     lvl_chk = lvl
  38.   else
  39.     lvl_chk = 0
  40.   end
  41. end
  42.  
  43. -- Call if you wish for this entity to respawn after leaving the map.
  44. function keep_existing()
  45.   exist_kep = true
  46. end
  47.  
  48. -- Call to get the game var state of this entity.
  49. function get_value()
  50.   local map_id_new = string.gsub(entity:get_map():get_id(), "/", "__")
  51.  
  52.   return map_id_new .. "_" .. entity:get_name() .. "_destoryed"
  53. end
  54.  
  55. --
  56.  
  57. local function destroy_self()
  58.   if remains_exists then
  59.     map:get_entity(entity:get_name() .. "_remains"):set_enabled(true)
  60.   end
  61.   if underlayer then
  62.       map:get_entity(entity:get_name() .. "_destroy"):set_enabled(false)
  63.   end
  64.  
  65.   -- If your sprite has a diffrent animation for being destoryed, change the string "destroy"  into that animation id.
  66.   entity:get_sprite():set_animation("destroy", function()
  67.     print("setting game value: " .. get_value())
  68.  
  69.     -- code for checking if to continue existing afterwards.
  70.     if not exist_kep then
  71.       game:set_value(get_value(), true)
  72.     end
  73.     entity:set_enabled(false)
  74.   end)
  75. end
  76.  
  77. -- Event called when the custom entity is initialized.
  78. function entity:on_created()
  79.   entity:set_modified_ground("wall")
  80.  
  81.   -- code for self removale if the rockstack has already been rammed.
  82.   if game:get_ability("lift") >= lvl_chk then
  83.     if game:get_value(get_value()) then
  84.       if underlayer then
  85.         map:get_entity(entity:get_name() .. "_destroy"):remove()
  86.       end
  87.       entity:remove()
  88.     end
  89.   end
  90. end
  91.  
  92. -- If you wish to preform the checks another way, please feel free to do so.
  93. -- this was the best way that I could come up with personally though.
  94. map:register_event("on_update", function()
  95.   if map:has_entity(name) then
  96.     if entity:overlaps(hero, "facing") and hero:get_state() == "running" then
  97.       destroy_self()
  98.     end
  99.   end
  100. end)
  101.  
  102.  
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: 208
    • 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: 72
    • 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?