1

我正在为我将要制作的游戏地图编写脚本。这有点像s4联赛中的追逐者系统。

我的问题是,一旦每个人都将他们的“waschaser”设置为 true,脚本应该发出“关闭地图”通知,但是一旦每个人都被追逐,什么都没有发生,我不知道为什么。

这是我的桌子的设置方式

chaserdb_players = { }
chaserdb_players[charname] = { score = 0, death = 0, kill = 0, waschaser = false }

现在,一旦地图开始,它将搜索下一个可用的人,waschaser = false。

   for characterName,i in next, chaserdb_players do
     if (i.waschaser == false) then
      local player = getPlayerByName(characterName, map_copy)
      if (player ~= nil) then
        addChaserState(player)
        break
       end
      end
    end

在 addChaserState(player) 函数中,它为该角色切换 waschaser = true 。

我遇到的问题是,一旦地图中的每个人都有他们的 waschaser = true,我需要一个系统通知才能启动,我已经尝试过这样做

for characterName,i in next, chaserdb_players do
          if (i.waschaser == false) then
            local player = getPlayerByName(characterName, map_copy)
            if (player ~= nil) then
                addChaserState(player)
                break
            end
        else
            Notice("All players have been chaser! The map will close in 30 seconds!")
            map_close = true
        end
    end

这是 getPlayerByName 函数

function getPlayerByName(name, map_copy)
BeginGetMapCopyPlayerCha(map_copy)
for i = 0 , chaserdb_playercount - 1 , 1 do
    local player = GetMapCopyNextPlayerCha ( map_copy )
    if (player == 0 or player == nil) then 
        return nil
    else
        local playerName = GetChaDefaultName(player)
        if (playerName == name) then
            return player
        end
    end
end
end

但这不起作用。

有人可以帮忙吗?如果您需要更多信息,请随时告诉我,我会添加。

4

2 回答 2

1

将您的通知移到 for 循环之外。并使用布尔标志来检查任何可能的错误:

local bFlag = true
for i,characterName in next, chaserdb_players do
    if (characterName.waschaser == false) then
    local player = getPlayerByName(i, map_copy)
        if (player ~= nil) then
            addChaserState(player)
            break
        end
    else
        bFlag = false
    end
end
if bFlag then
    Notice("All players have been chaser! The map will close in 30 seconds!")
    map_close = true
end
于 2013-06-01T07:23:17.553 回答
0

稍微地道一点:

local allChased = true
for name, character in pairs(chaserdb_players) do
    if not character.waschaser then
        local player = getPlayerByName(name, map_copy)
        if player then
            addChaserState(player)
            break
        end
    else
        allChased = false
    end
end
if allChased then
    Notice("All players have been chaser! The map will close in 30 seconds!")
    map_close = true
end

将其包装在一个函数中效果很好:

function nextChaser()
    for name, character in ipairs(chaserdb_players) do
        if not character.waschaser then
            local player = getPlayerByName(name, map_copy)
            if player then
                return player
            end
        end
    end
end

local player = nextChaser()
if player then
    addChaserState(player)
else
    Notice("All players have been chaser! The map will close in 30 seconds!")
    map_close = true
end
于 2013-06-01T09:01:12.577 回答