Exedion
Active Member
- Joined
- Jun 11, 2007
- Messages
- 629
- Reaction score
- 30
some days ago, diath give me a function to get the closer creature in a area, with a radius based on center position, with that function i made my own one, and work very well with players, but with monsters give me a error:
The function:
a script working with players:
with a closer dragon, this return me a message like: The Dragon is the most closer creature.
a not working script with monster:
is a testing script: the attacker is my player and the cid is the creature with other creature closer, this must return me the closer creature but only return me this error:
help please!
- - - Updated - - -
bump
- - - Updated - - -
bump
The function:
LUA:
function getCloserCreaurebyStorage(position, key, radiusA, radiusB)
local area, creatures = getArea(position, radiusA, radiusB), {}
for i = 1, #area do
local creature = getTopCreature(area[i]).uid
if creature > 0 and creature > getTopCreature(position).uid and getCreatureStorage(creature, key) ~= 1 then
table.insert(creatures, creature)
end
end
table.sort(creatures,
function(a, b)
return getDistanceBetween(getThingPosition(a), position) < getDistanceBetween(getThingPosition(b), position)
end
)
return #creatures > 0 and creatures[1] or nil
end
a script working with players:
LUA:
function onCastSpell(cid, var)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The ".. getCreatureName(getCloserCreaurebyStorage(getThingPosition(cid), 1000, 5, 7)) .." is the most closer creature.")
return true
end
with a closer dragon, this return me a message like: The Dragon is the most closer creature.
a not working script with monster:
LUA:
function onStatsChange(cid, attacker, type, combat, value)
doPlayerSendTextMessage(attacker, MESSAGE_STATUS_CONSOLE_BLUE, "The ".. getCreatureName(getCloserCreaurebyStorage(getThingPosition(cid), 1000, 5, 7)) .." is the most closer creature.")
return true
end
is a testing script: the attacker is my player and the cid is the creature with other creature closer, this must return me the closer creature but only return me this error:
Code:
[20/11/2012 17:13:41] [Error - CreatureScript Interface]
[20/11/2012 17:13:41] data/creaturescripts/scripts/chainreaction.lua:onStatsChange
[20/11/2012 17:13:41] Description:
[20/11/2012 17:13:41] data/creaturescripts/scripts/chainreaction.lua:28: attempt to concatenate a boolean value
[20/11/2012 17:13:41] stack traceback:
[20/11/2012 17:13:41] data/creaturescripts/scripts/chainreaction.lua:28: in function <data/creaturescripts/scripts/chainreaction.lua:1>
help please!
- - - Updated - - -
bump
- - - Updated - - -
bump