简体   繁体   English

命令中的Lua计时器

[英]Lua Timer(s) on command

Sorry, but this one is what some may call an open-ended question. 抱歉,但这是一些人可能会提到的开放性问题。

I am attempting to make a command where if someone says !spectate, they are put in spectate mode, and stay in there for 30 seconds. 我正在尝试发出一条命令,如果有人说“!spectate”,他们将处于旁听模式,并在其中停留30秒钟。 So far I have been totally unsuccessful, and as such, have no idea really of what I'm doing, so not erroneous code available :( 到目前为止,我一直都没有成功,因此,我不知道自己在做什么,所以没有错误的代码:(

Here's some things which may assist those who answer: 以下是一些可以帮助回答问题的人员:

To put one in spectate mode, after someone says !spectate (without the 30 second limit) you do this: 要将某人置于旁听模式,请在有人说出!spectate之后(不超过30秒的限制),您可以执行以下操作:

if Message == "!spectate" then
  InputConsole("spectate %d", pID)
end

The game this will be used with is Command and Conquer: Renegade 将使用的游戏是《命令与征服:叛徒》。

Sorry I can't be much more helpful than that, I am totally out of my depth here! 抱歉,我无法提供更多帮助,我在这里完全不懂事!

However you'd go about doing this would be specific to Renegade's Lua API. 但是,您将要做的是特定于Renegade的Lua API。 I've never used it myself, but the almighty Google reckons that Renegades uses LuaTT , for which the API docs say: 我从未亲自使用过它,但是全能的Google认为Renegades使用LuaTT ,API文档对此表示:

You can have only 255 scripts attached to objects. 您只能将255个脚本附加到对象。 For timers, make your own api based of OnThink and os.time 对于计时器,请基于OnThink和os.time创建自己的api

The docs aren't particularly good, but a quick look at the example code found here suggests something along these lines would work: 这些文档并不是特别好,但是快速浏览一下此处找到的示例代码,可以发现以下几行很有效:

local timers = {
  { time = 1343910384, cb = function() doSomething() end }
}

function OnThink()  -- this is called every frame
  for i = 1, #timers do
    if os.time() > timers[i].time then 
      timers[i].cb()
      table.remove(timers, i)
    end
  end
end

The code you posted would then look something like this: 您发布的代码将如下所示:

if Message == "!spectate" then
  InputConsole("spectate %d", pID) -- move player to spectators
  table.insert(timers, {
    time = os.time() + 30,                                 -- 30 seconds from now,
    cb   = function() InputConsole("spectate %d", pID) end -- remove player from spectators
  })
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM