Hey,
I am looking to create a version of the cleric that can only target particular jobs with heals and buffs. Take for instance if you only wanted your cleric to heal and buff Footmen/Women, Knights and Archers, leaving the other classes to your herbalist?
I did some digging and off the back of some information from one of my previous topics i dug up the add_health_buff.lua and aura_buff.lua. These led me to entities.lua in which i found the “entities.has_job_role” function. This led me to believe that if i gave my desired classes a new and unique role in there description.json such as, “Nazgren” then made my healers abilities require this perk then this would be enough. To this end i looked for how to implement this function and came up with these
custom_add_buff.lua
– Aura buff generic class
– Add this as the script to your buff if you want your buff
– to periodically apply another buff to entities around it
local AuraBuff = class()
function AuraBuff:on_buff_added(entity, buff)
local json = buff:get_json()
self._tuning = json.script_info
if not self._tuning or not self._tuning.aura_buff then
return
end
local pulse_duration = self._tuning.pulse or "15m"
self._entity = entity
self._pulse_listener = stonehearth.calendar:set_interval(“Aura Buff “…buff:get_uri()…” pulse”, pulse_duration,
function()
self:_on_pulse()
end)
if self._tuning.pulse_immediately then
self:_on_pulse()
end
end
function AuraBuff:_on_pulse()
local player_id = radiant.entities.get_player_id(self._entity)
local num_affected = 0
– get everyone around us
local aura_buff = self._tuning.aura_buff
local sensor_name = self._tuning.sensor_name or 'sight’
local sensor = self._entity:add_component(‘sensor_list’):get_sensor(sensor_name)
local enemies_within_range = false
local target_entities = {}
for id, target in sensor:each_contents() do
if id ~= self._entity:get_id() or self._tuning.affect_self then
local target_player_id = radiant.entities.get_player_id(target)
if stonehearth.player:are_player_ids_friendly(player_id, target_player_id) then
local can_target = true
– If we can only target specific type of entity, make sure the entity’s target_type matches
if self._tuning.target_type then
if radiant.entities.get_target_type(target) ~= self._tuning.target_type then
can_target = false
end
end
if not self:_is_within_range(target) then
can_target = false
end
if can_target then
table.insert(target_entities, target)
end
elseif self._tuning.emit_if_enemies_nearby and not enemies_within_range and stonehearth.player:are_player_ids_hostile(player_id, target_player_id) then
if self:_is_within_range(target) then
enemies_within_range = true
end
end
end
end
if self._tuning.emit_if_enemies_nearby and not enemies_within_range then
return – buff needs enemies to be nearby in order to emit the aura buff
end
for _, target in ipairs(target_entities) do
radiant.entities.add_buff(target, aura_buff)
if radiant.entities.has_buff(target, aura_buff) then
num_affected = num_affected + 1
end
end
if num_affected > 0 and self._tuning and self._tuning.pulse_effect then
radiant.effects.run_effect(self._entity, self._tuning.pulse_effect)
end
end
function AuraBuff:_is_within_range(target)
if self._tuning.radius then
local distance = radiant.entities.distance_between_entities(self._entity, target)
if not distance or distance > self._tuning.radius then
return false
end
end
return true
end
function AuraBuff:on_buff_removed(entity, buff)
if self._pulse_listener then
self._pulse_listener:destroy()
self._pulse_listener = nil
end
end
function entities.has_job_role(entity, combat)
local job_component = entity:get_component(‘stonehearth:job’)
if not job_component then
buff:destroy()
end
end
return AuraBuff
I then saved this, replaced the default after making a back up and when i loaded into the game to see if the Clerics would only heal combat jobs i was met with this error:
error
release-771 (x64)[M]
std::logic_error: 'Error loading “stonehearth/data/buffs/scripts/aura_buff.lua”: stonehearth/data/buffs/scripts/aura_buff.lua:90: variable ‘entities’ is not declared’
stack traceback:
[C]: ?
[C]: in function 'require_script’
radiant/modules/mods.lua:11: in function 'load_script’
stonehearth/components/buffs/buff.lua:296: in function '_create_script_controller’
stonehearth/components/buffs/buff.lua:96: in function '_create_buff’
stonehearth/components/buffs/buff.lua:78: in function <stonehearth/components/buffs/buff.lua:73>
So i deleted the “entities”, and left just the (combat), thinking the entities part must be the variable that i was meant to change, not the role_kind but got the exact same error back, even though “entities” no longer existed on line 90.
Where have i gone wrong?
Edit: tried changeing it to target_entities to better match the rest, no change.