function godTier_skill_trigger:GetTargetsInRange(actor, centerX, centerY, radius, targetType)
local targets = {}
local map_id = getbaseinfo(actor, 3)
-- 如果targetType是表,直接返回表中的对象
if type(targetType) == "table" then
for _, obj
🤖 回答引擎: 后端Lua |
🕒 时间: 2026-04-29 00:32:40 |
👁️ 阅读: 7
嗨,我是Lua后端老师!
小仙,你写的这个函数`GetTargetsInRange`已经考虑得很周全了!让我看看你的代码。
你已经在函数里写了这段逻辑:
```lua
-- 如果targetType为nil或0,则获取所有对象
local getAll = (targetType == nil or targetType == 0)
local getPlayers = (getAll or targetType == 1)
local getMonsters = (getAll or targetType == 2)
local getHeroes = (getAll or targetType == 4 or targetType == 64)
local getCopies = (getAll or targetType == 8 or targetType == 128)
```
这段代码处理得很好!当`targetType`为`nil`或者`0`时,`getAll`会变成`true`,然后:
- `getPlayers = true`
- `getMonsters = true`
- `getHeroes = true`
- `getCopies = true`
这样就会执行后面的所有获取逻辑,获取玩家、怪物、英雄和分身,完全符合你的需求。
不过我发现代码里有个小问题,在获取分身的部分:
```lua
elseif getCopies and isplayer(obj) and getbaseinfo(obj, 1) ~= actor then
table.insert(targets, obj)
```
这里的判断`getbaseinfo(obj, 1) ~= actor`是为了排除自己吗?如果是的话,这个逻辑是对的。但要注意`actor`是玩家对象,而`getbaseinfo(obj, 1)`返回的是玩家名字(字符串),所以这个比较是字符串比较。
整体来说,你的函数已经实现了当第五个参数为`nil`或`0`时获取所有对象的功能,继续加油哦!如果还有不明白的地方,随时可以问我或者请教浮生梦尊师!
嗨,我是Lua后端老师!
小仙,你写的这个函数`GetTargetsInRange`已经考虑得很周全了!让我看看你的代码。
你已经在函数里写了这段逻辑:
```lua
-- 如果targetType为nil或0,则获取所有对象
local getAll = (targetType == nil or targetType == 0)
local getPlayers = (getAll or targetType == 1)
local getMonsters = (getAll or targetType == 2)
local getHeroes = (getAll or targetType == 4 or targetType == 64)
local getCopies = (getAll or targetType == 8 or targetType == 128)
```
这段代码处理得很好!当`targetType`为`nil`或者`0`时,`getAll`会变成`true`,然后:
- `getPlayers = true`
- `getMonsters = true`
- `getHeroes = true`
- `getCopies = true`
这样就会执行后面的所有获取逻辑,获取玩家、怪物、英雄和分身,完全符合你的需求。
不过我发现代码里有个小问题,在获取分身的部分:
```lua
elseif getCopies and isplayer(obj) and getbaseinfo(obj, 1) ~= actor then
table.insert(targets, obj)
```
这里的判断`getbaseinfo(obj, 1) ~= actor`是为了排除自己吗?如果是的话,这个逻辑是对的。但要注意`actor`是玩家对象,而`getbaseinfo(obj, 1)`返回的是玩家名字(字符串),所以这个比较是字符串比较。
整体来说,你的函数已经实现了当第五个参数为`nil`或`0`时获取所有对象的功能,继续加油哦!如果还有不明白的地方,随时可以问我或者请教浮生梦尊师!
← 返回问答库