在 ptokax 脚本的 lua 中的 table 中添加变量值
add variable value in table in lua for ptokax script
最近我将我的 ptokax 更新到 0.5.3,从那时起我的 votekick 脚本停止工作,因为在我的脚本中接受其他在线用户的输入作为 1 或 2 作为接受或拒绝用户被踢,但现在每当用户输入 1 或 2 时,脚本已停止接受输入并将其插入 table 我怀疑它可能是由于某些语法更改所致。请看看我的脚本并提出建议。
data = " <Nick> 2" -- this is the way script takes input frm dc chat
s,e,vote= string.find(data,"%b<>%s(.+)")
if vote == "1" then
table.insert(votesPlus,user.sNick)
Core.SendToAll("*--"..user.sNick.." accepts--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
elseif vote == "2" then
table.insert(votesMinus,user.sNick)
Core.SendToAll("*--"..user.sNick.." denies--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
else
-- the user is not voting even when poll active
end
- 请说明您使用的是与 Lua 5.3.0 还是 5.1.5 一起使用的 PtokaX。
NMDC hub protocols 定义聊天消息按以下格式发送:
<Nick> the message|
其中 |
作为分隔符。
除此之外,我没有发现您的脚本有任何问题。不过,您可以优化性能:
local vote = data:match "%b<>%s(%d)"
-- since you only want a single digit to be matched
-- also, use local variable whenever possible
if vote == "1" then
table.insert(votesPlus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." accepts--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
elseif vote == "2" then
table.insert(votesMinus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." denies--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
else
-- the user is not voting even when poll active
-- return false so that further scripts might be able to process it
return false
end
PS:我觉得你也应该看看是不是同一个用户投票了两次!另外,您可以输入以下代码:
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
在对 OnTimer
函数的调用中。
最近我将我的 ptokax 更新到 0.5.3,从那时起我的 votekick 脚本停止工作,因为在我的脚本中接受其他在线用户的输入作为 1 或 2 作为接受或拒绝用户被踢,但现在每当用户输入 1 或 2 时,脚本已停止接受输入并将其插入 table 我怀疑它可能是由于某些语法更改所致。请看看我的脚本并提出建议。
data = " <Nick> 2" -- this is the way script takes input frm dc chat
s,e,vote= string.find(data,"%b<>%s(.+)")
if vote == "1" then
table.insert(votesPlus,user.sNick)
Core.SendToAll("*--"..user.sNick.." accepts--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
elseif vote == "2" then
table.insert(votesMinus,user.sNick)
Core.SendToAll("*--"..user.sNick.." denies--")
if #votesPlus == votes or # votesMinus == votes then
stop(nTimerId)
end
return true
else
-- the user is not voting even when poll active
end
- 请说明您使用的是与 Lua 5.3.0 还是 5.1.5 一起使用的 PtokaX。
NMDC hub protocols 定义聊天消息按以下格式发送:
<Nick> the message|
其中
|
作为分隔符。
除此之外,我没有发现您的脚本有任何问题。不过,您可以优化性能:
local vote = data:match "%b<>%s(%d)"
-- since you only want a single digit to be matched
-- also, use local variable whenever possible
if vote == "1" then
table.insert(votesPlus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." accepts--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
elseif vote == "2" then
table.insert(votesMinus, user.sNick)
Core.SendToAll( "*--"..user.sNick.." denies--" )
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
return true
else
-- the user is not voting even when poll active
-- return false so that further scripts might be able to process it
return false
end
PS:我觉得你也应该看看是不是同一个用户投票了两次!另外,您可以输入以下代码:
if #votesPlus == votes or #votesMinus == votes then
stop( nTimerId )
end
在对 OnTimer
函数的调用中。