diff --git a/data-otservbr-global/lib/quests/soul_war.lua b/data-otservbr-global/lib/quests/soul_war.lua index 668c67f92b9..f5b2d75f5ba 100644 --- a/data-otservbr-global/lib/quests/soul_war.lua +++ b/data-otservbr-global/lib/quests/soul_war.lua @@ -1569,21 +1569,3 @@ function Creature:applyZoneEffect(var, combat, zoneName) return true end - -function string.toPosition(str) - local patterns = { - -- table format - "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", - -- Position format - "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", - -- x, y, z format - "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", - } - - for _, pattern in ipairs(patterns) do - local x, y, z = string.match(str, pattern) - if x and y and z then - return Position(tonumber(x), tonumber(y), tonumber(z)) - end - end -end diff --git a/data/libs/functions/string.lua b/data/libs/functions/string.lua index 9d746b82e3a..42b7a8bab4b 100644 --- a/data/libs/functions/string.lua +++ b/data/libs/functions/string.lua @@ -129,3 +129,19 @@ end string.capitalize = function(str) return str:gsub("%f[%a].", string.upper) end + +function string.toPosition(inputString) + local positionPatterns = { + "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", + "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", + "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", + } + + for _, pattern in ipairs(positionPatterns) do + local posX, posY, posZ = string.match(inputString, pattern) + if posX and posY and posZ then + return Position(tonumber(posX), tonumber(posY), tonumber(posZ)) + end + end + return nil +end