Hi,
My learning is on a good way thanks to your various helps.
I have another question.
I have created a rake, but I need it the ability to cut a brush (a destructible with can_be_cut set to true).
The rake will eventually deal damage to enemy and cut thoses brushes.
I'm also trying to learn more about usable items this way, here is the code of my item "rake"
So my idea is basically to detect if a collision is occuring between my "rateau" (rake) and the bush.
If the collided entity goes by the "plantation" name, then i want to start the bush destroyed sprite animation.
So with this code i have this error:
Error: In collision callback: [string "items/rateau.lua"]:39: attempt to call method 'create_sprite' (a nil value)
If I understand correctly it means my entity can't use the create_sprite animation.
I think i miss the methodology of doing this type of stuff. For the moment i'm thinking like this:
1) test colllision
2) get the entity that is collided
3) start the cut animation if it's a brush.
But It raises questions: the callbacck from the collision test is allowing me to access the "targeted entity". But how do I test if it's a destructible brush. I can test the "destructible" part with the get_type() function (instead of get_name() which force me to list and give one unique name for each damned brush on the map).
And why do I have an error on the create_sprite() function when i try to start the destroy animation of the brush.
Thanks
My learning is on a good way thanks to your various helps.
I have another question.
I have created a rake, but I need it the ability to cut a brush (a destructible with can_be_cut set to true).
The rake will eventually deal damage to enemy and cut thoses brushes.
I'm also trying to learn more about usable items this way, here is the code of my item "rake"
Code Select
-- rateau.lua
local item = ...
local game = item:get_game()
function item:on_using()
-- some code
local entities_touched = { }
rateau:set_origin(4, 5)
rateau:add_collision_test("overlapping", function(rateau, entity)
local nom_entite = entity:get_name()
if(nom_entite == "plantation")then
local sprite = "entities/bush_green"
entity:create_sprite(sprite)
entity:set_animation("destroy")
end
-- some code
So my idea is basically to detect if a collision is occuring between my "rateau" (rake) and the bush.
If the collided entity goes by the "plantation" name, then i want to start the bush destroyed sprite animation.
So with this code i have this error:
Error: In collision callback: [string "items/rateau.lua"]:39: attempt to call method 'create_sprite' (a nil value)
If I understand correctly it means my entity can't use the create_sprite animation.
I think i miss the methodology of doing this type of stuff. For the moment i'm thinking like this:
1) test colllision
2) get the entity that is collided
3) start the cut animation if it's a brush.
But It raises questions: the callbacck from the collision test is allowing me to access the "targeted entity". But how do I test if it's a destructible brush. I can test the "destructible" part with the get_type() function (instead of get_name() which force me to list and give one unique name for each damned brush on the map).
And why do I have an error on the create_sprite() function when i try to start the destroy animation of the brush.
Thanks