Thanks Diarandor that makes sense I'll try it out soon. Also is there a way to make a turret only activate by a switch like a dart trap? Or would that be a custom entity rather than an enemy?
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.
#77
Development / Re: How do you code turret type enemies?
December 24, 2015, 03:40:54 AM
The first turret turned out to be really easy but for the other two (the four direction and eight direction turrets) I want it so that the turrets fire in all of the directions at the same time rather than only one.
#78
Development / How do you code turret type enemies?
December 23, 2015, 04:51:49 AM
I'm not too sure about how to go about making turrets that remain stationary but continuously fire(I supposed using a timer)
One turret would fire in one direction but does not change direction to follow the hero, one fires in four main directions(N,S,E,W) and another that fires in eight direction (N,NW,NE,W,E,SW,SE,S)
One turret would fire in one direction but does not change direction to follow the hero, one fires in four main directions(N,S,E,W) and another that fires in eight direction (N,NW,NE,W,E,SW,SE,S)
#79
Development / Lens of Truth?
November 17, 2015, 05:50:25 PM
Hey, I would like to try to create an item similar to the Lens of Truth from OoT, and I would just like to make sure something like that is possible. My initial thought process is to make the item enable specific dynamic tiles while it is being used and then re-disable them when the item is no longer in use.
#80
Development / Re: Question about Switches
October 31, 2015, 02:39:14 PM
That seems to have been the problem as far as enemies go. For switches however, I tried switching to solid switches yet it still doesn't work. Do I need to create a custom entity that activates when hit with an arrow?
#81
Development / Re: Question about Switches
October 31, 2015, 01:18:19 AM
Thanks the bread that works great As for the code about 1), I'm just using the custom bow/arrow code from zelda_roth...
The arrows always just go through the switches and enemies...
Code ( lua) Select
local arrow = ...
local game = arrow:get_game()
local map = arrow:get_map()
local hero = map:get_hero()
local direction = hero:get_direction()
local bow = game:get_item("bow")
local force
local sprite_id
local sprite
local enemies_touched = {}
local entity_reached
local entity_reached_dxy
local flying
-- Arrow shot by the bow. Replaces the built-in one to allow light arrows.
function arrow:on_created()
local direction = arrow:get_direction()
local horizontal = direction % 2 == 0
if horizontal then
arrow:set_size(16, 8)
arrow:set_origin(8, 4)
else
arrow:set_size(8, 16)
arrow:set_origin(4, 8)
end
arrow:set_can_traverse_ground("hole", true) -- For cases of shooting arrow near a hole, so it's not destroyed right away.
arrow:set_optimization_distance(0) -- Make the arrow continue outside the screen until the max distance.
local bow = game:get_item("bow")
force = bow.get_force and bow:get_force() or 1
end
-- Traversable rules.
arrow:set_can_traverse("crystal", true)
arrow:set_can_traverse("crystal_block", true)
arrow:set_can_traverse("hero", true)
arrow:set_can_traverse("jumper", true)
arrow:set_can_traverse("stairs", false)
arrow:set_can_traverse("stream", true)
arrow:set_can_traverse("switch", true)
arrow:set_can_traverse("teletransporter", true)
arrow:set_can_traverse_ground("deep_water", true)
arrow:set_can_traverse_ground("shallow_water", true)
arrow:set_can_traverse_ground("hole", true)
arrow:set_can_traverse_ground("lava", true)
arrow:set_can_traverse_ground("prickles", true)
arrow:set_can_traverse_ground("low_wall", true)
arrow.apply_cliffs = true
-- Triggers the animation and sound of the arrow reaching something
-- and removes the arrow after some delay.
local function attach_to_obstacle()
flying = false
sprite:set_animation("reached_obstacle")
sol.audio.play_sound("arrow_hit")
arrow:stop_movement()
-- Remove the arrow after a delay.
sol.timer.start(map, 1500, function()
arrow:remove()
end)
end
-- Attaches the arrow to an entity and make it follow it.
local function attach_to_entity(entity)
if entity_reached ~= nil then
-- Already attached.
return
end
-- Stop flying.
attach_to_obstacle()
-- Make the arrow follow the entity reached when it moves.
entity_reached = entity
local entity_reached_x, entity_reached_y = entity_reached:get_position()
local x, y = arrow:get_position()
entity_reached_dxy = { entity_reached_x - x, entity_reached_y - y }
sol.timer.start(arrow, 10, function()
if not entity_reached:exists() then
arrow:remove()
return false
end
if entity_reached:get_type() == "enemy" then
local enemy_sprite = entity_reached:get_sprite()
if entity_reached:get_life() <= 0 and
enemy_sprite ~= nil and
enemy_sprite:get_animation() ~= "hurt" then
-- Dying animation of an enemy: don't keep the arrow.
arrow:remove()
return false
end
end
x, y = entity_reached:get_position()
x, y = x - entity_reached_dxy[1], y - entity_reached_dxy[2]
arrow:set_position(x, y)
return true
end)
end
-- Hurt enemies.
arrow:add_collision_test("sprite", function(arrow, entity)
if entity:get_type() == "enemy" then
local enemy = entity
if enemies_touched[enemy] then
-- If protected we don't want to play the sound repeatedly.
return
end
enemies_touched[enemy] = true
local reaction = enemy:get_attack_arrow(enemy_sprite)
enemy:receive_attack_consequence("arrow", reaction)
attach_to_entity(enemy)
end
end)
-- Activate crystals and solid switches.
arrow:add_collision_test("overlapping", function(arrow, entity)
local entity_type = entity:get_type()
if entity_type == "crystal" then
-- Activate crystals.
if flying then
sol.audio.play_sound("switch")
map:change_crystal_state()
attach_to_entity(entity)
end
elseif entity_type == "switch" then
-- Activate solid switches.
local switch = entity
local sprite = switch:get_sprite()
if flying and sprite ~= nil and
(sprite:get_animation_set() == "entities/switch_crystal" or
sprite:get_animation_set() == "entities/switch_eye_down" or
sprite:get_animation_set() == "entities/switch_eye_left" or
sprite:get_animation_set() == "entities/switch_eye_right" or
sprite:get_animation_set() == "entities/switch_eye_up" or
sprite:get_animation_set() == "entities/switch_eye_invisible") then
if not switch:is_activated() then
sol.audio.play_sound("switch")
switch:set_activated(true)
if switch:on_activated() ~= nil then switch:on_activated() end
end
attach_to_entity(entity)
end
end
end)
function arrow:get_sprite_id()
return sprite_id
end
function arrow:set_sprite_id(id)
sprite_id = id
end
function arrow:get_force()
return force
end
function arrow:set_force(f)
force = f
end
function arrow:go()
local sprite_id = arrow:get_sprite_id()
sprite = arrow:create_sprite(sprite_id)
sprite:set_animation("flying")
sprite:set_direction(direction)
local movement = sol.movement.create("straight")
local angle = direction * math.pi / 2
movement:set_speed(192)
movement:set_angle(angle)
movement:set_smooth(false)
movement:set_max_distance(500)
movement:start(arrow)
flying = true
end
function arrow:on_obstacle_reached()
attach_to_obstacle()
end
The arrows always just go through the switches and enemies...
#82
Development / Question about Switches
October 30, 2015, 07:31:51 PM
Hey I'm having a bit of trouble with arrow switches. 1)When I shoot an arrow, the arrow goes straight through the switch rather than activating it. 2) Is it possible to require more than one switch in order to activate a dynamic tile like a bridge?
#83
Development / Re: Using timers in custom entitites
October 16, 2015, 07:55:07 PMCode ( lua) Select
local entity = ...
function entity:on_created()
self:create_sprite("entities/spring")
self:set_size(16, 16)
self:set_origin(16, 16)
self:set_traversable_by(true)
local game = self:get_game()
local hero = game:get_hero()
sol.timer.start(1000, function()
if entity:overlaps(hero) then
game:add_life(1)
hero:set_animation("plunging_water")
end
return true
end)
end
This sort of does what I want but I'm not sure what needs to be done to make the animation work without being part of the timer function
#84
Development / Re: Using timers in custom entitites
October 12, 2015, 02:18:52 PM
For the spring the player is meant to be able to go in without requiring the flippers so I don't think setting the ground to deep water would work and should just use the animation for swimming but to just be a regular traversable
#85
Development / Re: Using timers in custom entitites
October 12, 2015, 03:12:24 AM
That code works perfect and is way cleaner than mine was. Thanks.
but for adding an animation would I have to use set animation or get? The custom entity is meant to be for a hot spring so the player would be using a swim animation
but for adding an animation would I have to use set animation or get? The custom entity is meant to be for a hot spring so the player would be using a swim animation
#86
Development / Re: Using timers in custom entitites
October 11, 2015, 11:00:52 PM
Alright I have a basic code with the collision test
but not too sure on what to use for ending the timer when not on the collision
Code ( lua) Select
local entity = ...
local map = entity:get_map()
local hero = map:get_entity("hero")
local game = entity:get_game()
local timer
function entity:on_created()
self:create_sprite("entities/spring")
self:set_size(16, 16)
self:set_origin(16, 16)
self:set_traversable_by(true)
end
entity:add_collision_test("overlapping", function(spring, other)
if other:get_type() ~= "hero" then
return
end
sol.timer.start(1000, function()
game:add_life(1)
return true
end)
end)
but not too sure on what to use for ending the timer when not on the collision
#87
Development / Using timers in custom entitites
October 11, 2015, 05:22:37 AM
Hey so I was trying to make a custom entity that restores health over time. The code basically works fine but the timer covers the entire map rather than just when traversing the entity. Is there a way to make it so the hero has to be on the entity for the timer to activate?
Also, how do i change the hero animation on the entity because set_animation doesnt seem to be working...
Also, how do i change the hero animation on the entity because set_animation doesnt seem to be working...
#88
Development / Re: Moving data to new computer
October 04, 2015, 06:11:14 PM
Ah I completely forgot about that. Thanks Renkineko that worked perfectly
#89
Development / Re: Moving data to new computer
October 03, 2015, 03:31:15 PM
Yeah its english...Should be the same since all the data is copied from my desktop and the language was set as en there
#90
Development / Moving data to new computer
October 02, 2015, 09:53:41 PM
I just got a new laptop and I tried to move the data to it, but now the screen is black and I am receiving an error that did not exist on my original computer.
"Error: In timer callback: [string "scripts/menus/title.lua"]:27: attempt to index local 'zs_presents_img' (a nil value)"
I had this error before, but it was fixed so I'm not sure why it is suddenly reappearing when I have double checked that the image required exists under languages
"Error: In timer callback: [string "scripts/menus/title.lua"]:27: attempt to index local 'zs_presents_img' (a nil value)"
I had this error before, but it was fixed so I'm not sure why it is suddenly reappearing when I have double checked that the image required exists under languages