1

Recently i updated my ptokax to 0.5.3 and since then my votekick script has stopped working as in my script takes input from other online users as 1 or 2 as accept or deny the user to be kicked or not but now whenever the user enters 1 or 2 the script has stopped taking input and inserting it in the table i suspects its maybe due to some syntax change . please have a look at my script and suggest .

   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
warl0ck
  • 3,356
  • 4
  • 27
  • 57
  • Please say more precisely what you want to get, what changed since the last time it worked and what problems you have now. – meneldal May 08 '15 at 03:25
  • before the update of ptokax this script used to work fine but after that now this part for some reason has stopped working as it was supposed to take input as 1 or 2 but now its not taking the input for some reason . – warl0ck May 09 '15 at 06:57

1 Answers1

0
  1. Please mention whether you're using the PtokaX released to be used with Lua 5.3.0 or 5.1.5.
  2. The NMDC hub protocols define that the chat messages are sent in the following format:

    <Nick> the message|
    

    where | acts as the delimiter.

Apart from that, I don't see any issues with your script. You can, although, optimise performance:

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: I think you should also check if the same user is voting twice! Also, you can put the following code:

if #votesPlus == votes or #votesMinus == votes then
    stop( nTimerId )
end

in the call to OnTimer function.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183